OLD | NEW |
---|---|
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 |
11 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ | 11 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
12 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ | 12 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "webrtc/base/atomicops.h" | 16 #include "webrtc/base/atomicops.h" |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/system_wrappers/include/logging.h" | |
stefan-webrtc
2016/03/15 10:14:10
Should we use webrtc/base/logging.h?
åsapersson
2016/03/15 12:46:23
Done.
| |
19 | 20 |
20 // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate | 21 // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate |
21 // statistics. | 22 // statistics. |
22 // | 23 // |
23 // Histogram for counters. | 24 // Histogram for counters. |
24 // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); | 25 // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); |
25 // | 26 // |
26 // Histogram for enumerators. | 27 // Histogram for enumerators. |
27 // The boundary should be above the max enumerator sample. | 28 // The boundary should be above the max enumerator sample. |
28 // RTC_HISTOGRAM_ENUMERATION(name, sample, boundary); | 29 // RTC_HISTOGRAM_ENUMERATION(name, sample, boundary); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ | 72 #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ |
72 RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) | 73 RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) |
73 | 74 |
74 #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ | 75 #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ |
75 RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) | 76 RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) |
76 | 77 |
77 #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ | 78 #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ |
78 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) | 79 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) |
79 | 80 |
80 #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ | 81 #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ |
81 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ | 82 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, false, \ |
83 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) | |
84 | |
85 // RTC_HISTOGRAM_COUNTS with logging. | |
86 #define RTC_LHISTOGRAM_COUNTS_100(name, sample) \ | |
87 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 100, 50) | |
88 | |
89 #define RTC_LHISTOGRAM_COUNTS_200(name, sample) \ | |
90 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 200, 50) | |
91 | |
92 #define RTC_LHISTOGRAM_COUNTS_1000(name, sample) \ | |
93 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 1000, 50) | |
94 | |
95 #define RTC_LHISTOGRAM_COUNTS_10000(name, sample) \ | |
96 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 10000, 50) | |
97 | |
98 #define RTC_LHISTOGRAM_COUNTS_100000(name, sample) \ | |
99 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 100000, 50) | |
100 | |
101 #define RTC_LHISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ | |
102 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, true, \ | |
82 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) | 103 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) |
83 | 104 |
84 // Deprecated. | 105 // Deprecated. |
85 // TODO(asapersson): Remove. | 106 // TODO(asapersson): Remove. |
86 #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ | 107 #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ |
87 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) | 108 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) |
88 | 109 |
89 #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ | 110 #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ |
90 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ | 111 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
91 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) | 112 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) |
92 | 113 |
93 // Histogram for percentage (evenly spaced buckets). | 114 // Histogram for percentage (evenly spaced buckets). |
94 #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ | 115 #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ |
95 RTC_HISTOGRAM_ENUMERATION(name, sample, 101) | 116 RTC_HISTOGRAM_ENUMERATION(name, sample, 101) |
96 | 117 |
118 // RTC_HISTOGRAM_PERCENTAGE with logging. | |
119 #define RTC_LHISTOGRAM_PERCENTAGE(name, sample) \ | |
120 RTC_LHISTOGRAM_ENUMERATION(name, sample, 101) | |
121 | |
97 // Histogram for enumerators (evenly spaced buckets). | 122 // Histogram for enumerators (evenly spaced buckets). |
98 // |boundary| should be above the max enumerator sample. | 123 // |boundary| should be above the max enumerator sample. |
99 #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ | 124 #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ |
100 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ | 125 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, false, \ |
126 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) | |
127 | |
128 // RTC_HISTOGRAM_ENUMERATION with logging. | |
129 #define RTC_LHISTOGRAM_ENUMERATION(name, sample, boundary) \ | |
130 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, true, \ | |
101 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) | 131 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) |
102 | 132 |
103 // The name of the histogram should not vary. | 133 // The name of the histogram should not vary. |
104 // TODO(asapersson): Consider changing string to const char*. | 134 // TODO(asapersson): Consider changing string to const char*. |
105 #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ | 135 #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, log, \ |
106 factory_get_invocation) \ | 136 factory_get_invocation) \ |
107 do { \ | 137 do { \ |
138 if (log) { \ | |
139 LOG(LS_INFO) << constant_name << " " << sample; \ | |
140 } \ | |
108 static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ | 141 static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ |
109 webrtc::metrics::Histogram* histogram_pointer = \ | 142 webrtc::metrics::Histogram* histogram_pointer = \ |
110 rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ | 143 rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ |
111 if (!histogram_pointer) { \ | 144 if (!histogram_pointer) { \ |
112 histogram_pointer = factory_get_invocation; \ | 145 histogram_pointer = factory_get_invocation; \ |
113 webrtc::metrics::Histogram* prev_pointer = \ | 146 webrtc::metrics::Histogram* prev_pointer = \ |
114 rtc::AtomicOps::CompareAndSwapPtr( \ | 147 rtc::AtomicOps::CompareAndSwapPtr( \ |
115 &atomic_histogram_pointer, \ | 148 &atomic_histogram_pointer, \ |
116 static_cast<webrtc::metrics::Histogram*>(nullptr), \ | 149 static_cast<webrtc::metrics::Histogram*>(nullptr), \ |
117 histogram_pointer); \ | 150 histogram_pointer); \ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) | 188 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) |
156 | 189 |
157 #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ | 190 #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ |
158 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | 191 RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
159 RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) | 192 RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) |
160 | 193 |
161 #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ | 194 #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ |
162 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | 195 RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
163 RTC_HISTOGRAM_PERCENTAGE(name, sample)) | 196 RTC_HISTOGRAM_PERCENTAGE(name, sample)) |
164 | 197 |
198 // RTC_HISTOGRAMS_COUNTS with logging. | |
199 #define RTC_LHISTOGRAMS_COUNTS_100(index, name, sample) \ | |
200 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
201 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 100, 50)) | |
202 | |
203 #define RTC_LHISTOGRAMS_COUNTS_200(index, name, sample) \ | |
204 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
205 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 200, 50)) | |
206 | |
207 #define RTC_LHISTOGRAMS_COUNTS_1000(index, name, sample) \ | |
208 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
209 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 1000, 50)) | |
210 | |
211 #define RTC_LHISTOGRAMS_COUNTS_10000(index, name, sample) \ | |
212 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
213 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 10000, 50)) | |
214 | |
215 #define RTC_LHISTOGRAMS_COUNTS_100000(index, name, sample) \ | |
216 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
217 RTC_LHISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) | |
218 | |
219 #define RTC_LHISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ | |
220 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
221 RTC_LHISTOGRAM_ENUMERATION(name, sample, boundary)) | |
222 | |
223 #define RTC_LHISTOGRAMS_PERCENTAGE(index, name, sample) \ | |
224 RTC_HISTOGRAMS_COMMON(index, name, sample, \ | |
225 RTC_LHISTOGRAM_PERCENTAGE(name, sample)) | |
226 | |
165 #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ | 227 #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ |
166 do { \ | 228 do { \ |
167 switch (index) { \ | 229 switch (index) { \ |
168 case 0: \ | 230 case 0: \ |
169 macro_invocation; \ | 231 macro_invocation; \ |
170 break; \ | 232 break; \ |
171 case 1: \ | 233 case 1: \ |
172 macro_invocation; \ | 234 macro_invocation; \ |
173 break; \ | 235 break; \ |
174 case 2: \ | 236 case 2: \ |
(...skipping 28 matching lines...) Expand all Loading... | |
203 // Function for adding a |sample| to a histogram. | 265 // Function for adding a |sample| to a histogram. |
204 // |name| can be used to verify that it matches the histogram name. | 266 // |name| can be used to verify that it matches the histogram name. |
205 void HistogramAdd( | 267 void HistogramAdd( |
206 Histogram* histogram_pointer, const std::string& name, int sample); | 268 Histogram* histogram_pointer, const std::string& name, int sample); |
207 | 269 |
208 } // namespace metrics | 270 } // namespace metrics |
209 } // namespace webrtc | 271 } // namespace webrtc |
210 | 272 |
211 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ | 273 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
212 | 274 |
OLD | NEW |