blob: 71e71b3432bacf719c88065cc9da8e72346e4596 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#include "webrtc/api/fakemetricsobserver.h"
jbauchac8869e2015-07-03 01:36:14 -070012#include "webrtc/base/checks.h"
13
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());
Guo-wei Shieh456696a2015-09-30 21:48:54 -070048 RTC_CHECK(counters_.size() > static_cast<size_t>(type));
49 const auto& it = counters_[type].find(counter);
50 if (it == counters_[type].end()) {
51 return 0;
52 }
53 return it->second;
jbauchac8869e2015-07-03 01:36:14 -070054}
55
Guo-wei Shieh456696a2015-09-30 21:48:54 -070056int FakeMetricsObserver::GetHistogramSample(
jbauchac8869e2015-07-03 01:36:14 -070057 PeerConnectionMetricsName type) const {
henrikg91d6ede2015-09-17 00:24:34 -070058 RTC_DCHECK(thread_checker_.CalledOnValidThread());
Guo-wei Shieh456696a2015-09-30 21:48:54 -070059 return histogram_samples_[type];
jbauchac8869e2015-07-03 01:36:14 -070060}
61
62} // namespace webrtc