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. |
11 | 11 |
12 // For Histogram(exponential histogram), LinearHistogram and CustomHistogram, | 12 // For Histogram(exponential histogram), LinearHistogram and CustomHistogram, |
13 // the minimum for a declared range is 1 (instead of 0), while the maximum is | 13 // the minimum for a declared range is 1 (instead of 0), while the maximum is |
14 // (HistogramBase::kSampleType_MAX - 1). Currently you can declare histograms | 14 // (HistogramBase::kSampleType_MAX - 1). Currently you can declare histograms |
15 // with ranges exceeding those limits (e.g. 0 as minimal or | 15 // with ranges exceeding those limits (e.g. 0 as minimal or |
16 // HistogramBase::kSampleType_MAX as maximal), but those excesses will be | 16 // HistogramBase::kSampleType_MAX as maximal), but those excesses will be |
17 // silently clamped to those limits (for backwards compatibility with existing | 17 // silently clamped to those limits (for backwards compatibility with existing |
18 // code). Best practice is to not exceed the limits. | 18 // code). Best practice is to not exceed the limits. |
19 | 19 |
| 20 // Each use of a histogram with the same name will reference the same underlying |
| 21 // data, so it is safe to record to the same histogram from multiple locations |
| 22 // in the code. It is a runtime error if all uses of the same histogram do not |
| 23 // agree exactly in type, bucket size and range. |
| 24 |
20 // For Histogram and LinearHistogram, the maximum for a declared range should | 25 // For Histogram and LinearHistogram, the maximum for a declared range should |
21 // always be larger (not equal) than minmal range. Zero and | 26 // always be larger (not equal) than minmal range. Zero and |
22 // HistogramBase::kSampleType_MAX are implicitly added as first and last ranges, | 27 // HistogramBase::kSampleType_MAX are implicitly added as first and last ranges, |
23 // so the smallest legal bucket_count is 3. However CustomHistogram can have | 28 // so the smallest legal bucket_count is 3. However CustomHistogram can have |
24 // bucket count as 2 (when you give a custom ranges vector containing only 1 | 29 // bucket count as 2 (when you give a custom ranges vector containing only 1 |
25 // range). | 30 // range). |
26 // For these 3 kinds of histograms, the max bucket count is always | 31 // For these 3 kinds of histograms, the max bucket count is always |
27 // (Histogram::kBucketCount_MAX - 1). | 32 // (Histogram::kBucketCount_MAX - 1). |
28 | 33 |
29 // The buckets layout of class Histogram is exponential. For example, buckets | 34 // The buckets layout of class Histogram is exponential. For example, buckets |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 // Most commonly this is the numeric value, but in derived classes it may | 525 // Most commonly this is the numeric value, but in derived classes it may |
521 // be a name (or string description) given to the bucket. | 526 // be a name (or string description) given to the bucket. |
522 virtual const std::string GetAsciiBucketRange(size_t it) const; | 527 virtual const std::string GetAsciiBucketRange(size_t it) const; |
523 | 528 |
524 private: | 529 private: |
525 // Allow tests to corrupt our innards for testing purposes. | 530 // Allow tests to corrupt our innards for testing purposes. |
526 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BoundsTest); | 531 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BoundsTest); |
527 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest); | 532 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest); |
528 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds); | 533 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds); |
529 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); | 534 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); |
| 535 FRIEND_TEST_ALL_PREFIXES(HistogramTest, NameMatchTest); |
530 | 536 |
531 friend class StatisticsRecorder; // To allow it to delete duplicates. | 537 friend class StatisticsRecorder; // To allow it to delete duplicates. |
532 friend class StatisticsRecorderTest; | 538 friend class StatisticsRecorderTest; |
533 | 539 |
534 // Implementation of SnapshotSamples function. | 540 // Implementation of SnapshotSamples function. |
535 scoped_ptr<SampleVector> SnapshotSampleVector() const; | 541 scoped_ptr<SampleVector> SnapshotSampleVector() const; |
536 | 542 |
537 //---------------------------------------------------------------------------- | 543 //---------------------------------------------------------------------------- |
538 // Helpers for emitting Ascii graphic. Each method appends data to output. | 544 // Helpers for emitting Ascii graphic. Each method appends data to output. |
539 | 545 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 709 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
704 static BucketRanges* CreateBucketRangesFromCustomRanges( | 710 static BucketRanges* CreateBucketRangesFromCustomRanges( |
705 const std::vector<Sample>& custom_ranges); | 711 const std::vector<Sample>& custom_ranges); |
706 | 712 |
707 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 713 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
708 }; | 714 }; |
709 | 715 |
710 } // namespace base | 716 } // namespace base |
711 | 717 |
712 #endif // BASE_METRICS_HISTOGRAM_H_ | 718 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |