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

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

Issue 484603006: Add LOCAL_ prefix to non-UMA histogram macros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 6 years, 3 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/field_trial.h ('k') | base/metrics/histogram.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 8
9 // It supports calls to accumulate either time intervals (which are processed 9 // It supports calls to accumulate either time intervals (which are processed
10 // as integral number of milliseconds), or arbitrary integral units. 10 // as integral number of milliseconds), or arbitrary integral units.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // recurring cost of executing (adding additional samples). Toward that end, 91 // recurring cost of executing (adding additional samples). Toward that end,
92 // the macros declare a static pointer to the histogram in question, and only 92 // the macros declare a static pointer to the histogram in question, and only
93 // take a "slow path" to construct (or find) the histogram on the first run 93 // take a "slow path" to construct (or find) the histogram on the first run
94 // through the macro. We leak the histograms at shutdown time so that we don't 94 // through the macro. We leak the histograms at shutdown time so that we don't
95 // have to validate using the pointers at any time during the running of the 95 // have to validate using the pointers at any time during the running of the
96 // process. 96 // process.
97 97
98 // The following code is generally what a thread-safe static pointer 98 // The following code is generally what a thread-safe static pointer
99 // initialization looks like for a histogram (after a macro is expanded). This 99 // initialization looks like for a histogram (after a macro is expanded). This
100 // sample is an expansion (with comments) of the code for 100 // sample is an expansion (with comments) of the code for
101 // HISTOGRAM_CUSTOM_COUNTS(). 101 // LOCAL_HISTOGRAM_CUSTOM_COUNTS().
102 102
103 /* 103 /*
104 do { 104 do {
105 // The pointer's presence indicates the initialization is complete. 105 // The pointer's presence indicates the initialization is complete.
106 // Initialization is idempotent, so it can safely be atomically repeated. 106 // Initialization is idempotent, so it can safely be atomically repeated.
107 static base::subtle::AtomicWord atomic_histogram_pointer = 0; 107 static base::subtle::AtomicWord atomic_histogram_pointer = 0;
108 108
109 // Acquire_Load() ensures that we acquire visibility to the pointed-to data 109 // Acquire_Load() ensures that we acquire visibility to the pointed-to data
110 // in the histogram. 110 // in the histogram.
111 base::Histogram* histogram_pointer(reinterpret_cast<base::Histogram*>( 111 base::Histogram* histogram_pointer(reinterpret_cast<base::Histogram*>(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (DCHECK_IS_ON) \ 158 if (DCHECK_IS_ON) \
159 histogram_pointer->CheckName(constant_histogram_name); \ 159 histogram_pointer->CheckName(constant_histogram_name); \
160 histogram_pointer->histogram_add_method_invocation; \ 160 histogram_pointer->histogram_add_method_invocation; \
161 } while (0) 161 } while (0)
162 162
163 163
164 //------------------------------------------------------------------------------ 164 //------------------------------------------------------------------------------
165 // Provide easy general purpose histogram in a macro, just like stats counters. 165 // Provide easy general purpose histogram in a macro, just like stats counters.
166 // The first four macros use 50 buckets. 166 // The first four macros use 50 buckets.
167 167
168 #define HISTOGRAM_TIMES(name, sample) HISTOGRAM_CUSTOM_TIMES( \ 168 #define LOCAL_HISTOGRAM_TIMES(name, sample) LOCAL_HISTOGRAM_CUSTOM_TIMES( \
169 name, sample, base::TimeDelta::FromMilliseconds(1), \ 169 name, sample, base::TimeDelta::FromMilliseconds(1), \
170 base::TimeDelta::FromSeconds(10), 50) 170 base::TimeDelta::FromSeconds(10), 50)
171 171
172 // For folks that need real specific times, use this to select a precise range 172 // For folks that need real specific times, use this to select a precise range
173 // of times you want plotted, and the number of buckets you want used. 173 // of times you want plotted, and the number of buckets you want used.
174 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ 174 #define LOCAL_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
175 STATIC_HISTOGRAM_POINTER_BLOCK(name, AddTime(sample), \ 175 STATIC_HISTOGRAM_POINTER_BLOCK(name, AddTime(sample), \
176 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ 176 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \
177 base::HistogramBase::kNoFlags)) 177 base::HistogramBase::kNoFlags))
178 178
179 #define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ 179 #define LOCAL_HISTOGRAM_COUNTS(name, sample) LOCAL_HISTOGRAM_CUSTOM_COUNTS( \
180 name, sample, 1, 1000000, 50) 180 name, sample, 1, 1000000, 50)
181 181
182 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ 182 #define LOCAL_HISTOGRAM_COUNTS_100(name, sample) \
183 name, sample, 1, 100, 50) 183 LOCAL_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 100, 50)
184 184
185 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ 185 #define LOCAL_HISTOGRAM_COUNTS_10000(name, sample) \
186 name, sample, 1, 10000, 50) 186 LOCAL_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50)
187 187
188 #define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ 188 #define LOCAL_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
189 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ 189 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
190 base::Histogram::FactoryGet(name, min, max, bucket_count, \ 190 base::Histogram::FactoryGet(name, min, max, bucket_count, \
191 base::HistogramBase::kNoFlags)) 191 base::HistogramBase::kNoFlags))
192 192
193 // This is a helper macro used by other macros and shouldn't be used directly. 193 // This is a helper macro used by other macros and shouldn't be used directly.
194 #define HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary, flag) \ 194 #define HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary, flag) \
195 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ 195 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
196 base::LinearHistogram::FactoryGet(name, 1, boundary, boundary + 1, \ 196 base::LinearHistogram::FactoryGet(name, 1, boundary, boundary + 1, \
197 flag)) 197 flag))
198 198
199 #define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ 199 #define LOCAL_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
200 HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) 200 LOCAL_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
201 201
202 #define HISTOGRAM_BOOLEAN(name, sample) \ 202 #define LOCAL_HISTOGRAM_BOOLEAN(name, sample) \
203 STATIC_HISTOGRAM_POINTER_BLOCK(name, AddBoolean(sample), \ 203 STATIC_HISTOGRAM_POINTER_BLOCK(name, AddBoolean(sample), \
204 base::BooleanHistogram::FactoryGet(name, base::Histogram::kNoFlags)) 204 base::BooleanHistogram::FactoryGet(name, base::Histogram::kNoFlags))
205 205
206 // Support histograming of an enumerated value. The samples should always be 206 // Support histograming of an enumerated value. The samples should always be
207 // strictly less than |boundary_value| -- this prevents you from running into 207 // strictly less than |boundary_value| -- this prevents you from running into
208 // problems down the line if you add additional buckets to the histogram. Note 208 // problems down the line if you add additional buckets to the histogram. Note
209 // also that, despite explicitly setting the minimum bucket value to |1| below, 209 // also that, despite explicitly setting the minimum bucket value to |1| below,
210 // it is fine for enumerated histograms to be 0-indexed -- this is because 210 // it is fine for enumerated histograms to be 0-indexed -- this is because
211 // enumerated histograms should never have underflow. 211 // enumerated histograms should never have underflow.
212 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) \ 212 #define LOCAL_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \
213 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ 213 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
214 base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ 214 base::LinearHistogram::FactoryGet(name, 1, boundary_value, \
215 boundary_value + 1, base::HistogramBase::kNoFlags)) 215 boundary_value + 1, base::HistogramBase::kNoFlags))
216 216
217 // Support histograming of an enumerated value. Samples should be one of the 217 // Support histograming of an enumerated value. Samples should be one of the
218 // std::vector<int> list provided via |custom_ranges|. See comments above 218 // std::vector<int> list provided via |custom_ranges|. See comments above
219 // CustomRanges::FactoryGet about the requirement of |custom_ranges|. 219 // CustomRanges::FactoryGet about the requirement of |custom_ranges|.
220 // You can use the helper function CustomHistogram::ArrayToCustomRanges to 220 // You can use the helper function CustomHistogram::ArrayToCustomRanges to
221 // transform a C-style array of valid sample values to a std::vector<int>. 221 // transform a C-style array of valid sample values to a std::vector<int>.
222 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ 222 #define LOCAL_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
223 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ 223 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
224 base::CustomHistogram::FactoryGet(name, custom_ranges, \ 224 base::CustomHistogram::FactoryGet(name, custom_ranges, \
225 base::HistogramBase::kNoFlags)) 225 base::HistogramBase::kNoFlags))
226 226
227 #define HISTOGRAM_MEMORY_KB(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ 227 #define LOCAL_HISTOGRAM_MEMORY_KB(name, sample) LOCAL_HISTOGRAM_CUSTOM_COUNTS( \
228 name, sample, 1000, 500000, 50) 228 name, sample, 1000, 500000, 50)
229 229
230 //------------------------------------------------------------------------------ 230 //------------------------------------------------------------------------------
231 // Define Debug vs non-debug flavors of macros.
232 #ifndef NDEBUG
233
234 #define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample)
235 #define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample)
236 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\
237 name, under_one_hundred)
238 #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
239 HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count)
240 #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \
241 HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count)
242 #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
243 HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count)
244 #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \
245 HISTOGRAM_ENUMERATION(name, sample, boundary_value)
246 #define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
247 HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges)
248
249 #else // NDEBUG
250 // Keep a mention of passed variables to avoid unused variable warnings in
251 // release build if these variables are only used in macros.
252 #define DISCARD_2_ARGUMENTS(a, b) \
253 while (0) { \
254 static_cast<void>(a); \
255 static_cast<void>(b); \
256 }
257 #define DISCARD_3_ARGUMENTS(a, b, c) \
258 while (0) { \
259 static_cast<void>(a); \
260 static_cast<void>(b); \
261 static_cast<void>(c); \
262 }
263 #define DISCARD_5_ARGUMENTS(a, b, c, d ,e) \
264 while (0) { \
265 static_cast<void>(a); \
266 static_cast<void>(b); \
267 static_cast<void>(c); \
268 static_cast<void>(d); \
269 static_cast<void>(e); \
270 }
271 #define DHISTOGRAM_TIMES(name, sample) \
272 DISCARD_2_ARGUMENTS(name, sample)
273
274 #define DHISTOGRAM_COUNTS(name, sample) \
275 DISCARD_2_ARGUMENTS(name, sample)
276
277 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) \
278 DISCARD_2_ARGUMENTS(name, under_one_hundred)
279
280 #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
281 DISCARD_5_ARGUMENTS(name, sample, min, max, bucket_count)
282
283 #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \
284 DISCARD_5_ARGUMENTS(name, sample, min, max, bucket_count)
285
286 #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
287 DISCARD_5_ARGUMENTS(name, sample, min, max, bucket_count)
288
289 #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \
290 DISCARD_3_ARGUMENTS(name, sample, boundary_value)
291
292 #define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
293 DISCARD_3_ARGUMENTS(name, sample, custom_ranges)
294
295 #endif // NDEBUG
296
297 //------------------------------------------------------------------------------
298 // The following macros provide typical usage scenarios for callers that wish 231 // The following macros provide typical usage scenarios for callers that wish
299 // to record histogram data, and have the data submitted/uploaded via UMA. 232 // to record histogram data, and have the data submitted/uploaded via UMA.
300 // Not all systems support such UMA, but if they do, the following macros 233 // Not all systems support such UMA, but if they do, the following macros
301 // should work with the service. 234 // should work with the service.
302 235
303 #define UMA_HISTOGRAM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ 236 #define UMA_HISTOGRAM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
304 name, sample, base::TimeDelta::FromMilliseconds(1), \ 237 name, sample, base::TimeDelta::FromMilliseconds(1), \
305 base::TimeDelta::FromSeconds(10), 50) 238 base::TimeDelta::FromSeconds(10), 50)
306 239
307 #define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ 240 #define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 Sample minimum, 334 Sample minimum,
402 Sample maximum, 335 Sample maximum,
403 size_t bucket_count, 336 size_t bucket_count,
404 int32 flags); 337 int32 flags);
405 static HistogramBase* FactoryTimeGet(const std::string& name, 338 static HistogramBase* FactoryTimeGet(const std::string& name,
406 base::TimeDelta minimum, 339 base::TimeDelta minimum,
407 base::TimeDelta maximum, 340 base::TimeDelta maximum,
408 size_t bucket_count, 341 size_t bucket_count,
409 int32 flags); 342 int32 flags);
410 343
411 // Time call for use with DHISTOGRAM*.
412 // Returns TimeTicks::Now() in debug and TimeTicks() in release build.
413 static TimeTicks DebugNow();
414
415 static void InitializeBucketRanges(Sample minimum, 344 static void InitializeBucketRanges(Sample minimum,
416 Sample maximum, 345 Sample maximum,
417 BucketRanges* ranges); 346 BucketRanges* ranges);
418 347
419 // This constant if for FindCorruption. Since snapshots of histograms are 348 // This constant if for FindCorruption. Since snapshots of histograms are
420 // taken asynchronously relative to sampling, and our counting code currently 349 // taken asynchronously relative to sampling, and our counting code currently
421 // does not prevent race conditions, it is pretty likely that we'll catch a 350 // does not prevent race conditions, it is pretty likely that we'll catch a
422 // redundant count that doesn't match the sample count. We allow for a 351 // redundant count that doesn't match the sample count. We allow for a
423 // certain amount of slop before flagging this as an inconsistency. Even with 352 // certain amount of slop before flagging this as an inconsistency. Even with
424 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), 353 // an inconsistency, we'll snapshot it again (for UMA in about a half hour),
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // compatibility). The limits can be unordered or contain duplication, but 582 // compatibility). The limits can be unordered or contain duplication, but
654 // client should not depend on this. 583 // client should not depend on this.
655 static HistogramBase* FactoryGet(const std::string& name, 584 static HistogramBase* FactoryGet(const std::string& name,
656 const std::vector<Sample>& custom_ranges, 585 const std::vector<Sample>& custom_ranges,
657 int32 flags); 586 int32 flags);
658 587
659 // Overridden from Histogram: 588 // Overridden from Histogram:
660 virtual HistogramType GetHistogramType() const OVERRIDE; 589 virtual HistogramType GetHistogramType() const OVERRIDE;
661 590
662 // Helper method for transforming an array of valid enumeration values 591 // Helper method for transforming an array of valid enumeration values
663 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. 592 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION.
664 // This function ensures that a guard bucket exists right after any 593 // This function ensures that a guard bucket exists right after any
665 // valid sample value (unless the next higher sample is also a valid value), 594 // valid sample value (unless the next higher sample is also a valid value),
666 // so that invalid samples never fall into the same bucket as valid samples. 595 // so that invalid samples never fall into the same bucket as valid samples.
667 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 596 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
668 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 597 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
669 size_t num_values); 598 size_t num_values);
670 protected: 599 protected:
671 CustomHistogram(const std::string& name, 600 CustomHistogram(const std::string& name,
672 const BucketRanges* ranges); 601 const BucketRanges* ranges);
673 602
(...skipping 10 matching lines...) Expand all
684 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 613 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
685 static BucketRanges* CreateBucketRangesFromCustomRanges( 614 static BucketRanges* CreateBucketRangesFromCustomRanges(
686 const std::vector<Sample>& custom_ranges); 615 const std::vector<Sample>& custom_ranges);
687 616
688 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 617 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
689 }; 618 };
690 619
691 } // namespace base 620 } // namespace base
692 621
693 #endif // BASE_METRICS_HISTOGRAM_H_ 622 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698