blob: d804f0dfb99f8c393bf51ff361d1850f84a0ddca [file] [log] [blame]
Henrik Kjellanderbd0ae452016-02-10 09:53:121/*
kjellander95ed4e62016-02-10 15:54:432 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
Henrik Kjellanderbd0ae452016-02-10 09:53:123 *
kjellander95ed4e62016-02-10 15:54:434 * 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.
Henrik Kjellanderbd0ae452016-02-10 09:53:129 */
10
11#include "webrtc/api/fakemetricsobserver.h"
Edward Lemur76de83e2017-07-06 17:44:3412#include "webrtc/rtc_base/checks.h"
Henrik Kjellanderbd0ae452016-02-10 09:53:1213
14namespace webrtc {
15
16FakeMetricsObserver::FakeMetricsObserver() {
17 Reset();
18}
19
20void FakeMetricsObserver::Reset() {
21 RTC_DCHECK(thread_checker_.CalledOnValidThread());
22 counters_.clear();
23 memset(histogram_samples_, 0, sizeof(histogram_samples_));
24}
25
26void FakeMetricsObserver::IncrementEnumCounter(
27 PeerConnectionEnumCounterType type,
28 int counter,
29 int counter_max) {
30 RTC_DCHECK(thread_checker_.CalledOnValidThread());
31 if (counters_.size() <= static_cast<size_t>(type)) {
32 counters_.resize(type + 1);
33 }
34 auto& counters = counters_[type];
35 ++counters[counter];
36}
37
38void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type,
39 int value) {
40 RTC_DCHECK(thread_checker_.CalledOnValidThread());
41 RTC_DCHECK_EQ(histogram_samples_[type], 0);
42 histogram_samples_[type] = value;
43}
44
45int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type,
46 int counter) const {
47 RTC_DCHECK(thread_checker_.CalledOnValidThread());
Honghai Zhangf702e1b2016-10-05 18:47:2248 if (counters_.size() <= static_cast<size_t>(type)) {
49 return 0;
50 }
Henrik Kjellanderbd0ae452016-02-10 09:53:1251 const auto& it = counters_[type].find(counter);
52 if (it == counters_[type].end()) {
53 return 0;
54 }
55 return it->second;
56}
57
58int FakeMetricsObserver::GetHistogramSample(
59 PeerConnectionMetricsName type) const {
60 RTC_DCHECK(thread_checker_.CalledOnValidThread());
61 return histogram_samples_[type];
62}
63
64} // namespace webrtc