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

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

Issue 2801613002: Allow UmaHistogramEnumeration to be used with enum classes. (Closed)
Patch Set: dcheng magic Created 3 years, 8 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_METRICS_HISTOGRAM_FUNCTIONS_H_ 5 #ifndef BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
6 #define BASE_METRICS_HISTOGRAM_FUNCTIONS_H_ 6 #define BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
7 7
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/histogram_base.h" 9 #include "base/metrics/histogram_base.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 25 matching lines...) Expand all
36 36
37 // For adding sample to enum histogram. 37 // For adding sample to enum histogram.
38 // Sample usage: 38 // Sample usage:
39 // base::UmaHistogramEnumeration("My.Enumeration", VALUE, EVENT_MAX_VALUE); 39 // base::UmaHistogramEnumeration("My.Enumeration", VALUE, EVENT_MAX_VALUE);
40 // Note that new Enum values can be added, but existing enums must never be 40 // Note that new Enum values can be added, but existing enums must never be
41 // renumbered or deleted and reused. 41 // renumbered or deleted and reused.
42 template <typename T> 42 template <typename T>
43 void UmaHistogramEnumeration(const std::string& name, T sample, T max) { 43 void UmaHistogramEnumeration(const std::string& name, T sample, T max) {
44 static_assert(std::is_enum<T>::value, 44 static_assert(std::is_enum<T>::value,
45 "Non enum passed to UmaHistogramEnumeration"); 45 "Non enum passed to UmaHistogramEnumeration");
46 return UmaHistogramExactLinear(name, static_cast<int>(sample), max); 46 DCHECK_LE(static_cast<uintmax_t>(max), static_cast<uintmax_t>(INT_MAX));
47 DCHECK_LE(static_cast<uintmax_t>(sample), static_cast<uintmax_t>(max));
48 return UmaHistogramExactLinear(name, static_cast<int>(sample),
49 static_cast<int>(max));
47 } 50 }
48 51
49 // For adding boolean sample to histogram. 52 // For adding boolean sample to histogram.
50 // Sample usage: 53 // Sample usage:
51 // base::UmaHistogramBoolean("My.Boolean", true) 54 // base::UmaHistogramBoolean("My.Boolean", true)
52 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample); 55 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
53 56
54 // For adding histogram with percent. 57 // For adding histogram with percent.
55 // Percents are integer between 1 and 100. 58 // Percents are integer between 1 and 100.
56 // Sample usage: 59 // Sample usage:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 94
92 // For recording memory related histograms. 95 // For recording memory related histograms.
93 // Used to measure common KB-granularity memory stats. Range is up to 500M. 96 // Used to measure common KB-granularity memory stats. Range is up to 500M.
94 BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample); 97 BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
95 // Used to measure common MB-granularity memory stats. Range is up to ~64G. 98 // Used to measure common MB-granularity memory stats. Range is up to ~64G.
96 BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample); 99 BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
97 100
98 } // namespace base 101 } // namespace base
99 102
100 #endif // BASE_METRICS_HISTOGRAM_FUNCTIONS_H_ 103 #endif // BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698