asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 | // |
| 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 |
| 6 | // tree. An additional intellectual property rights grant can be found |
| 7 | // in the file PATENTS. All contributing project authors may |
| 8 | // be found in the AUTHORS file in the root of the source tree. |
| 9 | // |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
| 12 | #define SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 15 | #include <map> |
| 16 | #include <memory> |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 17 | #include <string> |
| 18 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/atomic_ops.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "rtc_base/checks.h" |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 21 | |
| 22 | // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate |
| 23 | // statistics. |
| 24 | // |
| 25 | // Histogram for counters. |
| 26 | // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); |
| 27 | // |
| 28 | // Histogram for enumerators. |
| 29 | // The boundary should be above the max enumerator sample. |
| 30 | // RTC_HISTOGRAM_ENUMERATION(name, sample, boundary); |
| 31 | // |
| 32 | // |
| 33 | // The macros use the methods HistogramFactoryGetCounts, |
| 34 | // HistogramFactoryGetEnumeration and HistogramAdd. |
| 35 | // |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 36 | // By default WebRTC provides implementations of the aforementioned methods |
| 37 | // that can be found in system_wrappers/source/metrics.cc. If clients want to |
| 38 | // provide a custom version, they will have to: |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 39 | // |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 40 | // 1. Compile WebRTC defining the preprocessor macro |
| 41 | // WEBRTC_EXCLUDE_METRICS_DEFAULT (if GN is used this can be achieved |
| 42 | // by setting the GN arg rtc_exclude_metrics_default to true). |
| 43 | // 2. Provide implementations of: |
| 44 | // Histogram* webrtc::metrics::HistogramFactoryGetCounts( |
| 45 | // const std::string& name, int sample, int min, int max, |
| 46 | // int bucket_count); |
| 47 | // Histogram* webrtc::metrics::HistogramFactoryGetEnumeration( |
| 48 | // const std::string& name, int sample, int boundary); |
| 49 | // void webrtc::metrics::HistogramAdd( |
| 50 | // Histogram* histogram_pointer, const std::string& name, int sample); |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 51 | // |
| 52 | // Example usage: |
| 53 | // |
| 54 | // RTC_HISTOGRAM_COUNTS("WebRTC.Video.NacksSent", nacks_sent, 1, 100000, 100); |
| 55 | // |
| 56 | // enum Types { |
| 57 | // kTypeX, |
| 58 | // kTypeY, |
| 59 | // kBoundary, |
| 60 | // }; |
| 61 | // |
| 62 | // RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary); |
henrik.lundin | c9badd5 | 2016-12-06 03:58:58 -0800 | [diff] [blame] | 63 | // |
| 64 | // NOTE: It is recommended to do the Chromium review for modifications to |
| 65 | // histograms.xml before new metrics are committed to WebRTC. |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 66 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 67 | // Macros for adding samples to a named histogram. |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 68 | |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 69 | // Histogram for counters (exponentially spaced buckets). |
| 70 | #define RTC_HISTOGRAM_COUNTS_100(name, sample) \ |
| 71 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50) |
| 72 | |
| 73 | #define RTC_HISTOGRAM_COUNTS_200(name, sample) \ |
| 74 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50) |
| 75 | |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 76 | #define RTC_HISTOGRAM_COUNTS_500(name, sample) \ |
| 77 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50) |
| 78 | |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 79 | #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ |
| 80 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) |
| 81 | |
| 82 | #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ |
| 83 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) |
| 84 | |
| 85 | #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ |
| 86 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) |
| 87 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 88 | #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ |
| 89 | RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ |
| 90 | webrtc::metrics::HistogramFactoryGetCounts( \ |
| 91 | name, min, max, bucket_count)) |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 92 | |
henrik.lundin | f29e05d | 2016-12-01 09:58:45 -0800 | [diff] [blame] | 93 | #define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \ |
| 94 | RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ |
| 95 | webrtc::metrics::HistogramFactoryGetCountsLinear( \ |
| 96 | name, min, max, bucket_count)) |
| 97 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 98 | // Slow metrics: pointer to metric is acquired at each call and is not cached. |
| 99 | // |
asapersson | 5380532 | 2015-12-21 01:46:20 -0800 | [diff] [blame] | 100 | #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ |
| 101 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 102 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 103 | #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ |
| 104 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) |
| 105 | |
| 106 | #define RTC_HISTOGRAM_COUNTS_SPARSE_500(name, sample) \ |
| 107 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 500, 50) |
| 108 | |
| 109 | #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ |
| 110 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) |
| 111 | |
| 112 | #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ |
| 113 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) |
| 114 | |
| 115 | #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ |
| 116 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) |
| 117 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 118 | #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ |
| 119 | RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
| 120 | webrtc::metrics::HistogramFactoryGetCounts( \ |
| 121 | name, min, max, bucket_count)) |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 122 | |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 123 | // Histogram for percentage (evenly spaced buckets). |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 124 | #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ |
| 125 | RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) |
| 126 | |
| 127 | // Histogram for booleans. |
| 128 | #define RTC_HISTOGRAM_BOOLEAN_SPARSE(name, sample) \ |
| 129 | RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 2) |
| 130 | |
| 131 | // Histogram for enumerators (evenly spaced buckets). |
| 132 | // |boundary| should be above the max enumerator sample. |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 133 | // |
| 134 | // TODO(qingsi): Refactor the default implementation given by RtcHistogram, |
| 135 | // which is already sparse, and remove the boundary argument from the macro. |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 136 | #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ |
Qingsi Wang | 36e0f57 | 2019-01-16 18:37:21 -0800 | [diff] [blame] | 137 | RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \ |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 138 | name, sample, \ |
Qingsi Wang | d6eb71e | 2018-06-26 12:30:04 -0700 | [diff] [blame] | 139 | webrtc::metrics::SparseHistogramFactoryGetEnumeration(name, boundary)) |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 140 | |
| 141 | // Histogram for percentage (evenly spaced buckets). |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 142 | #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ |
| 143 | RTC_HISTOGRAM_ENUMERATION(name, sample, 101) |
| 144 | |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 145 | // Histogram for booleans. |
| 146 | #define RTC_HISTOGRAM_BOOLEAN(name, sample) \ |
| 147 | RTC_HISTOGRAM_ENUMERATION(name, sample, 2) |
| 148 | |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 149 | // Histogram for enumerators (evenly spaced buckets). |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 150 | // |boundary| should be above the max enumerator sample. |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 151 | #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ |
Qingsi Wang | 36e0f57 | 2019-01-16 18:37:21 -0800 | [diff] [blame] | 152 | RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 153 | name, sample, \ |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 154 | webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) |
| 155 | |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 156 | // The name of the histogram should not vary. |
| 157 | // TODO(asapersson): Consider changing string to const char*. |
sakal | 71b8393 | 2016-09-16 06:56:15 -0700 | [diff] [blame] | 158 | #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ |
| 159 | factory_get_invocation) \ |
| 160 | do { \ |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 161 | static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ |
sakal | 71b8393 | 2016-09-16 06:56:15 -0700 | [diff] [blame] | 162 | webrtc::metrics::Histogram* histogram_pointer = \ |
| 163 | rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ |
| 164 | if (!histogram_pointer) { \ |
| 165 | histogram_pointer = factory_get_invocation; \ |
| 166 | webrtc::metrics::Histogram* prev_pointer = \ |
| 167 | rtc::AtomicOps::CompareAndSwapPtr( \ |
| 168 | &atomic_histogram_pointer, \ |
| 169 | static_cast<webrtc::metrics::Histogram*>(nullptr), \ |
| 170 | histogram_pointer); \ |
| 171 | RTC_DCHECK(prev_pointer == nullptr || \ |
| 172 | prev_pointer == histogram_pointer); \ |
| 173 | } \ |
| 174 | if (histogram_pointer) { \ |
sakal | 71b8393 | 2016-09-16 06:56:15 -0700 | [diff] [blame] | 175 | webrtc::metrics::HistogramAdd(histogram_pointer, sample); \ |
| 176 | } \ |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 177 | } while (0) |
| 178 | |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 179 | // The histogram is constructed/found for each call. |
sakal | 71b8393 | 2016-09-16 06:56:15 -0700 | [diff] [blame] | 180 | // May be used for histograms with infrequent updates.` |
asapersson | 1fe48a5 | 2016-01-07 01:02:42 -0800 | [diff] [blame] | 181 | #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ |
sakal | 71b8393 | 2016-09-16 06:56:15 -0700 | [diff] [blame] | 182 | do { \ |
| 183 | webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ |
| 184 | if (histogram_pointer) { \ |
| 185 | webrtc::metrics::HistogramAdd(histogram_pointer, sample); \ |
| 186 | } \ |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 187 | } while (0) |
| 188 | |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 189 | // Helper macros. |
| 190 | // Macros for calling a histogram with varying name (e.g. when using a metric |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 191 | // in different modes such as real-time vs screenshare). Fast, because pointer |
| 192 | // is cached. |index| should be different for different names. Allowed |index| |
| 193 | // values are 0, 1, and 2. |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 194 | #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 195 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 196 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 197 | |
| 198 | #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 199 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 200 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 201 | |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 202 | #define RTC_HISTOGRAMS_COUNTS_500(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 203 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 204 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50)) |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 205 | |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 206 | #define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 207 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 208 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 209 | |
| 210 | #define RTC_HISTOGRAMS_COUNTS_10000(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 211 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 212 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 213 | |
| 214 | #define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 215 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 216 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 217 | |
| 218 | #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 219 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 220 | RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 221 | |
| 222 | #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 223 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 224 | RTC_HISTOGRAM_PERCENTAGE(name, sample)) |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 225 | |
| 226 | #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 227 | do { \ |
| 228 | switch (index) { \ |
| 229 | case 0: \ |
| 230 | macro_invocation; \ |
| 231 | break; \ |
| 232 | case 1: \ |
| 233 | macro_invocation; \ |
| 234 | break; \ |
| 235 | case 2: \ |
| 236 | macro_invocation; \ |
| 237 | break; \ |
| 238 | default: \ |
| 239 | RTC_NOTREACHED(); \ |
| 240 | } \ |
asapersson | 040b79f | 2016-02-02 07:13:01 -0800 | [diff] [blame] | 241 | } while (0) |
| 242 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 243 | namespace webrtc { |
| 244 | namespace metrics { |
| 245 | |
asapersson@webrtc.org | 83b5200 | 2014-11-28 10:17:13 +0000 | [diff] [blame] | 246 | // Time that should have elapsed for stats that are gathered once per call. |
| 247 | enum { kMinRunTimeInSeconds = 10 }; |
| 248 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 249 | class Histogram; |
| 250 | |
| 251 | // Functions for getting pointer to histogram (constructs or finds the named |
| 252 | // histogram). |
| 253 | |
| 254 | // Get histogram for counters. |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 255 | Histogram* HistogramFactoryGetCounts(const std::string& name, |
| 256 | int min, |
| 257 | int max, |
| 258 | int bucket_count); |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 259 | |
henrik.lundin | f29e05d | 2016-12-01 09:58:45 -0800 | [diff] [blame] | 260 | // Get histogram for counters with linear bucket spacing. |
| 261 | Histogram* HistogramFactoryGetCountsLinear(const std::string& name, |
| 262 | int min, |
| 263 | int max, |
| 264 | int bucket_count); |
| 265 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 266 | // Get histogram for enumerators. |
| 267 | // |boundary| should be above the max enumerator sample. |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 268 | Histogram* HistogramFactoryGetEnumeration(const std::string& name, |
| 269 | int boundary); |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 270 | |
Qingsi Wang | d6eb71e | 2018-06-26 12:30:04 -0700 | [diff] [blame] | 271 | // Get sparse histogram for enumerators. |
| 272 | // |boundary| should be above the max enumerator sample. |
| 273 | Histogram* SparseHistogramFactoryGetEnumeration(const std::string& name, |
| 274 | int boundary); |
| 275 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 276 | // Function for adding a |sample| to a histogram. |
sakal | 71b8393 | 2016-09-16 06:56:15 -0700 | [diff] [blame] | 277 | void HistogramAdd(Histogram* histogram_pointer, int sample); |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 278 | |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 279 | struct SampleInfo { |
| 280 | SampleInfo(const std::string& name, int min, int max, size_t bucket_count); |
| 281 | ~SampleInfo(); |
| 282 | |
| 283 | const std::string name; |
| 284 | const int min; |
| 285 | const int max; |
| 286 | const size_t bucket_count; |
| 287 | std::map<int, int> samples; // <value, # of events> |
| 288 | }; |
| 289 | |
| 290 | // Enables collection of samples. |
| 291 | // This method should be called before any other call into webrtc. |
| 292 | void Enable(); |
| 293 | |
| 294 | // Gets histograms and clears all samples. |
| 295 | void GetAndReset( |
| 296 | std::map<std::string, std::unique_ptr<SampleInfo>>* histograms); |
| 297 | |
| 298 | // Functions below are mainly for testing. |
| 299 | |
| 300 | // Clears all samples. |
| 301 | void Reset(); |
| 302 | |
| 303 | // Returns the number of times the |sample| has been added to the histogram. |
| 304 | int NumEvents(const std::string& name, int sample); |
| 305 | |
| 306 | // Returns the total number of added samples to the histogram. |
| 307 | int NumSamples(const std::string& name); |
| 308 | |
| 309 | // Returns the minimum sample value (or -1 if the histogram has no samples). |
| 310 | int MinSample(const std::string& name); |
| 311 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 312 | } // namespace metrics |
| 313 | } // namespace webrtc |
| 314 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 315 | #endif // SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |