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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 class PickleIterator; | 97 class PickleIterator; |
98 class SampleVector; | 98 class SampleVector; |
99 | 99 |
100 class BASE_EXPORT Histogram : public HistogramBase { | 100 class BASE_EXPORT Histogram : public HistogramBase { |
101 public: | 101 public: |
102 // Initialize maximum number of buckets in histograms as 16,384. | 102 // Initialize maximum number of buckets in histograms as 16,384. |
103 static const uint32_t kBucketCount_MAX; | 103 static const uint32_t kBucketCount_MAX; |
104 | 104 |
105 typedef std::vector<Count> Counts; | 105 typedef std::vector<Count> Counts; |
106 | 106 |
| 107 ~Histogram() override; |
| 108 |
107 //---------------------------------------------------------------------------- | 109 //---------------------------------------------------------------------------- |
108 // For a valid histogram, input should follow these restrictions: | 110 // For a valid histogram, input should follow these restrictions: |
109 // minimum > 0 (if a minimum below 1 is specified, it will implicitly be | 111 // minimum > 0 (if a minimum below 1 is specified, it will implicitly be |
110 // normalized up to 1) | 112 // normalized up to 1) |
111 // maximum > minimum | 113 // maximum > minimum |
112 // buckets > 2 [minimum buckets needed: underflow, overflow and the range] | 114 // buckets > 2 [minimum buckets needed: underflow, overflow and the range] |
113 // Additionally, | 115 // Additionally, |
114 // buckets <= (maximum - minimum + 2) - this is to ensure that we don't have | 116 // buckets <= (maximum - minimum + 2) - this is to ensure that we don't have |
115 // more buckets than the range of numbers; having more buckets than 1 per | 117 // more buckets than the range of numbers; having more buckets than 1 per |
116 // value in the range would be nonsensical. | 118 // value in the range would be nonsensical. |
(...skipping 15 matching lines...) Expand all Loading... |
132 Sample minimum, | 134 Sample minimum, |
133 Sample maximum, | 135 Sample maximum, |
134 uint32_t bucket_count, | 136 uint32_t bucket_count, |
135 int32_t flags); | 137 int32_t flags); |
136 static HistogramBase* FactoryTimeGet(const char* name, | 138 static HistogramBase* FactoryTimeGet(const char* name, |
137 base::TimeDelta minimum, | 139 base::TimeDelta minimum, |
138 base::TimeDelta maximum, | 140 base::TimeDelta maximum, |
139 uint32_t bucket_count, | 141 uint32_t bucket_count, |
140 int32_t flags); | 142 int32_t flags); |
141 | 143 |
142 // Get a histogram using data in persistent storage. | 144 // Create a histogram using data in persistent storage. |
143 static HistogramBase* PersistentGet(const std::string& name, | 145 static scoped_ptr<HistogramBase> PersistentCreate( |
144 Sample minimum, | 146 const std::string& name, |
145 Sample maximum, | 147 Sample minimum, |
146 const BucketRanges* ranges, | 148 Sample maximum, |
147 HistogramBase::AtomicCount* counts, | 149 const BucketRanges* ranges, |
148 HistogramBase::AtomicCount* logged_counts, | 150 HistogramBase::AtomicCount* counts, |
149 uint32_t counts_size, | 151 HistogramBase::AtomicCount* logged_counts, |
150 HistogramSamples::Metadata* meta, | 152 uint32_t counts_size, |
151 HistogramSamples::Metadata* logged_meta); | 153 HistogramSamples::Metadata* meta, |
| 154 HistogramSamples::Metadata* logged_meta); |
152 | 155 |
153 static void InitializeBucketRanges(Sample minimum, | 156 static void InitializeBucketRanges(Sample minimum, |
154 Sample maximum, | 157 Sample maximum, |
155 BucketRanges* ranges); | 158 BucketRanges* ranges); |
156 | 159 |
157 // This constant if for FindCorruption. Since snapshots of histograms are | 160 // This constant if for FindCorruption. Since snapshots of histograms are |
158 // taken asynchronously relative to sampling, and our counting code currently | 161 // taken asynchronously relative to sampling, and our counting code currently |
159 // does not prevent race conditions, it is pretty likely that we'll catch a | 162 // does not prevent race conditions, it is pretty likely that we'll catch a |
160 // redundant count that doesn't match the sample count. We allow for a | 163 // redundant count that doesn't match the sample count. We allow for a |
161 // certain amount of slop before flagging this as an inconsistency. Even with | 164 // certain amount of slop before flagging this as an inconsistency. Even with |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 Histogram(const std::string& name, | 233 Histogram(const std::string& name, |
231 Sample minimum, | 234 Sample minimum, |
232 Sample maximum, | 235 Sample maximum, |
233 const BucketRanges* ranges, | 236 const BucketRanges* ranges, |
234 HistogramBase::AtomicCount* counts, | 237 HistogramBase::AtomicCount* counts, |
235 HistogramBase::AtomicCount* logged_counts, | 238 HistogramBase::AtomicCount* logged_counts, |
236 uint32_t counts_size, | 239 uint32_t counts_size, |
237 HistogramSamples::Metadata* meta, | 240 HistogramSamples::Metadata* meta, |
238 HistogramSamples::Metadata* logged_meta); | 241 HistogramSamples::Metadata* logged_meta); |
239 | 242 |
240 ~Histogram() override; | |
241 | |
242 // HistogramBase implementation: | 243 // HistogramBase implementation: |
243 bool SerializeInfoImpl(base::Pickle* pickle) const override; | 244 bool SerializeInfoImpl(base::Pickle* pickle) const override; |
244 | 245 |
245 // Method to override to skip the display of the i'th bucket if it's empty. | 246 // Method to override to skip the display of the i'th bucket if it's empty. |
246 virtual bool PrintEmptyBucket(uint32_t index) const; | 247 virtual bool PrintEmptyBucket(uint32_t index) const; |
247 | 248 |
248 // Get normalized size, relative to the ranges(i). | 249 // Get normalized size, relative to the ranges(i). |
249 virtual double GetBucketSize(Count current, uint32_t i) const; | 250 virtual double GetBucketSize(Count current, uint32_t i) const; |
250 | 251 |
251 // Return a string description of what goes in a given bucket. | 252 // Return a string description of what goes in a given bucket. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 Sample minimum, | 344 Sample minimum, |
344 Sample maximum, | 345 Sample maximum, |
345 uint32_t bucket_count, | 346 uint32_t bucket_count, |
346 int32_t flags); | 347 int32_t flags); |
347 static HistogramBase* FactoryTimeGet(const char* name, | 348 static HistogramBase* FactoryTimeGet(const char* name, |
348 TimeDelta minimum, | 349 TimeDelta minimum, |
349 TimeDelta maximum, | 350 TimeDelta maximum, |
350 uint32_t bucket_count, | 351 uint32_t bucket_count, |
351 int32_t flags); | 352 int32_t flags); |
352 | 353 |
353 // Get a histogram using data in persistent storage. | 354 // Create a histogram using data in persistent storage. |
354 static HistogramBase* PersistentGet(const std::string& name, | 355 static scoped_ptr<HistogramBase> PersistentCreate( |
355 Sample minimum, | 356 const std::string& name, |
356 Sample maximum, | 357 Sample minimum, |
357 const BucketRanges* ranges, | 358 Sample maximum, |
358 HistogramBase::AtomicCount* counts, | 359 const BucketRanges* ranges, |
359 HistogramBase::AtomicCount* logged_counts, | 360 HistogramBase::AtomicCount* counts, |
360 uint32_t counts_size, | 361 HistogramBase::AtomicCount* logged_counts, |
361 HistogramSamples::Metadata* meta, | 362 uint32_t counts_size, |
362 HistogramSamples::Metadata* logged_meta); | 363 HistogramSamples::Metadata* meta, |
| 364 HistogramSamples::Metadata* logged_meta); |
363 | 365 |
364 struct DescriptionPair { | 366 struct DescriptionPair { |
365 Sample sample; | 367 Sample sample; |
366 const char* description; // Null means end of a list of pairs. | 368 const char* description; // Null means end of a list of pairs. |
367 }; | 369 }; |
368 | 370 |
369 // Create a LinearHistogram and store a list of number/text values for use in | 371 // Create a LinearHistogram and store a list of number/text values for use in |
370 // writing the histogram graph. | 372 // writing the histogram graph. |
371 // |descriptions| can be NULL, which means no special descriptions to set. If | 373 // |descriptions| can be NULL, which means no special descriptions to set. If |
372 // it's not NULL, the last element in the array must has a NULL in its | 374 // it's not NULL, the last element in the array must has a NULL in its |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 // BooleanHistogram is a histogram for booleans. | 435 // BooleanHistogram is a histogram for booleans. |
434 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 436 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
435 public: | 437 public: |
436 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); | 438 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); |
437 | 439 |
438 // Overload of the above function that takes a const char* |name| param, | 440 // Overload of the above function that takes a const char* |name| param, |
439 // to avoid code bloat from the std::string constructor being inlined into | 441 // to avoid code bloat from the std::string constructor being inlined into |
440 // call sites. | 442 // call sites. |
441 static HistogramBase* FactoryGet(const char* name, int32_t flags); | 443 static HistogramBase* FactoryGet(const char* name, int32_t flags); |
442 | 444 |
443 // Get a histogram using data in persistent storage. | 445 // Create a histogram using data in persistent storage. |
444 static HistogramBase* PersistentGet(const std::string& name, | 446 static scoped_ptr<HistogramBase> PersistentCreate( |
445 const BucketRanges* ranges, | 447 const std::string& name, |
446 HistogramBase::AtomicCount* counts, | 448 const BucketRanges* ranges, |
447 HistogramBase::AtomicCount* logged_counts, | 449 HistogramBase::AtomicCount* counts, |
448 HistogramSamples::Metadata* meta, | 450 HistogramBase::AtomicCount* logged_counts, |
449 HistogramSamples::Metadata* logged_meta); | 451 HistogramSamples::Metadata* meta, |
| 452 HistogramSamples::Metadata* logged_meta); |
450 | 453 |
451 HistogramType GetHistogramType() const override; | 454 HistogramType GetHistogramType() const override; |
452 | 455 |
453 protected: | 456 protected: |
454 class Factory; | 457 class Factory; |
455 | 458 |
456 private: | 459 private: |
457 BooleanHistogram(const std::string& name, const BucketRanges* ranges); | 460 BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
458 BooleanHistogram(const std::string& name, | 461 BooleanHistogram(const std::string& name, |
459 const BucketRanges* ranges, | 462 const BucketRanges* ranges, |
(...skipping 22 matching lines...) Expand all Loading... |
482 const std::vector<Sample>& custom_ranges, | 485 const std::vector<Sample>& custom_ranges, |
483 int32_t flags); | 486 int32_t flags); |
484 | 487 |
485 // Overload of the above function that takes a const char* |name| param, | 488 // Overload of the above function that takes a const char* |name| param, |
486 // to avoid code bloat from the std::string constructor being inlined into | 489 // to avoid code bloat from the std::string constructor being inlined into |
487 // call sites. | 490 // call sites. |
488 static HistogramBase* FactoryGet(const char* name, | 491 static HistogramBase* FactoryGet(const char* name, |
489 const std::vector<Sample>& custom_ranges, | 492 const std::vector<Sample>& custom_ranges, |
490 int32_t flags); | 493 int32_t flags); |
491 | 494 |
492 // Get a histogram using data in persistent storage. | 495 // Create a histogram using data in persistent storage. |
493 static HistogramBase* PersistentGet(const std::string& name, | 496 static scoped_ptr<HistogramBase> PersistentCreate( |
494 const BucketRanges* ranges, | 497 const std::string& name, |
495 HistogramBase::AtomicCount* counts, | 498 const BucketRanges* ranges, |
496 HistogramBase::AtomicCount* logged_counts, | 499 HistogramBase::AtomicCount* counts, |
497 uint32_t counts_size, | 500 HistogramBase::AtomicCount* logged_counts, |
498 HistogramSamples::Metadata* meta, | 501 uint32_t counts_size, |
499 HistogramSamples::Metadata* logged_meta); | 502 HistogramSamples::Metadata* meta, |
| 503 HistogramSamples::Metadata* logged_meta); |
500 | 504 |
501 // Overridden from Histogram: | 505 // Overridden from Histogram: |
502 HistogramType GetHistogramType() const override; | 506 HistogramType GetHistogramType() const override; |
503 | 507 |
504 // Helper method for transforming an array of valid enumeration values | 508 // Helper method for transforming an array of valid enumeration values |
505 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. | 509 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. |
506 // This function ensures that a guard bucket exists right after any | 510 // This function ensures that a guard bucket exists right after any |
507 // valid sample value (unless the next higher sample is also a valid value), | 511 // valid sample value (unless the next higher sample is also a valid value), |
508 // so that invalid samples never fall into the same bucket as valid samples. | 512 // so that invalid samples never fall into the same bucket as valid samples. |
509 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. | 513 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. |
(...skipping 24 matching lines...) Expand all Loading... |
534 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 538 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
535 | 539 |
536 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 540 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
537 | 541 |
538 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 542 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
539 }; | 543 }; |
540 | 544 |
541 } // namespace base | 545 } // namespace base |
542 | 546 |
543 #endif // BASE_METRICS_HISTOGRAM_H_ | 547 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |