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" |
| 17 #include "webrtc/base/checks.h" |
16 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
17 | 19 |
18 // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate | 20 // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate |
19 // statistics. | 21 // statistics. |
20 // | 22 // |
21 // Histogram for counters. | 23 // Histogram for counters. |
22 // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); | 24 // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); |
23 // | 25 // |
24 // Histogram for enumerators. | 26 // Histogram for enumerators. |
25 // The boundary should be above the max enumerator sample. | 27 // The boundary should be above the max enumerator sample. |
(...skipping 25 matching lines...) Expand all Loading... |
51 // enum Types { | 53 // enum Types { |
52 // kTypeX, | 54 // kTypeX, |
53 // kTypeY, | 55 // kTypeY, |
54 // kBoundary, | 56 // kBoundary, |
55 // }; | 57 // }; |
56 // | 58 // |
57 // RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary); | 59 // RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary); |
58 | 60 |
59 | 61 |
60 // Macros for adding samples to a named histogram. | 62 // Macros for adding samples to a named histogram. |
61 // | |
62 // NOTE: this is a temporary solution. | |
63 // The aim is to mimic the behaviour in Chromium's src/base/metrics/histograms.h | |
64 // However as atomics are not supported in webrtc, this is for now a modified | |
65 // and temporary solution. Note that the histogram is constructed/found for | |
66 // each call. Therefore, for now only use this implementation for metrics | |
67 // that do not need to be updated frequently. | |
68 // TODO(asapersson): Change implementation when atomics are supported. | |
69 // Also consider changing string to const char* when switching to atomics. | |
70 | 63 |
71 // Histogram for counters. | 64 // Histogram for counters (exponentially spaced buckets). |
| 65 #define RTC_HISTOGRAM_COUNTS_100(name, sample) \ |
| 66 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50) |
| 67 |
| 68 #define RTC_HISTOGRAM_COUNTS_200(name, sample) \ |
| 69 RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50) |
| 70 |
| 71 #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ |
| 72 RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) |
| 73 |
| 74 #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ |
| 75 RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) |
| 76 |
| 77 #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ |
| 78 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) |
| 79 |
| 80 #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ |
| 81 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ |
| 82 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) |
| 83 |
| 84 // Deprecated. |
| 85 // TODO(asapersson): Remove. |
72 #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ | 86 #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ |
73 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) | 87 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) |
74 | 88 |
75 #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ | 89 #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ |
76 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) | 90 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) |
77 | 91 |
78 #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ | 92 #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ |
79 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) | 93 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) |
80 | 94 |
81 #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ | 95 #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ |
82 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) | 96 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) |
83 | 97 |
84 #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ | 98 #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ |
85 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) | 99 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) |
86 | 100 |
87 #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ | 101 #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ |
88 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ | 102 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
89 webrtc::metrics::HistogramFactoryGetCounts( \ | 103 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) |
90 name, min, max, bucket_count)) | |
91 | 104 |
92 // Histogram for percentage. | 105 // Histogram for percentage (evenly spaced buckets). |
| 106 #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ |
| 107 RTC_HISTOGRAM_ENUMERATION(name, sample, 101) |
| 108 |
| 109 // Deprecated. |
| 110 // TODO(asapersson): Remove. |
93 #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ | 111 #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ |
94 RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) | 112 RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) |
95 | 113 |
96 // Histogram for enumerators. | 114 // Histogram for enumerators (evenly spaced buckets). |
97 // |boundary| should be above the max enumerator sample. | 115 // |boundary| should be above the max enumerator sample. |
| 116 #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ |
| 117 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ |
| 118 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) |
| 119 |
| 120 // Deprecated. |
| 121 // TODO(asapersson): Remove. |
98 #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ | 122 #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ |
99 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ | 123 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
100 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) | 124 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) |
101 | 125 |
102 #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(constant_name, sample, \ | 126 // The name of the histogram should not vary. |
103 factory_get_invocation) \ | 127 // TODO(asapersson): Consider changing string to const char*. |
| 128 #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ |
| 129 factory_get_invocation) \ |
| 130 do { \ |
| 131 static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ |
| 132 webrtc::metrics::Histogram* histogram_pointer = \ |
| 133 rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ |
| 134 if (!histogram_pointer) { \ |
| 135 histogram_pointer = factory_get_invocation; \ |
| 136 webrtc::metrics::Histogram* prev_pointer = \ |
| 137 rtc::AtomicOps::CompareAndSwapPtr( \ |
| 138 &atomic_histogram_pointer, \ |
| 139 static_cast<webrtc::metrics::Histogram*>(nullptr), \ |
| 140 histogram_pointer); \ |
| 141 RTC_DCHECK(prev_pointer == nullptr || \ |
| 142 prev_pointer == histogram_pointer); \ |
| 143 } \ |
| 144 webrtc::metrics::HistogramAdd(histogram_pointer, constant_name, sample); \ |
| 145 } while (0) |
| 146 |
| 147 // Deprecated. |
| 148 // The histogram is constructed/found for each call. |
| 149 // May be used for histograms with infrequent updates. |
| 150 #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ |
104 do { \ | 151 do { \ |
105 webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ | 152 webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ |
106 webrtc::metrics::HistogramAdd(histogram_pointer, constant_name, sample); \ | 153 webrtc::metrics::HistogramAdd(histogram_pointer, name, sample); \ |
107 } while (0) | 154 } while (0) |
108 | 155 |
109 namespace webrtc { | 156 namespace webrtc { |
110 namespace metrics { | 157 namespace metrics { |
111 | 158 |
112 // Time that should have elapsed for stats that are gathered once per call. | 159 // Time that should have elapsed for stats that are gathered once per call. |
113 enum { kMinRunTimeInSeconds = 10 }; | 160 enum { kMinRunTimeInSeconds = 10 }; |
114 | 161 |
115 class Histogram; | 162 class Histogram; |
116 | 163 |
(...skipping 12 matching lines...) Expand all Loading... |
129 // Function for adding a |sample| to a histogram. | 176 // Function for adding a |sample| to a histogram. |
130 // |name| can be used to verify that it matches the histogram name. | 177 // |name| can be used to verify that it matches the histogram name. |
131 void HistogramAdd( | 178 void HistogramAdd( |
132 Histogram* histogram_pointer, const std::string& name, int sample); | 179 Histogram* histogram_pointer, const std::string& name, int sample); |
133 | 180 |
134 } // namespace metrics | 181 } // namespace metrics |
135 } // namespace webrtc | 182 } // namespace webrtc |
136 | 183 |
137 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ | 184 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
138 | 185 |
OLD | NEW |