blob: d09bf1718513990c74148ac967d5866820df0c73 [file] [log] [blame]
jbauchac8869e2015-07-03 01:36:14 -07001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
jbauchac8869e2015-07-03 01:36:14 -07003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
jbauchac8869e2015-07-03 01:36:14 -07009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "api/fakemetricsobserver.h"
12#include "rtc_base/checks.h"
jbauchac8869e2015-07-03 01:36:14 -070013
14namespace webrtc {
15
16FakeMetricsObserver::FakeMetricsObserver() {
17 Reset();
18}
19
20void FakeMetricsObserver::Reset() {
henrikg91d6ede2015-09-17 00:24:34 -070021 RTC_DCHECK(thread_checker_.CalledOnValidThread());
guoweisea1012b2015-08-21 09:06:28 -070022 counters_.clear();
Guo-wei Shieh456696a2015-09-30 21:48:54 -070023 memset(histogram_samples_, 0, sizeof(histogram_samples_));
jbauchac8869e2015-07-03 01:36:14 -070024}
25
Guo-wei Shieh3d564c12015-08-19 16:51:15 -070026void FakeMetricsObserver::IncrementEnumCounter(
27 PeerConnectionEnumCounterType type,
28 int counter,
29 int counter_max) {
henrikg91d6ede2015-09-17 00:24:34 -070030 RTC_DCHECK(thread_checker_.CalledOnValidThread());
Guo-wei Shieh3d564c12015-08-19 16:51:15 -070031 if (counters_.size() <= static_cast<size_t>(type)) {
32 counters_.resize(type + 1);
33 }
34 auto& counters = counters_[type];
Guo-wei Shieh3d564c12015-08-19 16:51:15 -070035 ++counters[counter];
jbauchac8869e2015-07-03 01:36:14 -070036}
37
38void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type,
39 int value) {
henrikg91d6ede2015-09-17 00:24:34 -070040 RTC_DCHECK(thread_checker_.CalledOnValidThread());
Guo-wei Shieh456696a2015-09-30 21:48:54 -070041 RTC_DCHECK_EQ(histogram_samples_[type], 0);
42 histogram_samples_[type] = value;
jbauchac8869e2015-07-03 01:36:14 -070043}
44
Guo-wei Shieh3d564c12015-08-19 16:51:15 -070045int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type,
46 int counter) const {
henrikg91d6ede2015-09-17 00:24:34 -070047 RTC_DCHECK(thread_checker_.CalledOnValidThread());
Honghai Zhangd93f50c2016-10-05 11:47:22 -070048 if (counters_.size() <= static_cast<size_t>(type)) {
49 return 0;
50 }
Guo-wei Shieh456696a2015-09-30 21:48:54 -070051 const auto& it = counters_[type].find(counter);
52 if (it == counters_[type].end()) {
53 return 0;
54 }
55 return it->second;
jbauchac8869e2015-07-03 01:36:14 -070056}
57
Guo-wei Shieh456696a2015-09-30 21:48:54 -070058int FakeMetricsObserver::GetHistogramSample(
jbauchac8869e2015-07-03 01:36:14 -070059 PeerConnectionMetricsName type) const {
henrikg91d6ede2015-09-17 00:24:34 -070060 RTC_DCHECK(thread_checker_.CalledOnValidThread());
Guo-wei Shieh456696a2015-09-30 21:48:54 -070061 return histogram_samples_[type];
jbauchac8869e2015-07-03 01:36:14 -070062}
63
64} // namespace webrtc