jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [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. |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/fakemetricsobserver.h" |
| 12 | #include "rtc_base/checks.h" |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 13 | |
| 14 | namespace webrtc { |
| 15 | |
| 16 | FakeMetricsObserver::FakeMetricsObserver() { |
| 17 | Reset(); |
| 18 | } |
| 19 | |
| 20 | void FakeMetricsObserver::Reset() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 21 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
guoweis | ea1012b | 2015-08-21 09:06:28 -0700 | [diff] [blame] | 22 | counters_.clear(); |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 23 | memset(histogram_samples_, 0, sizeof(histogram_samples_)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 26 | void FakeMetricsObserver::IncrementEnumCounter( |
| 27 | PeerConnectionEnumCounterType type, |
| 28 | int counter, |
| 29 | int counter_max) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 30 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 31 | if (counters_.size() <= static_cast<size_t>(type)) { |
| 32 | counters_.resize(type + 1); |
| 33 | } |
| 34 | auto& counters = counters_[type]; |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 35 | ++counters[counter]; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| 39 | int value) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 40 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 41 | RTC_DCHECK_EQ(histogram_samples_[type], 0); |
| 42 | histogram_samples_[type] = value; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 45 | int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, |
| 46 | int counter) const { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 47 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 48 | if (counters_.size() <= static_cast<size_t>(type)) { |
| 49 | return 0; |
| 50 | } |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 51 | const auto& it = counters_[type].find(counter); |
| 52 | if (it == counters_[type].end()) { |
| 53 | return 0; |
| 54 | } |
| 55 | return it->second; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 58 | int FakeMetricsObserver::GetHistogramSample( |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 59 | PeerConnectionMetricsName type) const { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 60 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 61 | return histogram_samples_[type]; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } // namespace webrtc |