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

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

Issue 2801613002: Allow UmaHistogramEnumeration to be used with enum classes. (Closed)
Patch Set: With DCHECKs 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_GE(static_cast<int64_t>(max), 0);
47 DCHECK_LE(static_cast<int64_t>(max), INT_MAX);
48 DCHECK_GE(static_cast<int64_t>(sample), 0);
49 DCHECK_LE(sample, max);
benwells 2017/04/06 07:30:01 How is this? Some questions: - do you have a bette
benwells 2017/04/06 07:40:24 A smart person here suggested this: DCHECK_EQ(max,
dcheng 2017/04/06 07:47:05 Yeah, static assert won't work here.
benwells 2017/04/06 08:16:48 OK ... yeah, subtle :) Thanks!
50 return UmaHistogramExactLinear(name, static_cast<int>(sample),
51 static_cast<int>(max));
47 } 52 }
48 53
49 // For adding boolean sample to histogram. 54 // For adding boolean sample to histogram.
50 // Sample usage: 55 // Sample usage:
51 // base::UmaHistogramBoolean("My.Boolean", true) 56 // base::UmaHistogramBoolean("My.Boolean", true)
52 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample); 57 BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
53 58
54 // For adding histogram with percent. 59 // For adding histogram with percent.
55 // Percents are integer between 1 and 100. 60 // Percents are integer between 1 and 100.
56 // Sample usage: 61 // Sample usage:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 96
92 // For recording memory related histograms. 97 // For recording memory related histograms.
93 // Used to measure common KB-granularity memory stats. Range is up to 500M. 98 // Used to measure common KB-granularity memory stats. Range is up to 500M.
94 BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample); 99 BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
95 // Used to measure common MB-granularity memory stats. Range is up to ~64G. 100 // Used to measure common MB-granularity memory stats. Range is up to ~64G.
96 BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample); 101 BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
97 102
98 } // namespace base 103 } // namespace base
99 104
100 #endif // BASE_METRICS_HISTOGRAM_FUNCTIONS_H_ 105 #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