OLD | NEW |
---|---|
(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 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.
| |
20 // 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.
| |
21 // Although with flexibility that histogram names and values needn't be | |
22 // 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.
| |
23 // These functions are slower compared to their macro equivalent by about a few | |
24 // 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
| |
25 // critical code. | |
26 namespace base { | |
27 | |
28 // For histograms with linear buckets. | |
29 // Used for capturing integer data with a linear bucketing scheme. This can be | |
30 // used when you want the exact value of some small numeric count, with a max of | |
31 // 100 or less. If you need to capture a range of greater than 100, we recommend | |
32 // the use of the COUNT histograms below. | |
33 // Sample usage: | |
34 // base::UmaHistogramExactLinear("Histogram.Linear", some_value, 10); | |
35 BASE_EXPORT void UmaHistogramExactLinear( | |
36 const std::string& name, int sample, int value_max); | |
37 | |
38 // For adding sample to enum histogram. | |
39 // Sample usage: | |
40 // base::UmaHistogramEnumeration("My.Enumeration", VALUE, EVENT_MAX_VALUE); | |
41 // Note that new Enum values can be added, but existing enums must never be | |
42 // renumbered or deleted and reused. | |
43 template <typename T> void UmaHistogramEnumeration( | |
44 const std::string& name, T sample, T max) { | |
45 static_assert( | |
46 std::is_enum<T>::value, "Non enum passed to UmaHistogramEnumeration"); | |
47 return UmaHistogramExactLinear(name, static_cast<int>(sample), max); | |
48 } | |
49 | |
50 // For adding boolean sample to histogram. | |
51 // Sample usage: | |
52 // base::UmaHistogramBoolean("My.Boolean", true) | |
53 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample); | |
54 | |
55 // For adding histogram with percent. | |
56 // Percents are integer between 1 and 100. | |
57 // Sample usage: | |
58 // base::UmaHistogramPercentage("My.Percent", 69) | |
59 BASE_EXPORT void UmaHistogramPercentage( | |
60 const std::string& name, int percent); | |
61 | |
62 // For adding counts histogram. | |
63 // Sample usage: | |
64 // base::UmaHistogramCounts("My.Counts", some_value, 1, 600, 30) | |
65 BASE_EXPORT void UmaHistogramCustomCounts( | |
66 const std::string& name, int sample, int min, int max, int buckets); | |
67 | |
68 // Counts specialization for maximum counts 100, 1000, 10k, 100k, 1M and 10M. | |
69 BASE_EXPORT void UmaHistogramCounts100(const std::string& name, int sample); | |
70 BASE_EXPORT void UmaHistogramCounts1000(const std::string& name, int sample); | |
71 BASE_EXPORT void UmaHistogramCounts10000(const std::string& name, int sample); | |
72 BASE_EXPORT void UmaHistogramCounts100000(const std::string& name, int sample); | |
73 BASE_EXPORT void UmaHistogramCounts1M(const std::string& name, int sample); | |
74 BASE_EXPORT void UmaHistogramCounts10M(const std::string& name, int sample); | |
75 | |
76 // For histograms storing times. | |
77 BASE_EXPORT void UmaHistogramCustomTimes( | |
78 const std::string& name, TimeDelta sample, TimeDelta min, | |
79 TimeDelta max, int buckets); | |
80 // For short timings from 1 ms up to 10 seconds (50 buckets). | |
81 BASE_EXPORT void UmaHistogramTimes(const std::string& name, TimeDelta sample); | |
82 // For medium timings up to 3 minutes (50 buckets). | |
83 BASE_EXPORT void UmaHistogramMediumTimes( | |
84 const std::string& name, TimeDelta sample); | |
85 // For time intervals up to 1 hr (50 buckets). | |
86 BASE_EXPORT void UmaHistogramLongTimes( | |
87 const std::string& name, TimeDelta sample); | |
88 // For time intervals up to 1 hr (100 buckets). | |
89 BASE_EXPORT void UmaHistogramLongTimes100( | |
90 const std::string& name, 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_ | |
OLD | NEW |