From f29e05d774005eab99956f28b5a384509ea6b295 Mon Sep 17 00:00:00 2001 From: "henrik.lundin" Date: Thu, 1 Dec 2016 09:58:45 -0800 Subject: [PATCH] Add linearly spaced counting histograms This change adds HistogramFactoryGetCountsLinear and RTC_HISTOGRAM_COUNTS_LINEAR. Note that the default implementation of HistogramFactoryGetCounts in metrics_default.cc also provides a linearly spaced histogram, while the Chrome UMA implementation provides exponentially spaced buckets. BUG=none Review-Url: https://codereview.webrtc.org/2548463002 Cr-Commit-Position: refs/heads/master@{#15367} --- webrtc/system_wrappers/include/metrics.h | 11 +++++++++++ webrtc/system_wrappers/source/metrics_default.cc | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/webrtc/system_wrappers/include/metrics.h b/webrtc/system_wrappers/include/metrics.h index 9b14736ec2..25a51807de 100644 --- a/webrtc/system_wrappers/include/metrics.h +++ b/webrtc/system_wrappers/include/metrics.h @@ -85,6 +85,11 @@ RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) +#define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \ + RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ + webrtc::metrics::HistogramFactoryGetCountsLinear( \ + name, min, max, bucket_count)) + // Deprecated. // TODO(asapersson): Remove. #define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ @@ -213,6 +218,12 @@ class Histogram; Histogram* HistogramFactoryGetCounts( const std::string& name, int min, int max, int bucket_count); +// Get histogram for counters with linear bucket spacing. +Histogram* HistogramFactoryGetCountsLinear(const std::string& name, + int min, + int max, + int bucket_count); + // Get histogram for enumerators. // |boundary| should be above the max enumerator sample. Histogram* HistogramFactoryGetEnumeration( diff --git a/webrtc/system_wrappers/source/metrics_default.cc b/webrtc/system_wrappers/source/metrics_default.cc index d7d24fa50d..6ca90dafdc 100644 --- a/webrtc/system_wrappers/source/metrics_default.cc +++ b/webrtc/system_wrappers/source/metrics_default.cc @@ -213,6 +213,19 @@ Histogram* HistogramFactoryGetCounts(const std::string& name, int min, int max, int bucket_count) { + // TODO(asapersson): Alternative implementation will be needed if this + // histogram type should be truly exponential. + return HistogramFactoryGetCountsLinear(name, min, max, bucket_count); +} + +// Histogram with linearly spaced buckets. +// Creates (or finds) histogram. +// The returned histogram pointer is cached (and used for adding samples in +// subsequent calls). +Histogram* HistogramFactoryGetCountsLinear(const std::string& name, + int min, + int max, + int bucket_count) { RtcHistogramMap* map = GetMap(); if (!map) return nullptr;