OLD | NEW |
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); | 128 reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); |
129 } | 129 } |
130 | 130 |
131 // Ensure calling contract is upheld, and the name does NOT vary. | 131 // Ensure calling contract is upheld, and the name does NOT vary. |
132 DCHECK(histogram_pointer->histogram_name() == constant_histogram_name); | 132 DCHECK(histogram_pointer->histogram_name() == constant_histogram_name); |
133 | 133 |
134 histogram_pointer->Add(sample); | 134 histogram_pointer->Add(sample); |
135 } while (0); | 135 } while (0); |
136 */ | 136 */ |
137 | 137 |
| 138 #define SMALL_STATIC_HISTOGRAM_POINTER_BLOCK(constant_histogram_name, \ |
| 139 histogram_add_method_invocation, \ |
| 140 histogram_factory_get_name, \ |
| 141 ...) \ |
| 142 do { \ |
| 143 static base::subtle::AtomicWord atomic_histogram_pointer = 0; \ |
| 144 base::HistogramBase* histogram_pointer( \ |
| 145 reinterpret_cast<base::HistogramBase*>( \ |
| 146 base::subtle::Acquire_Load(&atomic_histogram_pointer))); \ |
| 147 if (!histogram_pointer) { \ |
| 148 histogram_pointer = \ |
| 149 histogram_factory_get_name##AndAtomicRelease(&atomic_histogram_pointer
, \ |
| 150 __VA_ARGS__); \ |
| 151 } \ |
| 152 DCHECK_EQ(histogram_pointer->histogram_name(), \ |
| 153 std::string(constant_histogram_name)); \ |
| 154 histogram_pointer->histogram_add_method_invocation; \ |
| 155 } while (0) |
| 156 |
138 // The above pattern is repeated in several macros. The only elements that | 157 // The above pattern is repeated in several macros. The only elements that |
139 // vary are the invocation of the Add(sample) vs AddTime(sample), and the choice | 158 // vary are the invocation of the Add(sample) vs AddTime(sample), and the choice |
140 // of which FactoryGet method to use. The different FactoryGet methods have | 159 // of which FactoryGet method to use. The different FactoryGet methods have |
141 // various argument lists, so the function with its argument list is provided as | 160 // various argument lists, so the function with its argument list is provided as |
142 // a macro argument here. The name is only used in a DCHECK, to assure that | 161 // a macro argument here. The name is only used in a DCHECK, to assure that |
143 // callers don't try to vary the name of the histogram (which would tend to be | 162 // callers don't try to vary the name of the histogram (which would tend to be |
144 // ignored by the one-time initialization of the histogtram_pointer). | 163 // ignored by the one-time initialization of the histogtram_pointer). |
145 #define STATIC_HISTOGRAM_POINTER_BLOCK(constant_histogram_name, \ | 164 #define STATIC_HISTOGRAM_POINTER_BLOCK(constant_histogram_name, \ |
146 histogram_add_method_invocation, \ | 165 histogram_add_method_invocation, \ |
147 histogram_factory_get_invocation) \ | 166 histogram_factory_get_invocation) \ |
148 do { \ | 167 do { \ |
149 static base::subtle::AtomicWord atomic_histogram_pointer = 0; \ | 168 static base::subtle::AtomicWord atomic_histogram_pointer = 0; \ |
150 base::HistogramBase* histogram_pointer( \ | 169 base::HistogramBase* histogram_pointer( \ |
151 reinterpret_cast<base::HistogramBase*>( \ | 170 reinterpret_cast<base::HistogramBase*>( \ |
152 base::subtle::Acquire_Load(&atomic_histogram_pointer))); \ | 171 base::subtle::Acquire_Load(&atomic_histogram_pointer))); \ |
153 if (!histogram_pointer) { \ | 172 if (!histogram_pointer) { \ |
154 histogram_pointer = histogram_factory_get_invocation; \ | 173 histogram_pointer = histogram_factory_get_invocation; \ |
155 base::subtle::Release_Store(&atomic_histogram_pointer, \ | 174 base::subtle::NoBarrier_Store(&atomic_histogram_pointer, \ |
156 reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); \ | 175 reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); \ |
157 } \ | 176 } \ |
158 DCHECK_EQ(histogram_pointer->histogram_name(), \ | 177 DCHECK_EQ(histogram_pointer->histogram_name(), \ |
159 std::string(constant_histogram_name)); \ | 178 std::string(constant_histogram_name)); \ |
160 histogram_pointer->histogram_add_method_invocation; \ | 179 histogram_pointer->histogram_add_method_invocation; \ |
161 } while (0) | 180 } while (0) |
162 | 181 |
163 | 182 |
164 //------------------------------------------------------------------------------ | 183 //------------------------------------------------------------------------------ |
165 // Provide easy general purpose histogram in a macro, just like stats counters. | 184 // Provide easy general purpose histogram in a macro, just like stats counters. |
166 // The first four macros use 50 buckets. | 185 // The first four macros use 50 buckets. |
167 | 186 |
168 #define HISTOGRAM_TIMES(name, sample) HISTOGRAM_CUSTOM_TIMES( \ | 187 #define HISTOGRAM_TIMES(name, sample) HISTOGRAM_CUSTOM_TIMES( \ |
169 name, sample, base::TimeDelta::FromMilliseconds(1), \ | 188 name, sample, base::TimeDelta::FromMilliseconds(1), \ |
170 base::TimeDelta::FromSeconds(10), 50) | 189 base::TimeDelta::FromSeconds(10), 50) |
171 | 190 |
172 // For folks that need real specific times, use this to select a precise range | 191 // 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. | 192 // of times you want plotted, and the number of buckets you want used. |
174 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ | 193 #if 1 |
175 STATIC_HISTOGRAM_POINTER_BLOCK(name, AddTime(sample), \ | 194 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ |
| 195 STATIC_HISTOGRAM_POINTER_BLOCK(name, AddTime(sample), \ |
176 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ | 196 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ |
177 base::HistogramBase::kNoFlags)) | 197 base::HistogramBase::kNoFlags)) |
| 198 #else |
| 199 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ |
| 200 SMALL_STATIC_HISTOGRAM_POINTER_BLOCK( \ |
| 201 name, AddTime(sample), base::Histogram::FactoryTimeGet, \ |
| 202 name, min, max, bucket_count, base::HistogramBase::kNoFlags) |
| 203 #endif |
178 | 204 |
179 #define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ | 205 #define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ |
180 name, sample, 1, 1000000, 50) | 206 name, sample, 1, 1000000, 50) |
181 | 207 |
182 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ | 208 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ |
183 name, sample, 1, 100, 50) | 209 name, sample, 1, 100, 50) |
184 | 210 |
185 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ | 211 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ |
186 name, sample, 1, 10000, 50) | 212 name, sample, 1, 10000, 50) |
187 | 213 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 static HistogramBase* FactoryGet(const std::string& name, | 426 static HistogramBase* FactoryGet(const std::string& name, |
401 Sample minimum, | 427 Sample minimum, |
402 Sample maximum, | 428 Sample maximum, |
403 size_t bucket_count, | 429 size_t bucket_count, |
404 int32 flags); | 430 int32 flags); |
405 static HistogramBase* FactoryTimeGet(const std::string& name, | 431 static HistogramBase* FactoryTimeGet(const std::string& name, |
406 base::TimeDelta minimum, | 432 base::TimeDelta minimum, |
407 base::TimeDelta maximum, | 433 base::TimeDelta maximum, |
408 size_t bucket_count, | 434 size_t bucket_count, |
409 int32 flags); | 435 int32 flags); |
| 436 static HistogramBase* FactoryTimeGetAndAtomicRelease( |
| 437 base::subtle::AtomicWord* atomic_histogram_pointer, |
| 438 const std::string& name, |
| 439 base::TimeDelta minimum, |
| 440 base::TimeDelta maximum, |
| 441 size_t bucket_count, |
| 442 int32 flags); |
410 | 443 |
411 // Time call for use with DHISTOGRAM*. | 444 // Time call for use with DHISTOGRAM*. |
412 // Returns TimeTicks::Now() in debug and TimeTicks() in release build. | 445 // Returns TimeTicks::Now() in debug and TimeTicks() in release build. |
413 static TimeTicks DebugNow(); | 446 static TimeTicks DebugNow(); |
414 | 447 |
415 static void InitializeBucketRanges(Sample minimum, | 448 static void InitializeBucketRanges(Sample minimum, |
416 Sample maximum, | 449 Sample maximum, |
417 BucketRanges* ranges); | 450 BucketRanges* ranges); |
418 | 451 |
419 // This constant if for FindCorruption. Since snapshots of histograms are | 452 // This constant if for FindCorruption. Since snapshots of histograms are |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 717 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
685 static BucketRanges* CreateBucketRangesFromCustomRanges( | 718 static BucketRanges* CreateBucketRangesFromCustomRanges( |
686 const std::vector<Sample>& custom_ranges); | 719 const std::vector<Sample>& custom_ranges); |
687 | 720 |
688 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 721 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
689 }; | 722 }; |
690 | 723 |
691 } // namespace base | 724 } // namespace base |
692 | 725 |
693 #endif // BASE_METRICS_HISTOGRAM_H_ | 726 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |