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

Side by Side Diff: webrtc/system_wrappers/include/metrics.h

Issue 2337883003: Remove name parameter from HistogramAdd function. (Closed)
Patch Set: Add check to Android Metrics. Created 4 years, 3 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 // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 // 3 //
4 // Use of this source code is governed by a BSD-style license 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 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 6 // tree. An additional intellectual property rights grant can be found
7 // in the file PATENTS. All contributing project authors may 7 // in the file PATENTS. All contributing project authors may
8 // be found in the AUTHORS file in the root of the source tree. 8 // be found in the AUTHORS file in the root of the source tree.
9 // 9 //
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 RTC_HISTOGRAM_ENUMERATION(name, sample, 2) 103 RTC_HISTOGRAM_ENUMERATION(name, sample, 2)
104 104
105 // Histogram for enumerators (evenly spaced buckets). 105 // Histogram for enumerators (evenly spaced buckets).
106 // |boundary| should be above the max enumerator sample. 106 // |boundary| should be above the max enumerator sample.
107 #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ 107 #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \
108 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ 108 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \
109 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) 109 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
110 110
111 // The name of the histogram should not vary. 111 // The name of the histogram should not vary.
112 // TODO(asapersson): Consider changing string to const char*. 112 // TODO(asapersson): Consider changing string to const char*.
113 #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ 113 #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \
114 factory_get_invocation) \ 114 factory_get_invocation) \
115 do { \ 115 do { \
116 static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ 116 static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \
117 webrtc::metrics::Histogram* histogram_pointer = \ 117 webrtc::metrics::Histogram* histogram_pointer = \
118 rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ 118 rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \
119 if (!histogram_pointer) { \ 119 if (!histogram_pointer) { \
120 histogram_pointer = factory_get_invocation; \ 120 histogram_pointer = factory_get_invocation; \
121 webrtc::metrics::Histogram* prev_pointer = \ 121 webrtc::metrics::Histogram* prev_pointer = \
122 rtc::AtomicOps::CompareAndSwapPtr( \ 122 rtc::AtomicOps::CompareAndSwapPtr( \
123 &atomic_histogram_pointer, \ 123 &atomic_histogram_pointer, \
124 static_cast<webrtc::metrics::Histogram*>(nullptr), \ 124 static_cast<webrtc::metrics::Histogram*>(nullptr), \
125 histogram_pointer); \ 125 histogram_pointer); \
126 RTC_DCHECK(prev_pointer == nullptr || \ 126 RTC_DCHECK(prev_pointer == nullptr || \
127 prev_pointer == histogram_pointer); \ 127 prev_pointer == histogram_pointer); \
128 } \ 128 } \
129 webrtc::metrics::HistogramAdd(histogram_pointer, constant_name, sample); \ 129 if (histogram_pointer) { \
130 RTC_DCHECK_EQ(constant_name, \
131 webrtc::metrics::GetHistogramName(histogram_pointer)) \
132 << "The name should not vary."; \
133 webrtc::metrics::HistogramAdd(histogram_pointer, sample); \
134 } \
130 } while (0) 135 } while (0)
131 136
132 // Deprecated. 137 // Deprecated.
133 // The histogram is constructed/found for each call. 138 // The histogram is constructed/found for each call.
134 // May be used for histograms with infrequent updates. 139 // May be used for histograms with infrequent updates.`
135 #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ 140 #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \
136 do { \ 141 do { \
137 webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ 142 webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \
138 webrtc::metrics::HistogramAdd(histogram_pointer, name, sample); \ 143 if (histogram_pointer) { \
144 webrtc::metrics::HistogramAdd(histogram_pointer, sample); \
145 } \
139 } while (0) 146 } while (0)
140 147
141
142 // Helper macros. 148 // Helper macros.
143 // Macros for calling a histogram with varying name (e.g. when using a metric 149 // Macros for calling a histogram with varying name (e.g. when using a metric
144 // in different modes such as real-time vs screenshare). 150 // in different modes such as real-time vs screenshare).
145 #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \ 151 #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \
146 RTC_HISTOGRAMS_COMMON(index, name, sample, \ 152 RTC_HISTOGRAMS_COMMON(index, name, sample, \
147 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)) 153 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50))
148 154
149 #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \ 155 #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \
150 RTC_HISTOGRAMS_COMMON(index, name, sample, \ 156 RTC_HISTOGRAMS_COMMON(index, name, sample, \
151 RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)) 157 RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50))
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 211
206 // Get histogram for counters. 212 // Get histogram for counters.
207 Histogram* HistogramFactoryGetCounts( 213 Histogram* HistogramFactoryGetCounts(
208 const std::string& name, int min, int max, int bucket_count); 214 const std::string& name, int min, int max, int bucket_count);
209 215
210 // Get histogram for enumerators. 216 // Get histogram for enumerators.
211 // |boundary| should be above the max enumerator sample. 217 // |boundary| should be above the max enumerator sample.
212 Histogram* HistogramFactoryGetEnumeration( 218 Histogram* HistogramFactoryGetEnumeration(
213 const std::string& name, int boundary); 219 const std::string& name, int boundary);
214 220
221 // Returns name of the histogram.
222 const std::string& GetHistogramName(Histogram* histogram_pointer);
223
215 // Function for adding a |sample| to a histogram. 224 // Function for adding a |sample| to a histogram.
216 // |name| can be used to verify that it matches the histogram name. 225 void HistogramAdd(Histogram* histogram_pointer, int sample);
217 void HistogramAdd(
218 Histogram* histogram_pointer, const std::string& name, int sample);
219 226
220 } // namespace metrics 227 } // namespace metrics
221 } // namespace webrtc 228 } // namespace webrtc
222 229
223 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ 230 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_
224 231
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698