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

Unified Diff: base/metrics/histogram_functions.h

Issue 2393493002: Expose macros from base/metrics/histogram_macros.h as functions (Closed)
Patch Set: Review comments. Pass 1 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.h
diff --git a/base/metrics/histogram_functions.h b/base/metrics/histogram_functions.h
new file mode 100644
index 0000000000000000000000000000000000000000..a994f5fbd57e16d607d8b03234e14d45af1258c9
--- /dev/null
+++ b/base/metrics/histogram_functions.h
@@ -0,0 +1,100 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
+#define BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
+
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_base.h"
+#include "base/time/time.h"
+
+// Functions for recording metrics.
+//
+// For best practices on deciding when to emit to a histogram and what form
+// the histogram should take, see
+// https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/README.md
+
+// Functions for recording UMA histograms. These can be used for cases
+// when histogram name is generated at runtime. The functionality is
Alexei Svitkine (slow) 2016/11/12 01:43:45 Nit: "when the histogram name"
nikunjb 2016/11/12 02:06:53 Done.
+// equivalent to macros defined in histogram_macros.h for recording histogram.
Alexei Svitkine (slow) 2016/11/12 01:43:45 Nit: Remove "for recording histogram"
nikunjb 2016/11/12 02:06:53 Done.
+// Although with flexibility that histogram names and values needn't be
+// constants.
Alexei Svitkine (slow) 2016/11/12 01:43:45 Nit: Combine with the previous sentence. Also sugg
nikunjb 2016/11/12 02:06:53 Done.
+// These functions are slower compared to their macro equivalent by about a few
+// additional memory lookups. So, these shouldn't be used in performance
Alexei Svitkine (slow) 2016/11/12 01:43:45 Nit: "By about a few additional memory lookups" so
nikunjb 2016/11/12 02:06:53 Done. Rephrased to add additional comment. I wante
+// critical code.
+namespace base {
+
+// 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);
+BASE_EXPORT void UmaHistogramExactLinear(
+ const std::string& name, int sample, int value_max);
+
+// For adding sample to enum histogram.
+// Sample usage:
+// base::UmaHistogramEnumeration("My.Enumeration", VALUE, EVENT_MAX_VALUE);
+// Note that new Enum values can be added, but existing enums must never be
+// renumbered or deleted and reused.
+template <typename T> void UmaHistogramEnumeration(
+ const std::string& name, T sample, T max) {
+ static_assert(
+ std::is_enum<T>::value, "Non enum passed to UmaHistogramEnumeration");
+ return UmaHistogramExactLinear(name, static_cast<int>(sample), max);
+}
+
+// For adding boolean sample to histogram.
+// Sample usage:
+// base::UmaHistogramBoolean("My.Boolean", true)
+BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
+
+// For adding histogram with percent.
+// Percents are integer between 1 and 100.
+// Sample usage:
+// base::UmaHistogramPercentage("My.Percent", 69)
+BASE_EXPORT void UmaHistogramPercentage(
+ const std::string& name, int percent);
+
+// For adding counts histogram.
+// Sample usage:
+// base::UmaHistogramCounts("My.Counts", some_value, 1, 600, 30)
+BASE_EXPORT void UmaHistogramCustomCounts(
+ const std::string& name, int sample, int min, int max, int buckets);
+
+// Counts specialization for maximum counts 100, 1000, 10k, 100k, 1M and 10M.
+BASE_EXPORT void UmaHistogramCounts100(const std::string& name, int sample);
+BASE_EXPORT void UmaHistogramCounts1000(const std::string& name, int sample);
+BASE_EXPORT void UmaHistogramCounts10000(const std::string& name, int sample);
+BASE_EXPORT void UmaHistogramCounts100000(const std::string& name, int sample);
+BASE_EXPORT void UmaHistogramCounts1M(const std::string& name, int sample);
+BASE_EXPORT void UmaHistogramCounts10M(const std::string& name, int sample);
+
+// For histograms storing times.
+BASE_EXPORT void UmaHistogramCustomTimes(
+ const std::string& name, TimeDelta sample, TimeDelta min,
+ TimeDelta max, int buckets);
+// For short timings from 1 ms up to 10 seconds (50 buckets).
+BASE_EXPORT void UmaHistogramTimes(const std::string& name, TimeDelta sample);
+// For medium timings up to 3 minutes (50 buckets).
+BASE_EXPORT void UmaHistogramMediumTimes(
+ const std::string& name, TimeDelta sample);
+// For time intervals up to 1 hr (50 buckets).
+BASE_EXPORT void UmaHistogramLongTimes(
+ const std::string& name, TimeDelta sample);
+// For time intervals up to 1 hr (100 buckets).
+BASE_EXPORT void UmaHistogramLongTimes100(
+ const std::string& name, TimeDelta sample);
+
+// For recording memory related histograms.
+// Used to measure common KB-granularity memory stats. Range is up to 500M.
+BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
+// Used to measure common MB-granularity memory stats. Range is up to ~64G.
+BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
+
+} // namespace base
+
+#endif // BASE_METRICS_HISTOGRAM_FUNCTIONS_H_

Powered by Google App Engine
This is Rietveld 408576698