Chromium Code Reviews| 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/common_types.h" | 17 #include "webrtc/common_types.h" |
| 17 | 18 |
| 18 // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate | 19 // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate |
| 19 // statistics. | 20 // statistics. |
| 20 // | 21 // |
| 21 // Histogram for counters. | 22 // Histogram for counters. |
| 22 // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); | 23 // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); |
| 23 // | 24 // |
| 24 // Histogram for enumerators. | 25 // Histogram for enumerators. |
| 25 // The boundary should be above the max enumerator sample. | 26 // The boundary should be above the max enumerator sample. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 51 // enum Types { | 52 // enum Types { |
| 52 // kTypeX, | 53 // kTypeX, |
| 53 // kTypeY, | 54 // kTypeY, |
| 54 // kBoundary, | 55 // kBoundary, |
| 55 // }; | 56 // }; |
| 56 // | 57 // |
| 57 // RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary); | 58 // RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary); |
| 58 | 59 |
| 59 | 60 |
| 60 // Macros for adding samples to a named histogram. | 61 // 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 | 62 |
| 71 // Histogram for counters. | 63 // Histogram for counters (exponentially spaced buckets). |
| 64 #define RTC_HISTOGRAM_COUNTS_100(name, sample) \ | |
| 65 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50) | |
| 66 | |
| 67 #define RTC_HISTOGRAM_COUNTS_200(name, sample) \ | |
| 68 RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50) | |
| 69 | |
| 70 #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ | |
| 71 RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) | |
| 72 | |
| 73 #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ | |
| 74 RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) | |
| 75 | |
| 76 #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ | |
| 77 RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) | |
| 78 | |
| 79 #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ | |
| 80 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ | |
| 81 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) | |
| 82 | |
| 83 // Deprecated. | |
| 84 // TODO(asapersson): Remove. | |
| 72 #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ | 85 #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ |
| 73 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) | 86 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) |
| 74 | 87 |
| 75 #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ | 88 #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ |
| 76 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) | 89 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) |
| 77 | 90 |
| 78 #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ | 91 #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ |
| 79 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) | 92 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) |
| 80 | 93 |
| 81 #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ | 94 #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ |
| 82 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) | 95 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) |
| 83 | 96 |
| 84 #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ | 97 #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ |
| 85 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) | 98 RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) |
| 86 | 99 |
| 87 #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ | 100 #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ |
| 88 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ | 101 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
| 89 webrtc::metrics::HistogramFactoryGetCounts( \ | 102 webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) |
| 90 name, min, max, bucket_count)) | |
| 91 | 103 |
| 92 // Histogram for percentage. | 104 // Histogram for percentage (evenly spaced buckets). |
| 105 #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ | |
| 106 RTC_HISTOGRAM_ENUMERATION(name, sample, 101) | |
| 107 | |
| 108 // Deprecated. | |
| 109 // TODO(asapersson): Remove. | |
| 93 #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ | 110 #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ |
| 94 RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) | 111 RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) |
| 95 | 112 |
| 96 // Histogram for enumerators. | 113 // Histogram for enumerators (evenly spaced buckets). |
| 97 // |boundary| should be above the max enumerator sample. | 114 // |boundary| should be above the max enumerator sample. |
| 115 #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ | |
| 116 RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ | |
| 117 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) | |
| 118 | |
| 119 // Deprecated. | |
| 120 // TODO(asapersson): Remove. | |
| 98 #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ | 121 #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ |
| 99 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ | 122 RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
| 100 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) | 123 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) |
| 101 | 124 |
| 102 #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(constant_name, sample, \ | 125 // The name of the histogram should not vary. |
| 103 factory_get_invocation) \ | 126 // TODO(asapersson): Consider changing string to const char*. |
|
pbos-webrtc
2015/12/21 13:44:42
FTR: I think you should def. do this, const char*
åsapersson
2015/12/21 16:45:32
Ok, will look at that in a separate CL.
| |
| 127 #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ | |
| 128 factory_get_invocation) \ | |
| 129 do { \ | |
| 130 static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ | |
| 131 webrtc::metrics::Histogram* histogram_pointer = \ | |
| 132 rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ | |
| 133 if (!histogram_pointer) { \ | |
| 134 histogram_pointer = factory_get_invocation; \ | |
| 135 rtc::AtomicOps::CompareAndSwapPtr( \ | |
| 136 &atomic_histogram_pointer, \ | |
| 137 static_cast<webrtc::metrics::Histogram*>(nullptr), \ | |
| 138 histogram_pointer); \ | |
|
pbos-webrtc
2015/12/21 13:44:43
Consider DCHECKing that this previous value was ei
åsapersson
2015/12/21 16:45:32
Done.
| |
| 139 } \ | |
| 140 webrtc::metrics::HistogramAdd(histogram_pointer, constant_name, sample); \ | |
| 141 } while (0) | |
| 142 | |
| 143 // The histogram is constructed/found for each call. | |
| 144 // May be used for histograms with infrequent updates. | |
| 145 #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ | |
|
pbos-webrtc
2015/12/21 13:44:42
Should we consider getting rid of this implementat
åsapersson
2015/12/21 16:45:32
Yes when all sparse are removed. Added deprecated
| |
| 104 do { \ | 146 do { \ |
| 105 webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ | 147 webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ |
| 106 webrtc::metrics::HistogramAdd(histogram_pointer, constant_name, sample); \ | 148 webrtc::metrics::HistogramAdd(histogram_pointer, name, sample); \ |
| 107 } while (0) | 149 } while (0) |
| 108 | 150 |
| 109 namespace webrtc { | 151 namespace webrtc { |
| 110 namespace metrics { | 152 namespace metrics { |
| 111 | 153 |
| 112 // Time that should have elapsed for stats that are gathered once per call. | 154 // Time that should have elapsed for stats that are gathered once per call. |
| 113 enum { kMinRunTimeInSeconds = 10 }; | 155 enum { kMinRunTimeInSeconds = 10 }; |
| 114 | 156 |
| 115 class Histogram; | 157 class Histogram; |
| 116 | 158 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 129 // Function for adding a |sample| to a histogram. | 171 // Function for adding a |sample| to a histogram. |
| 130 // |name| can be used to verify that it matches the histogram name. | 172 // |name| can be used to verify that it matches the histogram name. |
| 131 void HistogramAdd( | 173 void HistogramAdd( |
| 132 Histogram* histogram_pointer, const std::string& name, int sample); | 174 Histogram* histogram_pointer, const std::string& name, int sample); |
| 133 | 175 |
| 134 } // namespace metrics | 176 } // namespace metrics |
| 135 } // namespace webrtc | 177 } // namespace webrtc |
| 136 | 178 |
| 137 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ | 179 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
| 138 | 180 |
| OLD | NEW |