| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 FakeMetricsObserver::FakeMetricsObserver() { | 33 FakeMetricsObserver::FakeMetricsObserver() { |
| 34 Reset(); | 34 Reset(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void FakeMetricsObserver::Reset() { | 37 void FakeMetricsObserver::Reset() { |
| 38 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 38 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 counters_.clear(); | 39 counters_.clear(); |
| 40 memset(int_histogram_samples_, 0, sizeof(int_histogram_samples_)); | 40 memset(histogram_samples_, 0, sizeof(histogram_samples_)); |
| 41 for (std::string& type : string_histogram_samples_) { | |
| 42 type.clear(); | |
| 43 } | |
| 44 } | 41 } |
| 45 | 42 |
| 46 void FakeMetricsObserver::IncrementEnumCounter( | 43 void FakeMetricsObserver::IncrementEnumCounter( |
| 47 PeerConnectionEnumCounterType type, | 44 PeerConnectionEnumCounterType type, |
| 48 int counter, | 45 int counter, |
| 49 int counter_max) { | 46 int counter_max) { |
| 50 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 47 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 if (counters_.size() <= static_cast<size_t>(type)) { | 48 if (counters_.size() <= static_cast<size_t>(type)) { |
| 52 counters_.resize(type + 1); | 49 counters_.resize(type + 1); |
| 53 } | 50 } |
| 54 auto& counters = counters_[type]; | 51 auto& counters = counters_[type]; |
| 55 if (counters.size() < static_cast<size_t>(counter_max)) { | |
| 56 counters.resize(counter_max); | |
| 57 } | |
| 58 ++counters[counter]; | 52 ++counters[counter]; |
| 59 } | 53 } |
| 60 | 54 |
| 61 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, | 55 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| 62 int value) { | 56 int value) { |
| 63 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 57 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 RTC_DCHECK_EQ(int_histogram_samples_[type], 0); | 58 RTC_DCHECK_EQ(histogram_samples_[type], 0); |
| 65 int_histogram_samples_[type] = value; | 59 histogram_samples_[type] = value; |
| 66 } | |
| 67 | |
| 68 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, | |
| 69 const std::string& value) { | |
| 70 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 71 string_histogram_samples_[type].assign(value); | |
| 72 } | 60 } |
| 73 | 61 |
| 74 int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, | 62 int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, |
| 75 int counter) const { | 63 int counter) const { |
| 76 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 64 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 77 RTC_CHECK(counters_.size() > static_cast<size_t>(type) && | 65 RTC_CHECK(counters_.size() > static_cast<size_t>(type)); |
| 78 counters_[type].size() > static_cast<size_t>(counter)); | 66 const auto& it = counters_[type].find(counter); |
| 79 return counters_[type][counter]; | 67 if (it == counters_[type].end()) { |
| 68 return 0; |
| 69 } |
| 70 return it->second; |
| 80 } | 71 } |
| 81 | 72 |
| 82 int FakeMetricsObserver::GetIntHistogramSample( | 73 int FakeMetricsObserver::GetHistogramSample( |
| 83 PeerConnectionMetricsName type) const { | 74 PeerConnectionMetricsName type) const { |
| 84 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 75 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 85 return int_histogram_samples_[type]; | 76 return histogram_samples_[type]; |
| 86 } | |
| 87 | |
| 88 const std::string& FakeMetricsObserver::GetStringHistogramSample( | |
| 89 PeerConnectionMetricsName type) const { | |
| 90 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 91 return string_histogram_samples_[type]; | |
| 92 } | 77 } |
| 93 | 78 |
| 94 } // namespace webrtc | 79 } // namespace webrtc |
| OLD | NEW |