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

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

Issue 2886933003: Use stricter type checking in UMA_HISTOGRAM_ENUMERATION (Closed)
Patch Set: simplify type checking Created 3 years, 5 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 | « base/metrics/histogram_functions_unittest.cc ('k') | base/metrics/histogram_unittest.nc » ('j') | 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_MACROS_INTERNAL_H_ 5 #ifndef BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_
6 #define BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_ 6 #define BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // 133 //
134 // Note the range checks verify two separate issues: 134 // Note the range checks verify two separate issues:
135 // - that the declared enum max isn't out of range of HistogramBase::Sample 135 // - that the declared enum max isn't out of range of HistogramBase::Sample
136 // - that the declared enum max is > 0 136 // - that the declared enum max is > 0
137 // 137 //
138 // TODO(dcheng): This should assert that the passed in types are actually enum 138 // TODO(dcheng): This should assert that the passed in types are actually enum
139 // types. 139 // types.
140 #define INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary, flag) \ 140 #define INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary, flag) \
141 do { \ 141 do { \
142 static_assert( \ 142 static_assert( \
143 !std::is_enum<decltype(sample)>::value || \ 143 !std::is_enum<std::decay<decltype(boundary)>::type>::value || \
144 !std::is_enum<decltype(boundary)>::value || \ 144 std::is_enum<std::decay<decltype(sample)>::type>::value, \
145 std::is_same<std::remove_const<decltype(sample)>::type, \ 145 "Unexpected: |boundary| is enum, but |sample| is not."); \
146 std::remove_const<decltype(boundary)>::type>::value, \ 146 static_assert( \
147 !std::is_enum<std::decay<decltype(sample)>::type>::value || \
148 !std::is_enum<std::decay<decltype(boundary)>::type>::value || \
149 std::is_same<std::decay<decltype(sample)>::type, \
150 std::decay<decltype(boundary)>::type>::value, \
147 "|sample| and |boundary| shouldn't be of different enums"); \ 151 "|sample| and |boundary| shouldn't be of different enums"); \
148 static_assert( \ 152 static_assert( \
149 static_cast<uintmax_t>(boundary) < \ 153 static_cast<uintmax_t>(boundary) < \
150 static_cast<uintmax_t>( \ 154 static_cast<uintmax_t>( \
151 std::numeric_limits<base::HistogramBase::Sample>::max()), \ 155 std::numeric_limits<base::HistogramBase::Sample>::max()), \
152 "|boundary| is out of range of HistogramBase::Sample"); \ 156 "|boundary| is out of range of HistogramBase::Sample"); \
153 INTERNAL_HISTOGRAM_EXACT_LINEAR_WITH_FLAG( \ 157 INTERNAL_HISTOGRAM_EXACT_LINEAR_WITH_FLAG( \
154 name, static_cast<base::HistogramBase::Sample>(sample), \ 158 name, static_cast<base::HistogramBase::Sample>(sample), \
155 static_cast<base::HistogramBase::Sample>(boundary), flag); \ 159 static_cast<base::HistogramBase::Sample>(boundary), flag); \
156 } while (0) 160 } while (0)
(...skipping 26 matching lines...) Expand all
183 // may be more efficient in memory if the total number of sample values is small 187 // may be more efficient in memory if the total number of sample values is small
184 // compared to the range of their values. 188 // compared to the range of their values.
185 #define INTERNAL_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ 189 #define INTERNAL_HISTOGRAM_SPARSE_SLOWLY(name, sample) \
186 do { \ 190 do { \
187 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \ 191 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \
188 name, base::HistogramBase::kUmaTargetedHistogramFlag); \ 192 name, base::HistogramBase::kUmaTargetedHistogramFlag); \
189 histogram->Add(sample); \ 193 histogram->Add(sample); \
190 } while (0) 194 } while (0)
191 195
192 #endif // BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_ 196 #endif // BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram_functions_unittest.cc ('k') | base/metrics/histogram_unittest.nc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698