Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(946)

Side by Side Diff: talk/app/webrtc/fakemetricsobserver.cc

Issue 1277263002: Add instrumentation to track the IceEndpointType. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
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.
54 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.
55 counters_[type].resize(counter_max);
56 }
57 ++counters_[type][counter];
49 } 58 }
50 59
51 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, 60 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type,
52 int value) { 61 int value) {
53 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
54 DCHECK_EQ(int_histogram_samples_[type], 0); 63 DCHECK_EQ(int_histogram_samples_[type], 0);
55 int_histogram_samples_[type] = value; 64 int_histogram_samples_[type] = value;
56 } 65 }
57 66
58 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, 67 void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type,
59 const std::string& value) { 68 const std::string& value) {
60 DCHECK(thread_checker_.CalledOnValidThread()); 69 DCHECK(thread_checker_.CalledOnValidThread());
61 string_histogram_samples_[type].assign(value); 70 string_histogram_samples_[type].assign(value);
62 } 71 }
63 72
64 int FakeMetricsObserver::GetCounter(PeerConnectionMetricsCounter type) const { 73 int FakeMetricsObserver::GetCounter(PeerConnectionEnumCounterType type,
74 int counter) const {
65 DCHECK(thread_checker_.CalledOnValidThread()); 75 DCHECK(thread_checker_.CalledOnValidThread());
66 return counters_[type]; 76 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
67 } 77 }
68 78
69 int FakeMetricsObserver::GetIntHistogramSample( 79 int FakeMetricsObserver::GetIntHistogramSample(
70 PeerConnectionMetricsName type) const { 80 PeerConnectionMetricsName type) const {
71 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
72 return int_histogram_samples_[type]; 82 return int_histogram_samples_[type];
73 } 83 }
74 84
75 const std::string& FakeMetricsObserver::GetStringHistogramSample( 85 const std::string& FakeMetricsObserver::GetStringHistogramSample(
76 PeerConnectionMetricsName type) const { 86 PeerConnectionMetricsName type) const {
77 DCHECK(thread_checker_.CalledOnValidThread()); 87 DCHECK(thread_checker_.CalledOnValidThread());
78 return string_histogram_samples_[type]; 88 return string_histogram_samples_[type];
79 } 89 }
80 90
81 } // namespace webrtc 91 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698