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

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

Issue 2393493002: Expose macros from base/metrics/histogram_macros.h as functions (Closed)
Patch Set: Review comments 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 2016 The Chromium Authors. All rights reserved.
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 // Functions for recording UMA histograms. These can be used for cases
19 // when the histogram name is generated at runtime. The functionality is
20 // equivalent to macros defined in histogram_macros.h but allowing non-constant
21 // histogram names. These functions are slower compared to their macro
22 // equivalent because the histogram objects are not cached between calls.
23 // So, these shouldn't be used in performance critical code.
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(const std::string& name,
34 int sample,
35 int value_max);
36
37 // For adding sample to enum histogram.
38 // Sample usage:
39 // base::UmaHistogramEnumeration("My.Enumeration", VALUE, EVENT_MAX_VALUE);
40 // Note that new Enum values can be added, but existing enums must never be
41 // renumbered or deleted and reused.
42 template <typename T>
43 void UmaHistogramEnumeration(const std::string& name, T sample, T max) {
44 static_assert(std::is_enum<T>::value,
45 "Non enum passed to UmaHistogramEnumeration");
46 return UmaHistogramExactLinear(name, static_cast<int>(sample), max);
47 }
48
49 // For adding boolean sample to histogram.
50 // Sample usage:
51 // base::UmaHistogramBoolean("My.Boolean", true)
52 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
53
54 // For adding histogram with percent.
55 // Percents are integer between 1 and 100.
56 // Sample usage:
57 // base::UmaHistogramPercentage("My.Percent", 69)
58 BASE_EXPORT void UmaHistogramPercentage(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(const std::string& name,
64 int sample,
65 int min,
66 int max,
67 int buckets);
68
69 // Counts specialization for maximum counts 100, 1000, 10k, 100k, 1M and 10M.
70 BASE_EXPORT void UmaHistogramCounts100(const std::string& name, int sample);
71 BASE_EXPORT void UmaHistogramCounts1000(const std::string& name, int sample);
72 BASE_EXPORT void UmaHistogramCounts10000(const std::string& name, int sample);
73 BASE_EXPORT void UmaHistogramCounts100000(const std::string& name, int sample);
74 BASE_EXPORT void UmaHistogramCounts1M(const std::string& name, int sample);
75 BASE_EXPORT void UmaHistogramCounts10M(const std::string& name, int sample);
76
77 // For histograms storing times.
78 BASE_EXPORT void UmaHistogramCustomTimes(const std::string& name,
79 TimeDelta sample,
80 TimeDelta min,
81 TimeDelta max,
82 int buckets);
83 // For short timings from 1 ms up to 10 seconds (50 buckets).
84 BASE_EXPORT void UmaHistogramTimes(const std::string& name, TimeDelta sample);
85 // For medium timings up to 3 minutes (50 buckets).
86 BASE_EXPORT void UmaHistogramMediumTimes(const std::string& name,
87 TimeDelta sample);
88 // For time intervals up to 1 hr (50 buckets).
89 BASE_EXPORT void UmaHistogramLongTimes(const std::string& name,
90 TimeDelta sample);
91
92 // For recording memory related histograms.
93 // Used to measure common KB-granularity memory stats. Range is up to 500M.
94 BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
95 // Used to measure common MB-granularity memory stats. Range is up to ~64G.
96 BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
97
98 } // namespace base
99
100 #endif // BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698