Chromium Code Reviews| Index: talk/app/webrtc/fakemetricsobserver.cc |
| diff --git a/talk/app/webrtc/fakemetricsobserver.cc b/talk/app/webrtc/fakemetricsobserver.cc |
| index 66e1c51f2a4035dd1ea011b78ae19ee2271ff692..54f11445f6c0857f16a651088b34f24446d52d25 100644 |
| --- a/talk/app/webrtc/fakemetricsobserver.cc |
| +++ b/talk/app/webrtc/fakemetricsobserver.cc |
| @@ -36,16 +36,25 @@ FakeMetricsObserver::FakeMetricsObserver() { |
| void FakeMetricsObserver::Reset() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - memset(counters_, 0, sizeof(counters_)); |
| + counters_ = std::vector<std::vector<int>>(); |
| memset(int_histogram_samples_, 0, sizeof(int_histogram_samples_)); |
| for (std::string& type : string_histogram_samples_) { |
| type.clear(); |
| } |
| } |
| -void FakeMetricsObserver::IncrementCounter(PeerConnectionMetricsCounter type) { |
| +void FakeMetricsObserver::IncrementEnumCounter( |
| + PeerConnectionEnumCounterType type, |
| + int counter, |
| + int counter_max) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - ++counters_[type]; |
| + if (counters_.size() <= static_cast<size_t>(type)) { |
| + counters_.resize(type + 1); |
| + } |
|
pthatcher1
2015/08/18 18:06:22
Why not just initialize the size in the constructo
guoweis_webrtc
2015/08/18 22:33:57
each counter type's max is different.
|
| + if (counters_[type].size() < static_cast<size_t>(counter_max)) { |
|
pthatcher1
2015/08/18 18:06:22
It might be more readable to use a reference:
aut
guoweis_webrtc
2015/08/18 22:33:56
sounds good.
|
| + counters_[type].resize(counter_max); |
| + } |
| + ++counters_[type][counter]; |
| } |
| void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| @@ -61,9 +70,10 @@ void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| string_histogram_samples_[type].assign(value); |
| } |
| -int FakeMetricsObserver::GetCounter(PeerConnectionMetricsCounter type) const { |
| +int FakeMetricsObserver::GetCounter(PeerConnectionEnumCounterType type, |
| + int counter) const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - return counters_[type]; |
| + return counters_[type][counter]; |
|
pthatcher1
2015/08/18 18:06:22
Won't this explode without a size check?
guoweis_webrtc
2015/08/18 22:33:56
add a DCHECK. I don't want to return silently. It'
pthatcher1
2015/08/19 02:47:52
But that only protects debug builds. I think we s
pthatcher2
2015/08/19 18:39:41
If we want a crash in release builds, then make it
|
| } |
| int FakeMetricsObserver::GetIntHistogramSample( |