| 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 |
| 11 | #ifndef SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
| 12 | #define SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
| 13 |
| 14 | #include <stddef.h> |
| 15 |
| 16 | #include <atomic> |
| 17 | #include <map> |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 |
| 21 | #include "absl/strings/string_view.h" |
| 22 | #include "rtc_base/checks.h" |
| 23 | #include "rtc_base/string_utils.h" |
| 24 |
| 25 | #if defined(RTC_DISABLE_METRICS) |
| 26 | #define RTC_METRICS_ENABLED 0 |
| 27 | #else |
| 28 | #define RTC_METRICS_ENABLED 1 |
| 29 | #endif |
| 30 |
| 31 | namespace webrtc { |
| 32 | namespace metrics_impl { |
| 33 | template <typename... Ts> |
| 34 | void NoOp(const Ts&...) {} |
| 35 | } // namespace metrics_impl |
| 36 | } // namespace webrtc |
| 37 |
| 38 | #if RTC_METRICS_ENABLED |
| 39 | #define EXPECT_METRIC_EQ(val1, val2) EXPECT_EQ(val1, val2) |
| 40 | #define EXPECT_METRIC_EQ_WAIT(val1, val2, timeout) \ |
| 41 | EXPECT_EQ_WAIT(val1, val2, timeout) |
| 42 | #define EXPECT_METRIC_GT(val1, val2) EXPECT_GT(val1, val2) |
| 43 | #define EXPECT_METRIC_LE(val1, val2) EXPECT_LE(val1, val2) |
| 44 | #define EXPECT_METRIC_TRUE(conditon) EXPECT_TRUE(conditon) |
| 45 | #define EXPECT_METRIC_FALSE(conditon) EXPECT_FALSE(conditon) |
| 46 | #define EXPECT_METRIC_THAT(value, matcher) EXPECT_THAT(value, matcher) |
| 47 | #else |
| 48 | #define EXPECT_METRIC_EQ(val1, val2) webrtc::metrics_impl::NoOp(val1, val2) |
| 49 | #define EXPECT_METRIC_EQ_WAIT(val1, val2, timeout) \ |
| 50 | webrtc::metrics_impl::NoOp(val1, val2, timeout) |
| 51 | #define EXPECT_METRIC_GT(val1, val2) webrtc::metrics_impl::NoOp(val1, val2) |
| 52 | #define EXPECT_METRIC_LE(val1, val2) webrtc::metrics_impl::NoOp(val1, val2) |
| 53 | #define EXPECT_METRIC_TRUE(condition) \ |
| 54 | webrtc::metrics_impl::NoOp(condition || true) |
| 55 | #define EXPECT_METRIC_FALSE(condition) \ |
| 56 | webrtc::metrics_impl::NoOp(condition && false) |
| 57 | #define EXPECT_METRIC_THAT(value, matcher) \ |
| 58 | webrtc::metrics_impl::NoOp(value, testing::_) |
| 59 | #endif |
| 60 |
| 61 | #if RTC_METRICS_ENABLED |
| 62 | // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate |
| 63 | // statistics. |
| 64 | // |
| 65 | // Histogram for counters. |
| 66 | // RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count); |
| 67 | // |
| 68 | // Histogram for enumerators. |
| 69 | // The boundary should be above the max enumerator sample. |
| 70 | // RTC_HISTOGRAM_ENUMERATION(name, sample, boundary); |
| 71 | // |
| 72 | // |
| 73 | // The macros use the methods HistogramFactoryGetCounts, |
| 74 | // HistogramFactoryGetEnumeration and HistogramAdd. |
| 75 | // |
| 76 | // By default WebRTC provides implementations of the aforementioned methods |
| 77 | // that can be found in system_wrappers/source/metrics.cc. If clients want to |
| 78 | // provide a custom version, they will have to: |
| 79 | // |
| 80 | // 1. Compile WebRTC defining the preprocessor macro |
| 81 | // WEBRTC_EXCLUDE_METRICS_DEFAULT (if GN is used this can be achieved |
| 82 | // by setting the GN arg rtc_exclude_metrics_default to true). |
| 83 | // 2. Provide implementations of: |
| 84 | // Histogram* webrtc::metrics::HistogramFactoryGetCounts( |
| 85 | // absl::string_view name, int sample, int min, int max, |
| 86 | // int bucket_count); |
| 87 | // Histogram* webrtc::metrics::HistogramFactoryGetEnumeration( |
| 88 | // absl::string_view name, int sample, int boundary); |
| 89 | // void webrtc::metrics::HistogramAdd( |
| 90 | // Histogram* histogram_pointer, absl::string_view name, int sample); |
| 91 | // |
| 92 | // Example usage: |
| 93 | // |
| 94 | // RTC_HISTOGRAM_COUNTS("WebRTC.Video.NacksSent", nacks_sent, 1, 100000, 100); |
| 95 | // |
| 96 | // enum Types { |
| 97 | // kTypeX, |
| 98 | // kTypeY, |
| 99 | // kBoundary, |
| 100 | // }; |
| 101 | // |
| 102 | // RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary); |
| 103 | // |
| 104 | // NOTE: It is recommended to do the Chromium review for modifications to |
| 105 | // histograms.xml before new metrics are committed to WebRTC. |
| 106 |
| 107 | // Macros for adding samples to a named histogram. |
| 108 |
| 109 | // Histogram for counters (exponentially spaced buckets). |
| 110 | #define RTC_HISTOGRAM_COUNTS_100(name, sample) \ |
| 111 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50) |
| 112 |
| 113 | #define RTC_HISTOGRAM_COUNTS_200(name, sample) \ |
| 114 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50) |
| 115 |
| 116 | #define RTC_HISTOGRAM_COUNTS_500(name, sample) \ |
| 117 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50) |
| 118 |
| 119 | #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ |
| 120 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) |
| 121 |
| 122 | #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ |
| 123 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) |
| 124 |
| 125 | #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ |
| 126 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) |
| 127 |
| 128 | #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ |
| 129 | RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ |
| 130 | webrtc::metrics::HistogramFactoryGetCounts( \ |
| 131 | name, min, max, bucket_count)) |
| 132 |
| 133 | #define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \ |
| 134 | RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ |
| 135 | webrtc::metrics::HistogramFactoryGetCountsLinear( \ |
| 136 | name, min, max, bucket_count)) |
| 137 |
| 138 | // Slow metrics: pointer to metric is acquired at each call and is not cached. |
| 139 | // |
| 140 | #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ |
| 141 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) |
| 142 |
| 143 | #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ |
| 144 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) |
| 145 |
| 146 | #define RTC_HISTOGRAM_COUNTS_SPARSE_500(name, sample) \ |
| 147 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 500, 50) |
| 148 |
| 149 | #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ |
| 150 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) |
| 151 |
| 152 | #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ |
| 153 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) |
| 154 |
| 155 | #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ |
| 156 | RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) |
| 157 |
| 158 | #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ |
| 159 | RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ |
| 160 | webrtc::metrics::HistogramFactoryGetCounts( \ |
| 161 | name, min, max, bucket_count)) |
| 162 |
| 163 | // Histogram for percentage (evenly spaced buckets). |
| 164 | #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ |
| 165 | RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) |
| 166 |
| 167 | // Histogram for booleans. |
| 168 | #define RTC_HISTOGRAM_BOOLEAN_SPARSE(name, sample) \ |
| 169 | RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 2) |
| 170 |
| 171 | // Histogram for enumerators (evenly spaced buckets). |
| 172 | // `boundary` should be above the max enumerator sample. |
| 173 | // |
| 174 | // TODO(qingsi): Refactor the default implementation given by RtcHistogram, |
| 175 | // which is already sparse, and remove the boundary argument from the macro. |
| 176 | #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ |
| 177 | RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \ |
| 178 | name, sample, \ |
| 179 | webrtc::metrics::SparseHistogramFactoryGetEnumeration(name, boundary)) |
| 180 |
| 181 | // Histogram for percentage (evenly spaced buckets). |
| 182 | #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ |
| 183 | RTC_HISTOGRAM_ENUMERATION(name, sample, 101) |
| 184 |
| 185 | // Histogram for booleans. |
| 186 | #define RTC_HISTOGRAM_BOOLEAN(name, sample) \ |
| 187 | RTC_HISTOGRAM_ENUMERATION(name, sample, 2) |
| 188 |
| 189 | // Histogram for enumerators (evenly spaced buckets). |
| 190 | // `boundary` should be above the max enumerator sample. |
| 191 | #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ |
| 192 | RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \ |
| 193 | name, sample, \ |
| 194 | webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) |
| 195 |
| 196 | // The name of the histogram should not vary. |
| 197 | #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ |
| 198 | factory_get_invocation) \ |
| 199 | do { \ |
| 200 | static std::atomic<webrtc::metrics::Histogram*> atomic_histogram_pointer( \ |
| 201 | nullptr); \ |
| 202 | webrtc::metrics::Histogram* histogram_pointer = \ |
| 203 | atomic_histogram_pointer.load(std::memory_order_acquire); \ |
| 204 | if (!histogram_pointer) { \ |
| 205 | histogram_pointer = factory_get_invocation; \ |
| 206 | webrtc::metrics::Histogram* null_histogram = nullptr; \ |
| 207 | atomic_histogram_pointer.compare_exchange_strong(null_histogram, \ |
| 208 | histogram_pointer); \ |
| 209 | } \ |
| 210 | if (histogram_pointer) { \ |
| 211 | webrtc::metrics::HistogramAdd(histogram_pointer, sample); \ |
| 212 | } \ |
| 213 | } while (0) |
| 214 |
| 215 | // The histogram is constructed/found for each call. |
| 216 | // May be used for histograms with infrequent updates.` |
| 217 | #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ |
| 218 | do { \ |
| 219 | webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ |
| 220 | if (histogram_pointer) { \ |
| 221 | webrtc::metrics::HistogramAdd(histogram_pointer, sample); \ |
| 222 | } \ |
| 223 | } while (0) |
| 224 |
| 225 | // Helper macros. |
| 226 | // Macros for calling a histogram with varying name (e.g. when using a metric |
| 227 | // in different modes such as real-time vs screenshare). Fast, because pointer |
| 228 | // is cached. `index` should be different for different names. Allowed `index` |
| 229 | // values are 0, 1, and 2. |
| 230 | #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \ |
| 231 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 232 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)) |
| 233 |
| 234 | #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \ |
| 235 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 236 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)) |
| 237 |
| 238 | #define RTC_HISTOGRAMS_COUNTS_500(index, name, sample) \ |
| 239 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 240 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50)) |
| 241 |
| 242 | #define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \ |
| 243 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 244 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50)) |
| 245 |
| 246 | #define RTC_HISTOGRAMS_COUNTS_10000(index, name, sample) \ |
| 247 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 248 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50)) |
| 249 |
| 250 | #define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \ |
| 251 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 252 | RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) |
| 253 |
| 254 | #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ |
| 255 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 256 | RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) |
| 257 |
| 258 | #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ |
| 259 | RTC_HISTOGRAMS_COMMON(index, name, sample, \ |
| 260 | RTC_HISTOGRAM_PERCENTAGE(name, sample)) |
| 261 |
| 262 | #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ |
| 263 | do { \ |
| 264 | switch (index) { \ |
| 265 | case 0: \ |
| 266 | macro_invocation; \ |
| 267 | break; \ |
| 268 | case 1: \ |
| 269 | macro_invocation; \ |
| 270 | break; \ |
| 271 | case 2: \ |
| 272 | macro_invocation; \ |
| 273 | break; \ |
| 274 | default: \ |
| 275 | RTC_DCHECK_NOTREACHED(); \ |
| 276 | } \ |
| 277 | } while (0) |
| 278 |
| 279 | #else |
| 280 |
| 281 | //////////////////////////////////////////////////////////////////////////////// |
| 282 | // This section defines no-op alternatives to the metrics macros when |
| 283 | // RTC_METRICS_ENABLED is defined. |
| 284 |
| 285 | #define RTC_HISTOGRAM_COUNTS_100(name, sample) \ |
| 286 | webrtc::metrics_impl::NoOp(name, sample) |
| 287 |
| 288 | #define RTC_HISTOGRAM_COUNTS_200(name, sample) \ |
| 289 | webrtc::metrics_impl::NoOp(name, sample) |
| 290 |
| 291 | #define RTC_HISTOGRAM_COUNTS_500(name, sample) \ |
| 292 | webrtc::metrics_impl::NoOp(name, sample) |
| 293 |
| 294 | #define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ |
| 295 | webrtc::metrics_impl::NoOp(name, sample) |
| 296 |
| 297 | #define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ |
| 298 | webrtc::metrics_impl::NoOp(name, sample) |
| 299 |
| 300 | #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ |
| 301 | webrtc::metrics_impl::NoOp(name, sample) |
| 302 |
| 303 | #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ |
| 304 | webrtc::metrics_impl::NoOp(name, sample, min, max, bucket_count) |
| 305 |
| 306 | #define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \ |
| 307 | webrtc::metrics_impl::NoOp(name, sample, min, max, bucket_count) |
| 308 |
| 309 | #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ |
| 310 | webrtc::metrics_impl::NoOp(name, sample) |
| 311 |
| 312 | #define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ |
| 313 | webrtc::metrics_impl::NoOp(name, sample) |
| 314 |
| 315 | #define RTC_HISTOGRAM_COUNTS_SPARSE_500(name, sample) \ |
| 316 | webrtc::metrics_impl::NoOp(name, sample) |
| 317 |
| 318 | #define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ |
| 319 | webrtc::metrics_impl::NoOp(name, sample) |
| 320 |
| 321 | #define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ |
| 322 | webrtc::metrics_impl::NoOp(name, sample) |
| 323 |
| 324 | #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ |
| 325 | webrtc::metrics_impl::NoOp(name, sample) |
| 326 |
| 327 | #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ |
| 328 | webrtc::metrics_impl::NoOp(name, sample, min, max, bucket_count) |
| 329 |
| 330 | #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ |
| 331 | webrtc::metrics_impl::NoOp(name, sample) |
| 332 |
| 333 | #define RTC_HISTOGRAM_BOOLEAN_SPARSE(name, sample) \ |
| 334 | webrtc::metrics_impl::NoOp(name, sample) |
| 335 |
| 336 | #define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ |
| 337 | webrtc::metrics_impl::NoOp(name, sample, boundary) |
| 338 |
| 339 | #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ |
| 340 | webrtc::metrics_impl::NoOp(name, sample) |
| 341 |
| 342 | #define RTC_HISTOGRAM_BOOLEAN(name, sample) \ |
| 343 | webrtc::metrics_impl::NoOp(name, sample) |
| 344 |
| 345 | #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ |
| 346 | webrtc::metrics_impl::NoOp(name, sample, boundary) |
| 347 |
| 348 | #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ |
| 349 | factory_get_invocation) \ |
| 350 | webrtc::metrics_impl::NoOp(constant_name, sample, factory_get_invocation) |
| 351 |
| 352 | #define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ |
| 353 | webrtc::metrics_impl::NoOp(name, sample, factory_get_invocation) |
| 354 |
| 355 | #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \ |
| 356 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 357 |
| 358 | #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \ |
| 359 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 360 |
| 361 | #define RTC_HISTOGRAMS_COUNTS_500(index, name, sample) \ |
| 362 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 363 |
| 364 | #define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \ |
| 365 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 366 |
| 367 | #define RTC_HISTOGRAMS_COUNTS_10000(index, name, sample) \ |
| 368 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 369 |
| 370 | #define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \ |
| 371 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 372 |
| 373 | #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ |
| 374 | webrtc::metrics_impl::NoOp(index, name, sample, boundary) |
| 375 |
| 376 | #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ |
| 377 | webrtc::metrics_impl::NoOp(index, name, sample) |
| 378 |
| 379 | #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ |
| 380 | webrtc::metrics_impl::NoOp(index, name, sample, macro_invocation) |
| 381 |
| 382 | #endif // RTC_METRICS_ENABLED |
| 383 |
| 384 | namespace webrtc { |
| 385 | namespace metrics { |
| 386 |
| 387 | // Time that should have elapsed for stats that are gathered once per call. |
| 388 | constexpr int kMinRunTimeInSeconds = 10; |
| 389 |
| 390 | class Histogram; |
| 391 |
| 392 | // Functions for getting pointer to histogram (constructs or finds the named |
| 393 | // histogram). |
| 394 |
| 395 | // Get histogram for counters. |
| 396 | Histogram* HistogramFactoryGetCounts(absl::string_view name, |
| 397 | int min, |
| 398 | int max, |
| 399 | int bucket_count); |
| 400 |
| 401 | // Get histogram for counters with linear bucket spacing. |
| 402 | Histogram* HistogramFactoryGetCountsLinear(absl::string_view name, |
| 403 | int min, |
| 404 | int max, |
| 405 | int bucket_count); |
| 406 |
| 407 | // Get histogram for enumerators. |
| 408 | // `boundary` should be above the max enumerator sample. |
| 409 | Histogram* HistogramFactoryGetEnumeration(absl::string_view name, int boundary); |
| 410 |
| 411 | // Get sparse histogram for enumerators. |
| 412 | // `boundary` should be above the max enumerator sample. |
| 413 | Histogram* SparseHistogramFactoryGetEnumeration(absl::string_view name, |
| 414 | int boundary); |
| 415 |
| 416 | // Function for adding a `sample` to a histogram. |
| 417 | void HistogramAdd(Histogram* histogram_pointer, int sample); |
| 418 |
| 419 | struct SampleInfo { |
| 420 | SampleInfo(absl::string_view name, int min, int max, size_t bucket_count); |
| 421 | ~SampleInfo(); |
| 422 |
| 423 | const std::string name; |
| 424 | const int min; |
| 425 | const int max; |
| 426 | const size_t bucket_count; |
| 427 | std::map<int, int> samples; // <value, # of events> |
| 428 | }; |
| 429 |
| 430 | // Enables collection of samples. |
| 431 | // This method should be called before any other call into webrtc. |
| 432 | void Enable(); |
| 433 |
| 434 | // Gets histograms and clears all samples. |
| 435 | void GetAndReset( |
| 436 | std::map<std::string, std::unique_ptr<SampleInfo>, rtc::AbslStringViewCmp>* |
| 437 | histograms); |
| 438 |
| 439 | // Functions below are mainly for testing. |
| 440 |
| 441 | // Clears all samples. |
| 442 | void Reset(); |
| 443 |
| 444 | // Returns the number of times the `sample` has been added to the histogram. |
| 445 | int NumEvents(absl::string_view name, int sample); |
| 446 |
| 447 | // Returns the total number of added samples to the histogram. |
| 448 | int NumSamples(absl::string_view name); |
| 449 |
| 450 | // Returns the minimum sample value (or -1 if the histogram has no samples). |
| 451 | int MinSample(absl::string_view name); |
| 452 |
| 453 | // Returns a map with keys the samples with at least one event and values the |
| 454 | // number of events for that sample. |
| 455 | std::map<int, int> Samples(absl::string_view name); |
| 456 |
| 457 | } // namespace metrics |
| 458 | } // namespace webrtc |
| 459 |
| 460 | #endif // SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ |
| 461 |