Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: webrtc/base/histogram.cc

Issue 2654473002: Remove static locals from histograms. (Closed)
Patch Set: use another HistogramBase constructor for enumerations Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/histogram.h ('k') | webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/histogram.cc
diff --git a/webrtc/base/histogram.cc b/webrtc/base/histogram.cc
new file mode 100644
index 0000000000000000000000000000000000000000..179a9c946d700da83f0f583667b276b3331cadad
--- /dev/null
+++ b/webrtc/base/histogram.cc
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "webrtc/base/histogram.h"
+
+#include "webrtc/base/checks.h"
+#include "webrtc/system_wrappers/include/metrics.h"
+
+namespace rtc {
+
+HistogramBase::HistogramBase(const char* name,
+ Type type,
+ int min,
+ int max,
+ int bucket_count)
+ : histogram_(type == Type::kCounts
+ ? webrtc::metrics::HistogramFactoryGetCounts(name,
+ min,
+ max,
+ bucket_count)
+ : webrtc::metrics::HistogramFactoryGetCountsLinear(
+ name,
+ min,
+ max,
+ bucket_count)) {
+ RTC_DCHECK(type == Type::kCounts || type == Type::kCountsLinear);
+}
+
+HistogramBase::HistogramBase(const char* name, Type type, int boundary)
+ : histogram_(
+ webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) {
+ // Enumerations should only specify boundary, other types should use the other
+ // constructor.
+ RTC_DCHECK(type == Type::kEnumeration);
+}
+
+void HistogramBase::AddSample(int sample) const {
+ webrtc::metrics::HistogramAdd(histogram_, sample);
+}
+
+// Histograms for counts with exponentionally spaced buckets.
+Histogram::Histogram(const char* name, int max) : Histogram(name, 1, max) {}
+Histogram::Histogram(const char* name, int min, int max)
+ : Histogram(name, min, max, 50) {}
+Histogram::Histogram(const char* name, int min, int max, int bucket_count)
+ : HistogramBase(name, Type::kCounts, min, max, bucket_count) {}
+
+
+// Histograms with linear spaced buckets.
+HistogramLinear::HistogramLinear(const char* name, int max)
+ : HistogramLinear(name, 1, max) {}
+HistogramLinear::HistogramLinear(const char* name, int min, int max)
+ : HistogramLinear(name, min, max, 50) {}
+HistogramLinear::HistogramLinear(const char* name,
+ int min,
+ int max,
+ int bucket_count)
+ : HistogramBase(name, Type::kCountsLinear, min, max, bucket_count) {}
+
+// Histograms for enumerations, values in [0, boundary) are valid.
+HistogramEnumeration::HistogramEnumeration(const char* name, int boundary)
+ : HistogramBase(name, Type::kEnumeration, boundary),
+ boundary_(boundary) {}
+void HistogramEnumeration::AddSample(int sample) {
+ RTC_DCHECK_GE(sample, 0);
+ RTC_DCHECK_LE(sample, boundary_);
+ HistogramBase::AddSample(sample);
+}
+
+// Histograms for booleans.
+HistogramBoolean::HistogramBoolean(const char* name)
+ : HistogramEnumeration(name, 2) {}
+void HistogramBoolean::AddSample(bool sample) {
+ HistogramEnumeration::AddSample(sample ? 1 : 0);
+}
+
+// Histograms for percentages.
+HistogramPercentage::HistogramPercentage(const char* name)
+ : HistogramEnumeration(name, 101) {}
+
+} // namespace rtc
« no previous file with comments | « webrtc/base/histogram.h ('k') | webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698