OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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. |
| 9 */ |
| 10 |
| 11 #include "webrtc/api/fakemetricsobserver.h" |
| 12 #include "webrtc/base/checks.h" |
| 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()); |
| 48 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; |
| 54 } |
| 55 |
| 56 int FakeMetricsObserver::GetHistogramSample( |
| 57 PeerConnectionMetricsName type) const { |
| 58 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 return histogram_samples_[type]; |
| 60 } |
| 61 |
| 62 } // namespace webrtc |
OLD | NEW |