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 // See header file for details and examples. | 8 // See header file for details and examples. |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 HistogramBase* Histogram::FactoryTimeGet(const std::string& name, | 124 HistogramBase* Histogram::FactoryTimeGet(const std::string& name, |
125 TimeDelta minimum, | 125 TimeDelta minimum, |
126 TimeDelta maximum, | 126 TimeDelta maximum, |
127 size_t bucket_count, | 127 size_t bucket_count, |
128 int32 flags) { | 128 int32 flags) { |
129 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()), | 129 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()), |
130 static_cast<Sample>(maximum.InMilliseconds()), bucket_count, | 130 static_cast<Sample>(maximum.InMilliseconds()), bucket_count, |
131 flags); | 131 flags); |
132 } | 132 } |
133 | 133 |
| 134 HistogramBase* Histogram::FactoryGet(const char* name, |
| 135 Sample minimum, |
| 136 Sample maximum, |
| 137 size_t bucket_count, |
| 138 int32 flags) { |
| 139 return FactoryGet(std::string(name), minimum, maximum, bucket_count, flags); |
| 140 } |
| 141 |
| 142 HistogramBase* Histogram::FactoryTimeGet(const char* name, |
| 143 TimeDelta minimum, |
| 144 TimeDelta maximum, |
| 145 size_t bucket_count, |
| 146 int32 flags) { |
| 147 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
| 148 flags); |
| 149 } |
| 150 |
134 // Calculate what range of values are held in each bucket. | 151 // Calculate what range of values are held in each bucket. |
135 // We have to be careful that we don't pick a ratio between starting points in | 152 // We have to be careful that we don't pick a ratio between starting points in |
136 // consecutive buckets that is sooo small, that the integer bounds are the same | 153 // consecutive buckets that is sooo small, that the integer bounds are the same |
137 // (effectively making one bucket get no values). We need to avoid: | 154 // (effectively making one bucket get no values). We need to avoid: |
138 // ranges(i) == ranges(i + 1) | 155 // ranges(i) == ranges(i + 1) |
139 // To avoid that, we just do a fine-grained bucket width as far as we need to | 156 // To avoid that, we just do a fine-grained bucket width as far as we need to |
140 // until we get a ratio that moves us along at least 2 units at a time. From | 157 // until we get a ratio that moves us along at least 2 units at a time. From |
141 // that bucket onward we do use the exponential growth of buckets. | 158 // that bucket onward we do use the exponential growth of buckets. |
142 // | 159 // |
143 // static | 160 // static |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name, | 542 HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name, |
526 TimeDelta minimum, | 543 TimeDelta minimum, |
527 TimeDelta maximum, | 544 TimeDelta maximum, |
528 size_t bucket_count, | 545 size_t bucket_count, |
529 int32 flags) { | 546 int32 flags) { |
530 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()), | 547 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()), |
531 static_cast<Sample>(maximum.InMilliseconds()), bucket_count, | 548 static_cast<Sample>(maximum.InMilliseconds()), bucket_count, |
532 flags); | 549 flags); |
533 } | 550 } |
534 | 551 |
| 552 HistogramBase* LinearHistogram::FactoryGet(const char* name, |
| 553 Sample minimum, |
| 554 Sample maximum, |
| 555 size_t bucket_count, |
| 556 int32 flags) { |
| 557 return FactoryGet(std::string(name), minimum, maximum, bucket_count, flags); |
| 558 } |
| 559 |
| 560 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, |
| 561 TimeDelta minimum, |
| 562 TimeDelta maximum, |
| 563 size_t bucket_count, |
| 564 int32 flags) { |
| 565 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
| 566 flags); |
| 567 } |
| 568 |
535 HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( | 569 HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( |
536 const std::string& name, | 570 const std::string& name, |
537 Sample minimum, | 571 Sample minimum, |
538 Sample maximum, | 572 Sample maximum, |
539 size_t bucket_count, | 573 size_t bucket_count, |
540 int32 flags, | 574 int32 flags, |
541 const DescriptionPair descriptions[]) { | 575 const DescriptionPair descriptions[]) { |
542 bool valid_arguments = Histogram::InspectConstructionArguments( | 576 bool valid_arguments = Histogram::InspectConstructionArguments( |
543 name, &minimum, &maximum, &bucket_count); | 577 name, &minimum, &maximum, &bucket_count); |
544 DCHECK(valid_arguments); | 578 DCHECK(valid_arguments); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 | 704 |
671 tentative_histogram->SetFlags(flags); | 705 tentative_histogram->SetFlags(flags); |
672 histogram = | 706 histogram = |
673 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 707 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
674 } | 708 } |
675 | 709 |
676 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->GetHistogramType()); | 710 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->GetHistogramType()); |
677 return histogram; | 711 return histogram; |
678 } | 712 } |
679 | 713 |
| 714 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32 flags) { |
| 715 return FactoryGet(std::string(name), flags); |
| 716 } |
| 717 |
680 HistogramType BooleanHistogram::GetHistogramType() const { | 718 HistogramType BooleanHistogram::GetHistogramType() const { |
681 return BOOLEAN_HISTOGRAM; | 719 return BOOLEAN_HISTOGRAM; |
682 } | 720 } |
683 | 721 |
684 BooleanHistogram::BooleanHistogram(const std::string& name, | 722 BooleanHistogram::BooleanHistogram(const std::string& name, |
685 const BucketRanges* ranges) | 723 const BucketRanges* ranges) |
686 : LinearHistogram(name, 1, 2, ranges) {} | 724 : LinearHistogram(name, 1, 2, ranges) {} |
687 | 725 |
688 HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { | 726 HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { |
689 std::string histogram_name; | 727 std::string histogram_name; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 tentative_histogram->SetFlags(flags); | 768 tentative_histogram->SetFlags(flags); |
731 | 769 |
732 histogram = | 770 histogram = |
733 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 771 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
734 } | 772 } |
735 | 773 |
736 DCHECK_EQ(histogram->GetHistogramType(), CUSTOM_HISTOGRAM); | 774 DCHECK_EQ(histogram->GetHistogramType(), CUSTOM_HISTOGRAM); |
737 return histogram; | 775 return histogram; |
738 } | 776 } |
739 | 777 |
| 778 HistogramBase* CustomHistogram::FactoryGet( |
| 779 const char* name, |
| 780 const std::vector<Sample>& custom_ranges, |
| 781 int32 flags) { |
| 782 return FactoryGet(std::string(name), custom_ranges, flags); |
| 783 } |
| 784 |
740 HistogramType CustomHistogram::GetHistogramType() const { | 785 HistogramType CustomHistogram::GetHistogramType() const { |
741 return CUSTOM_HISTOGRAM; | 786 return CUSTOM_HISTOGRAM; |
742 } | 787 } |
743 | 788 |
744 // static | 789 // static |
745 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( | 790 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( |
746 const Sample* values, size_t num_values) { | 791 const Sample* values, size_t num_values) { |
747 std::vector<Sample> all_values; | 792 std::vector<Sample> all_values; |
748 for (size_t i = 0; i < num_values; ++i) { | 793 for (size_t i = 0; i < num_values; ++i) { |
749 Sample value = values[i]; | 794 Sample value = values[i]; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 882 |
838 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 883 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
839 for (size_t i = 0; i < ranges.size(); i++) { | 884 for (size_t i = 0; i < ranges.size(); i++) { |
840 bucket_ranges->set_range(i, ranges[i]); | 885 bucket_ranges->set_range(i, ranges[i]); |
841 } | 886 } |
842 bucket_ranges->ResetChecksum(); | 887 bucket_ranges->ResetChecksum(); |
843 return bucket_ranges; | 888 return bucket_ranges; |
844 } | 889 } |
845 | 890 |
846 } // namespace base | 891 } // namespace base |
OLD | NEW |