Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 const uint32_t Histogram::kBucketCount_MAX = 16384u; | 88 const uint32_t Histogram::kBucketCount_MAX = 16384u; |
| 89 | 89 |
| 90 class Histogram::Factory { | 90 class Histogram::Factory { |
| 91 public: | 91 public: |
| 92 Factory(const std::string& name, | 92 Factory(const std::string& name, |
| 93 HistogramBase::Sample minimum, | 93 HistogramBase::Sample minimum, |
| 94 HistogramBase::Sample maximum, | 94 HistogramBase::Sample maximum, |
| 95 uint32_t bucket_count, | 95 uint32_t bucket_count, |
| 96 int32_t flags) | 96 int32_t flags) |
| 97 : Factory(name, HISTOGRAM, minimum, maximum, bucket_count, flags) {} | 97 : Factory(name, HISTOGRAM, minimum, maximum, bucket_count, flags) {} |
| 98 virtual ~Factory() = default; | |
| 98 | 99 |
| 99 // Create histogram based on construction parameters. Caller takes | 100 // Create histogram based on construction parameters. Caller takes |
| 100 // ownership of the returned object. | 101 // ownership of the returned object. |
| 101 HistogramBase* Build(); | 102 HistogramBase* Build(); |
| 102 | 103 |
| 103 protected: | 104 protected: |
| 104 Factory(const std::string& name, | 105 Factory(const std::string& name, |
| 105 HistogramType histogram_type, | 106 HistogramType histogram_type, |
| 106 HistogramBase::Sample minimum, | 107 HistogramBase::Sample minimum, |
| 107 HistogramBase::Sample maximum, | 108 HistogramBase::Sample maximum, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 123 | 124 |
| 124 // Allocate the correct Histogram object off the heap (in case persistent | 125 // Allocate the correct Histogram object off the heap (in case persistent |
| 125 // memory is not available). | 126 // memory is not available). |
| 126 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { | 127 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { |
| 127 return WrapUnique(new Histogram(name_, minimum_, maximum_, ranges)); | 128 return WrapUnique(new Histogram(name_, minimum_, maximum_, ranges)); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Perform any required datafill on the just-created histogram. If | 131 // Perform any required datafill on the just-created histogram. If |
| 131 // overridden, be sure to call the "super" version -- this method may not | 132 // overridden, be sure to call the "super" version -- this method may not |
| 132 // always remain empty. | 133 // always remain empty. |
| 133 virtual void FillHistogram(HistogramBase* histogram) {} | 134 virtual void FillHistogram(HistogramBase* /*histogram*/) {} |
| 134 | 135 |
| 135 // These values are protected (instead of private) because they need to | 136 // These values are protected (instead of private) because they need to |
| 136 // be accessible to methods of sub-classes in order to avoid passing | 137 // be accessible to methods of sub-classes in order to avoid passing |
| 137 // unnecessary parameters everywhere. | 138 // unnecessary parameters everywhere. |
| 138 const std::string& name_; | 139 const std::string& name_; |
| 139 const HistogramType histogram_type_; | 140 const HistogramType histogram_type_; |
| 140 HistogramBase::Sample minimum_; | 141 HistogramBase::Sample minimum_; |
| 141 HistogramBase::Sample maximum_; | 142 HistogramBase::Sample maximum_; |
| 142 uint32_t bucket_count_; | 143 uint32_t bucket_count_; |
| 143 int32_t flags_; | 144 int32_t flags_; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 samples_.reset(new SampleVector(HashMetricName(name), | 527 samples_.reset(new SampleVector(HashMetricName(name), |
| 527 counts, counts_size, meta, ranges)); | 528 counts, counts_size, meta, ranges)); |
| 528 logged_samples_.reset(new SampleVector(samples_->id(), logged_counts, | 529 logged_samples_.reset(new SampleVector(samples_->id(), logged_counts, |
| 529 counts_size, logged_meta, ranges)); | 530 counts_size, logged_meta, ranges)); |
| 530 } | 531 } |
| 531 } | 532 } |
| 532 | 533 |
| 533 Histogram::~Histogram() { | 534 Histogram::~Histogram() { |
| 534 } | 535 } |
| 535 | 536 |
| 536 bool Histogram::PrintEmptyBucket(uint32_t index) const { | 537 bool Histogram::PrintEmptyBucket(uint32_t /*index*/) const { |
| 537 return true; | 538 return true; |
| 538 } | 539 } |
| 539 | 540 |
| 540 // Use the actual bucket widths (like a linear histogram) until the widths get | 541 // Use the actual bucket widths (like a linear histogram) until the widths get |
| 541 // over some transition value, and then use that transition width. Exponentials | 542 // over some transition value, and then use that transition width. Exponentials |
| 542 // get so big so fast (and we don't expect to see a lot of entries in the large | 543 // get so big so fast (and we don't expect to see a lot of entries in the large |
| 543 // buckets), so we need this to make it possible to see what is going on and | 544 // buckets), so we need this to make it possible to see what is going on and |
| 544 // not have 0-graphical-height buckets. | 545 // not have 0-graphical-height buckets. |
| 545 double Histogram::GetBucketSize(Count current, uint32_t i) const { | 546 double Histogram::GetBucketSize(Count current, uint32_t i) const { |
| 546 DCHECK_GT(ranges(i + 1), ranges(i)); | 547 DCHECK_GT(ranges(i + 1), ranges(i)); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 Factory(const std::string& name, | 737 Factory(const std::string& name, |
| 737 HistogramBase::Sample minimum, | 738 HistogramBase::Sample minimum, |
| 738 HistogramBase::Sample maximum, | 739 HistogramBase::Sample maximum, |
| 739 uint32_t bucket_count, | 740 uint32_t bucket_count, |
| 740 int32_t flags, | 741 int32_t flags, |
| 741 const DescriptionPair* descriptions) | 742 const DescriptionPair* descriptions) |
| 742 : Histogram::Factory(name, LINEAR_HISTOGRAM, minimum, maximum, | 743 : Histogram::Factory(name, LINEAR_HISTOGRAM, minimum, maximum, |
| 743 bucket_count, flags) { | 744 bucket_count, flags) { |
| 744 descriptions_ = descriptions; | 745 descriptions_ = descriptions; |
| 745 } | 746 } |
| 747 ~Factory() override = default; | |
| 746 | 748 |
| 747 protected: | 749 protected: |
| 748 BucketRanges* CreateRanges() override { | 750 BucketRanges* CreateRanges() override { |
| 749 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 751 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
| 750 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 752 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
| 751 return ranges; | 753 return ranges; |
| 752 } | 754 } |
| 753 | 755 |
| 754 std::unique_ptr<HistogramBase> HeapAlloc( | 756 std::unique_ptr<HistogramBase> HeapAlloc( |
| 755 const BucketRanges* ranges) override { | 757 const BucketRanges* ranges) override { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 } | 930 } |
| 929 | 931 |
| 930 //------------------------------------------------------------------------------ | 932 //------------------------------------------------------------------------------ |
| 931 // This section provides implementation for BooleanHistogram. | 933 // This section provides implementation for BooleanHistogram. |
| 932 //------------------------------------------------------------------------------ | 934 //------------------------------------------------------------------------------ |
| 933 | 935 |
| 934 class BooleanHistogram::Factory : public Histogram::Factory { | 936 class BooleanHistogram::Factory : public Histogram::Factory { |
| 935 public: | 937 public: |
| 936 Factory(const std::string& name, int32_t flags) | 938 Factory(const std::string& name, int32_t flags) |
| 937 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {} | 939 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {} |
| 940 ~Factory() override = default; | |
| 938 | 941 |
| 939 protected: | 942 protected: |
| 940 BucketRanges* CreateRanges() override { | 943 BucketRanges* CreateRanges() override { |
| 941 BucketRanges* ranges = new BucketRanges(3 + 1); | 944 BucketRanges* ranges = new BucketRanges(3 + 1); |
| 942 LinearHistogram::InitializeBucketRanges(1, 2, ranges); | 945 LinearHistogram::InitializeBucketRanges(1, 2, ranges); |
| 943 return ranges; | 946 return ranges; |
| 944 } | 947 } |
| 945 | 948 |
| 946 std::unique_ptr<HistogramBase> HeapAlloc( | 949 std::unique_ptr<HistogramBase> HeapAlloc( |
| 947 const BucketRanges* ranges) override { | 950 const BucketRanges* ranges) override { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 //------------------------------------------------------------------------------ | 1019 //------------------------------------------------------------------------------ |
| 1017 | 1020 |
| 1018 class CustomHistogram::Factory : public Histogram::Factory { | 1021 class CustomHistogram::Factory : public Histogram::Factory { |
| 1019 public: | 1022 public: |
| 1020 Factory(const std::string& name, | 1023 Factory(const std::string& name, |
| 1021 const std::vector<Sample>* custom_ranges, | 1024 const std::vector<Sample>* custom_ranges, |
| 1022 int32_t flags) | 1025 int32_t flags) |
| 1023 : Histogram::Factory(name, CUSTOM_HISTOGRAM, 0, 0, 0, flags) { | 1026 : Histogram::Factory(name, CUSTOM_HISTOGRAM, 0, 0, 0, flags) { |
| 1024 custom_ranges_ = custom_ranges; | 1027 custom_ranges_ = custom_ranges; |
| 1025 } | 1028 } |
| 1029 ~Factory() override = default; | |
| 1026 | 1030 |
| 1027 protected: | 1031 protected: |
| 1028 BucketRanges* CreateRanges() override { | 1032 BucketRanges* CreateRanges() override { |
| 1029 // Remove the duplicates in the custom ranges array. | 1033 // Remove the duplicates in the custom ranges array. |
| 1030 std::vector<int> ranges = *custom_ranges_; | 1034 std::vector<int> ranges = *custom_ranges_; |
| 1031 ranges.push_back(0); // Ensure we have a zero value. | 1035 ranges.push_back(0); // Ensure we have a zero value. |
| 1032 ranges.push_back(HistogramBase::kSampleType_MAX); | 1036 ranges.push_back(HistogramBase::kSampleType_MAX); |
| 1033 std::sort(ranges.begin(), ranges.end()); | 1037 std::sort(ranges.begin(), ranges.end()); |
| 1034 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); | 1038 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); |
| 1035 | 1039 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 | 1133 |
| 1130 // Serialize ranges. First and last ranges are alwasy 0 and INT_MAX, so don't | 1134 // Serialize ranges. First and last ranges are alwasy 0 and INT_MAX, so don't |
| 1131 // write them. | 1135 // write them. |
| 1132 for (uint32_t i = 1; i < bucket_ranges()->bucket_count(); ++i) { | 1136 for (uint32_t i = 1; i < bucket_ranges()->bucket_count(); ++i) { |
| 1133 if (!pickle->WriteInt(bucket_ranges()->range(i))) | 1137 if (!pickle->WriteInt(bucket_ranges()->range(i))) |
| 1134 return false; | 1138 return false; |
| 1135 } | 1139 } |
| 1136 return true; | 1140 return true; |
| 1137 } | 1141 } |
| 1138 | 1142 |
| 1139 double CustomHistogram::GetBucketSize(Count current, uint32_t i) const { | 1143 double CustomHistogram::GetBucketSize(Count /*current*/, uint32_t /*i*/) const { |
|
Alexei Svitkine (slow)
2016/05/24 17:39:12
I don't think either commenting out the param or o
Luis Héctor Chávez
2016/05/24 17:45:07
Chromium follows the Google style, which does allo
Alexei Svitkine (slow)
2016/05/24 17:48:54
Sure, but Chromium also chooses certain patterns f
danakj
2016/05/24 18:39:52
Omitting is not the same as commenting out, and le
| |
| 1140 return 1; | 1144 return 1; |
| 1141 } | 1145 } |
| 1142 | 1146 |
| 1143 // static | 1147 // static |
| 1144 HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { | 1148 HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { |
| 1145 std::string histogram_name; | 1149 std::string histogram_name; |
| 1146 int flags; | 1150 int flags; |
| 1147 int declared_min; | 1151 int declared_min; |
| 1148 int declared_max; | 1152 int declared_max; |
| 1149 uint32_t bucket_count; | 1153 uint32_t bucket_count; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1179 Sample sample = custom_ranges[i]; | 1183 Sample sample = custom_ranges[i]; |
| 1180 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1184 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
| 1181 return false; | 1185 return false; |
| 1182 if (sample != 0) | 1186 if (sample != 0) |
| 1183 has_valid_range = true; | 1187 has_valid_range = true; |
| 1184 } | 1188 } |
| 1185 return has_valid_range; | 1189 return has_valid_range; |
| 1186 } | 1190 } |
| 1187 | 1191 |
| 1188 } // namespace base | 1192 } // namespace base |
| OLD | NEW |