Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 1 | /* |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 3 | * |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 4 | * 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 Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include "webrtc/api/fakemetricsobserver.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 12 | #include "webrtc/rtc_base/checks.h" |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 13 | |
| 14 | namespace webrtc { |
| 15 | |
| 16 | FakeMetricsObserver::FakeMetricsObserver() { |
| 17 | Reset(); |
| 18 | } |
| 19 | |
| 20 | void FakeMetricsObserver::Reset() { |
| 21 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 22 | counters_.clear(); |
| 23 | memset(histogram_samples_, 0, sizeof(histogram_samples_)); |
| 24 | } |
| 25 | |
| 26 | void 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 | |
| 38 | void 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 | |
| 45 | int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, |
| 46 | int counter) const { |
| 47 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Honghai Zhang | f702e1b | 2016-10-05 18:47:22 | [diff] [blame] | 48 | if (counters_.size() <= static_cast<size_t>(type)) { |
| 49 | return 0; |
| 50 | } |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 51 | const auto& it = counters_[type].find(counter); |
| 52 | if (it == counters_[type].end()) { |
| 53 | return 0; |
| 54 | } |
| 55 | return it->second; |
| 56 | } |
| 57 | |
| 58 | int FakeMetricsObserver::GetHistogramSample( |
| 59 | PeerConnectionMetricsName type) const { |
| 60 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 | return histogram_samples_[type]; |
| 62 | } |
| 63 | |
| 64 | } // namespace webrtc |