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

Side by Side Diff: base/metrics/histogram_functions.h

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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
Alexei Svitkine (slow) 2016/11/12 00:51:14 2016
nikunjb 2016/11/12 01:35:15 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
6 #define BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
7
8 #include "base/metrics/histogram.h"
9 #include "base/metrics/histogram_base.h"
10 #include "base/time/time.h"
11
12 // Functions for recording metrics.
13 //
14 // For best practices on deciding when to emit to a histogram and what form
15 // the histogram should take, see
16 // https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histo grams/README.md
17
18 // The functions for recording histograms here are equivalent to macros
19 // defined in histogram_macros.h except the function equivalents are
20 // slower and should not be called from tight loops.
21 // Using function calls is ideal when histogram names are generated and it is
22 // not possible to pass that to macro expansion.
Alexei Svitkine (slow) 2016/11/12 00:51:14 I would rephrase this and the previous sentence to
nikunjb 2016/11/12 01:35:15 Done.
23
24 namespace base {
25
26 // For histograms with linear buckets.
27 // Used for capturing integer data with a linear bucketing scheme. This can be
28 // used when you want the exact value of some small numeric count, with a max of
29 // 100 or less. If you need to capture a range of greater than 100, we recommend
30 // the use of the COUNT histograms below.
31 // Sample usage:
32 // base::UmaHistogramExactLinear("Histogram.Linear", some_value, 10);
33 BASE_EXPORT void UmaHistogramExactLinear(
34 const std::string& name, int sample, int value_max);
35
36 // For adding sample to enum histogram.
37 // Sample usage:
38 // base::UmaHistogramEnumeration("My.Enumeration", VALUE, EVENT_MAX_VALUE);
39 // Note that new Enum values can be added, but existing enums must never be
40 // renumbered or deleted and reused.
41 template <typename T> void UmaHistogramEnumeration(
42 const std::string& name, T sample, T max) {
43 static_assert(
44 std::is_enum<T>::value, "Non enum passed to UmaHistogramEnumeration");
45 return UmaHistogramExactLinear(name, static_cast<int>(sample), max);
46 }
47
48 // For adding boolean sample to histogram.
49 // Sample usage:
50 // base::UmaHistogramBoolean("My.Boolean", true)
51 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
52
53 // For adding histogram with percent.
54 // Percents are integer between 1 and 100.
55 // Sample usage:
56 // base::UmaHistogramPercentage("My.Percent", 69)
57 BASE_EXPORT void UmaHistogramPercentage(
58 const std::string& name, int percent);
59
60 // For adding counts histogram.
61 // Sample usage:
62 // base::UmaHistogramCounts("My.Counts", some_value, 1, 600, 30)
63 BASE_EXPORT void UmaHistogramCustomCounts(
64 const std::string& name, int sample, int min, int max, int buckets);
65
66 // Counts specialization for maximum counts 100, 1000, 10k, 100k, 1M and 10M.
67 BASE_EXPORT void UmaHistogramCounts100(const std::string& name, int sample);
68 BASE_EXPORT void UmaHistogramCounts1000(const std::string& name, int sample);
69 BASE_EXPORT void UmaHistogramCounts10000(const std::string& name, int sample);
70 BASE_EXPORT void UmaHistogramCounts100000(const std::string& name, int sample);
71 BASE_EXPORT void UmaHistogramCounts1M(const std::string& name, int sample);
72 BASE_EXPORT void UmaHistogramCounts10M(const std::string& name, int sample);
73
74 // For histograms storing times.
75 BASE_EXPORT void UmaHistogramCustomTimes(
76 const std::string& name, const TimeDelta& sample, const TimeDelta& min,
77 const TimeDelta& max, int buckets);
78 // For short timings from 1 ms up to 10 seconds (50 buckets).
79 BASE_EXPORT void UmaHistogramTimes(
80 const std::string& name, const TimeDelta& sample);
81 // For medium timings up to 3 minutes (50 buckets).
82 BASE_EXPORT void UmaHistogramMediumTimes(
83 const std::string& name, const TimeDelta& sample);
84 // For time intervals up to 1 hr (50 buckets).
85 BASE_EXPORT void UmaHistogramLongTimes(
86 const std::string& name, const TimeDelta& sample);
87 // For time intervals up to 1 hr (100 buckets).
88 BASE_EXPORT void UmaHistogramLongTimes100(
89 const std::string& name, const TimeDelta& sample);
90
91 // For recording memory related histograms.
92 // Used to measure common KB-granularity memory stats. Range is up to 500M.
93 BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
94 // Used to measure common MB-granularity memory stats. Range is up to ~64G.
95 BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
96
97 } // namespace base
98
99 #endif // BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698