| 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 18 matching lines...) Expand all Loading... |
| 29 #include "webrtc/base/checks.h" | 29 #include "webrtc/base/checks.h" |
| 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 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 memset(counters_, 0, sizeof(counters_)); | 39 counters_ = std::vector<std::vector<int>>(); |
| 40 memset(int_histogram_samples_, 0, sizeof(int_histogram_samples_)); | 40 memset(int_histogram_samples_, 0, sizeof(int_histogram_samples_)); |
| 41 for (std::string& type : string_histogram_samples_) { | 41 for (std::string& type : string_histogram_samples_) { |
| 42 type.clear(); | 42 type.clear(); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 void FakeMetricsObserver::IncrementCounter(PeerConnectionMetricsCounter type) { | 46 void FakeMetricsObserver::IncrementEnumCounter( |
| 47 PeerConnectionEnumCounterType type, |
| 48 int counter, |
| 49 int counter_max) { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 ++counters_[type]; | 51 if (counters_.size() <= static_cast<size_t>(type)) { |
| 52 counters_.resize(type + 1); |
| 53 } |
| 54 auto& counters = counters_[type]; |
| 55 if (counters.size() < static_cast<size_t>(counter_max)) { |
| 56 counters.resize(counter_max); |
| 57 } |
| 58 ++counters[counter]; |
| 49 } | 59 } |
| 50 | 60 |
| 51 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, | 61 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| 52 int value) { | 62 int value) { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 DCHECK_EQ(int_histogram_samples_[type], 0); | 64 DCHECK_EQ(int_histogram_samples_[type], 0); |
| 55 int_histogram_samples_[type] = value; | 65 int_histogram_samples_[type] = value; |
| 56 } | 66 } |
| 57 | 67 |
| 58 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, | 68 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| 59 const std::string& value) { | 69 const std::string& value) { |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 string_histogram_samples_[type].assign(value); | 71 string_histogram_samples_[type].assign(value); |
| 62 } | 72 } |
| 63 | 73 |
| 64 int FakeMetricsObserver::GetCounter(PeerConnectionMetricsCounter type) const { | 74 int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, |
| 75 int counter) const { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 return counters_[type]; | 77 DCHECK(counters_.size() > type && counters_[type].size() > counter); |
| 78 return counters_[type][counter]; |
| 67 } | 79 } |
| 68 | 80 |
| 69 int FakeMetricsObserver::GetIntHistogramSample( | 81 int FakeMetricsObserver::GetIntHistogramSample( |
| 70 PeerConnectionMetricsName type) const { | 82 PeerConnectionMetricsName type) const { |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 return int_histogram_samples_[type]; | 84 return int_histogram_samples_[type]; |
| 73 } | 85 } |
| 74 | 86 |
| 75 const std::string& FakeMetricsObserver::GetStringHistogramSample( | 87 const std::string& FakeMetricsObserver::GetStringHistogramSample( |
| 76 PeerConnectionMetricsName type) const { | 88 PeerConnectionMetricsName type) const { |
| 77 DCHECK(thread_checker_.CalledOnValidThread()); | 89 DCHECK(thread_checker_.CalledOnValidThread()); |
| 78 return string_histogram_samples_[type]; | 90 return string_histogram_samples_[type]; |
| 79 } | 91 } |
| 80 | 92 |
| 81 } // namespace webrtc | 93 } // namespace webrtc |
| OLD | NEW |