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

Unified Diff: base/metrics/histogram_functions.cc

Issue 2393493002: Expose macros from base/metrics/histogram_macros.h as functions (Closed)
Patch Set: Add Histogram functions API implementation and tests Created 4 years, 1 month 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
Index: base/metrics/histogram_functions.cc
diff --git a/base/metrics/histogram_functions.cc b/base/metrics/histogram_functions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7ee776dfd486d7445e31b790c7343b5065b83db
--- /dev/null
+++ b/base/metrics/histogram_functions.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
Alexei Svitkine (slow) 2016/11/12 00:51:14 2016 and remove the (c)
nikunjb 2016/11/12 01:35:15 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/metrics/histogram_functions.h"
+
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_base.h"
+#include "base/time/time.h"
+
+namespace base {
+
+// For adding boolean sample to histogram.
+// Sample usage:
+// base::UmaHistogramBoolean("My.Boolean", true)
Alexei Svitkine (slow) 2016/11/12 00:51:14 Remove the function comments from the .cc - they s
nikunjb 2016/11/12 01:35:15 Done.
+void UmaHistogramBoolean(const std::string& name, bool sample) {
+ HistogramBase* histogram = BooleanHistogram::FactoryGet(
+ name, base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(sample);
+}
+
+// For histograms with linear buckets.
+// Used for capturing integer data with a linear bucketing scheme. This can be
+// used when you want the exact value of some small numeric count, with a max of
+// 100 or less. If you need to capture a range of greater than 100, we recommend
+// the use of the COUNT histograms below.
+// Sample usage:
+// base::UmaHistogramExactLinear("Histogram.Linear", some_value, 10);
+void UmaHistogramExactLinear(
+ const std::string& name, int sample, int value_max) {
+ HistogramBase* histogram = LinearHistogram::FactoryGet(
+ name, 1, value_max, value_max + 1,
+ HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(sample);
+}
+
+// For adding histogram with percent.
+// Percents are integer between 1 and 100.
+// Sample usage:
+// base::UmaHistogramPercentage("My.Percent", 69)
+void UmaHistogramPercentage(const std::string& name, int percent) {
+ UmaHistogramExactLinear(name, percent, 100);
+}
+
+// For adding counts histogram.
+// Sample usage:
+// base::UmaHistogramCounts("My.Counts", some_value, 1, 600, 30)
+void UmaHistogramCustomCounts(
+ const std::string& name, int sample, int min, int max, int buckets) {
+ HistogramBase* histogram = Histogram::FactoryGet(
+ name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(sample);
+}
+
+// Counts specialization for maximum counts 100, 1000, 10k, 100k, 1M and 10M.
+void UmaHistogramCounts100(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 100, 50);
+}
+
+void UmaHistogramCounts1000(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
+}
+
+void UmaHistogramCounts10000(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 10000, 50);
+}
+
+void UmaHistogramCounts100000(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 100000, 50);
+}
+
+void UmaHistogramCounts1M(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 1000000, 50);
+}
+
+void UmaHistogramCounts10M(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 10000000, 50);
+}
+
+// For histograms storing times.
+void UmaHistogramCustomTimes(
+ const std::string& name, const TimeDelta& sample, const TimeDelta& min,
+ const TimeDelta& max, int buckets) {
+ HistogramBase* histogram = Histogram::FactoryTimeGet(
+ name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->AddTime(sample);
+}
+
+void UmaHistogramTimes(const std::string& name, const TimeDelta& sample){
+ UmaHistogramCustomTimes(
+ name, sample, TimeDelta::FromMilliseconds(1),
+ TimeDelta::FromSeconds(10), 50);
+}
+
+void UmaHistogramMediumTimes(const std::string& name, const TimeDelta& sample) {
+ UmaHistogramCustomTimes(
+ name, sample, TimeDelta::FromMilliseconds(1),
+ TimeDelta::FromMinutes(3), 50);
+}
+
+void UmaHistogramLongTimes(const std::string& name, const TimeDelta& sample) {
+ UmaHistogramCustomTimes(
+ name, sample, TimeDelta::FromMilliseconds(1),
+ TimeDelta::FromHours(1), 50);
+}
+
+void UmaHistogramLongTimes100(
+ const std::string& name, const TimeDelta& sample) {
+ UmaHistogramCustomTimes(
+ name, sample, TimeDelta::FromMilliseconds(1),
+ TimeDelta::FromHours(1), 100);
+}
+
+// For recording memory related histograms.
+void UmaHistogramMemoryKB(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
+}
+
+void UmaHistogramMemoryLargeMB(const std::string& name, int sample) {
+ UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
+}
+
+} //namespace base

Powered by Google App Engine
This is Rietveld 408576698