| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 virtual BucketRanges* CreateRanges() { | 118 virtual BucketRanges* CreateRanges() { |
| 119 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 119 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
| 120 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 120 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
| 121 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. | 121 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. |
| 122 return ranges; | 122 return ranges; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Allocate the correct Histogram object off the heap (in case persistent | 125 // Allocate the correct Histogram object off the heap (in case persistent |
| 126 // memory is not available). | 126 // memory is not available). |
| 127 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { | 127 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { |
| 128 return WrapUnique(new Histogram(name_, minimum_, maximum_, ranges)); | 128 return WrapUnique( |
| 129 new Histogram(GetPermanentName(name_), minimum_, maximum_, ranges)); |
| 129 } | 130 } |
| 130 | 131 |
| 131 // Perform any required datafill on the just-created histogram. If | 132 // Perform any required datafill on the just-created histogram. If |
| 132 // overridden, be sure to call the "super" version -- this method may not | 133 // overridden, be sure to call the "super" version -- this method may not |
| 133 // always remain empty. | 134 // always remain empty. |
| 134 virtual void FillHistogram(HistogramBase* histogram) {} | 135 virtual void FillHistogram(HistogramBase* histogram) {} |
| 135 | 136 |
| 136 // These values are protected (instead of private) because they need to | 137 // These values are protected (instead of private) because they need to |
| 137 // be accessible to methods of sub-classes in order to avoid passing | 138 // be accessible to methods of sub-classes in order to avoid passing |
| 138 // unnecessary parameters everywhere. | 139 // unnecessary parameters everywhere. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 HistogramBase* Histogram::FactoryTimeGet(const char* name, | 269 HistogramBase* Histogram::FactoryTimeGet(const char* name, |
| 269 TimeDelta minimum, | 270 TimeDelta minimum, |
| 270 TimeDelta maximum, | 271 TimeDelta maximum, |
| 271 uint32_t bucket_count, | 272 uint32_t bucket_count, |
| 272 int32_t flags) { | 273 int32_t flags) { |
| 273 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, | 274 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
| 274 flags); | 275 flags); |
| 275 } | 276 } |
| 276 | 277 |
| 277 std::unique_ptr<HistogramBase> Histogram::PersistentCreate( | 278 std::unique_ptr<HistogramBase> Histogram::PersistentCreate( |
| 278 const std::string& name, | 279 const char* name, |
| 279 Sample minimum, | 280 Sample minimum, |
| 280 Sample maximum, | 281 Sample maximum, |
| 281 const BucketRanges* ranges, | 282 const BucketRanges* ranges, |
| 282 const DelayedPersistentAllocation& counts, | 283 const DelayedPersistentAllocation& counts, |
| 283 const DelayedPersistentAllocation& logged_counts, | 284 const DelayedPersistentAllocation& logged_counts, |
| 284 HistogramSamples::Metadata* meta, | 285 HistogramSamples::Metadata* meta, |
| 285 HistogramSamples::Metadata* logged_meta) { | 286 HistogramSamples::Metadata* logged_meta) { |
| 286 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts, | 287 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts, |
| 287 logged_counts, meta, logged_meta)); | 288 logged_counts, meta, logged_meta)); |
| 288 } | 289 } |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 DCHECK(bucket_ranges()->HasValidChecksum()); | 534 DCHECK(bucket_ranges()->HasValidChecksum()); |
| 534 return pickle->WriteString(histogram_name()) && | 535 return pickle->WriteString(histogram_name()) && |
| 535 pickle->WriteInt(flags()) && | 536 pickle->WriteInt(flags()) && |
| 536 pickle->WriteInt(declared_min()) && | 537 pickle->WriteInt(declared_min()) && |
| 537 pickle->WriteInt(declared_max()) && | 538 pickle->WriteInt(declared_max()) && |
| 538 pickle->WriteUInt32(bucket_count()) && | 539 pickle->WriteUInt32(bucket_count()) && |
| 539 pickle->WriteUInt32(bucket_ranges()->checksum()); | 540 pickle->WriteUInt32(bucket_ranges()->checksum()); |
| 540 } | 541 } |
| 541 | 542 |
| 542 // TODO(bcwhite): Remove minimum/maximum parameters from here and call chain. | 543 // TODO(bcwhite): Remove minimum/maximum parameters from here and call chain. |
| 543 Histogram::Histogram(const std::string& name, | 544 Histogram::Histogram(const char* name, |
| 544 Sample minimum, | 545 Sample minimum, |
| 545 Sample maximum, | 546 Sample maximum, |
| 546 const BucketRanges* ranges) | 547 const BucketRanges* ranges) |
| 547 : HistogramBase(name), bucket_ranges_(ranges) { | 548 : HistogramBase(name), bucket_ranges_(ranges) { |
| 548 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. | 549 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. |
| 549 CHECK(ranges) << name << ": " << minimum << "-" << maximum; | 550 CHECK(ranges) << name << ": " << minimum << "-" << maximum; |
| 550 unlogged_samples_.reset(new SampleVector(HashMetricName(name), ranges)); | 551 unlogged_samples_.reset(new SampleVector(HashMetricName(name), ranges)); |
| 551 logged_samples_.reset(new SampleVector(unlogged_samples_->id(), ranges)); | 552 logged_samples_.reset(new SampleVector(unlogged_samples_->id(), ranges)); |
| 552 } | 553 } |
| 553 | 554 |
| 554 Histogram::Histogram(const std::string& name, | 555 Histogram::Histogram(const char* name, |
| 555 Sample minimum, | 556 Sample minimum, |
| 556 Sample maximum, | 557 Sample maximum, |
| 557 const BucketRanges* ranges, | 558 const BucketRanges* ranges, |
| 558 const DelayedPersistentAllocation& counts, | 559 const DelayedPersistentAllocation& counts, |
| 559 const DelayedPersistentAllocation& logged_counts, | 560 const DelayedPersistentAllocation& logged_counts, |
| 560 HistogramSamples::Metadata* meta, | 561 HistogramSamples::Metadata* meta, |
| 561 HistogramSamples::Metadata* logged_meta) | 562 HistogramSamples::Metadata* logged_meta) |
| 562 : HistogramBase(name), bucket_ranges_(ranges) { | 563 : HistogramBase(name), bucket_ranges_(ranges) { |
| 563 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. | 564 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. |
| 564 CHECK(ranges) << name << ": " << minimum << "-" << maximum; | 565 CHECK(ranges) << name << ": " << minimum << "-" << maximum; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 double current_size = GetBucketSize(samples.GetCountAtIndex(i), i); | 714 double current_size = GetBucketSize(samples.GetCountAtIndex(i), i); |
| 714 if (current_size > max) | 715 if (current_size > max) |
| 715 max = current_size; | 716 max = current_size; |
| 716 } | 717 } |
| 717 return max; | 718 return max; |
| 718 } | 719 } |
| 719 | 720 |
| 720 void Histogram::WriteAsciiHeader(const SampleVectorBase& samples, | 721 void Histogram::WriteAsciiHeader(const SampleVectorBase& samples, |
| 721 Count sample_count, | 722 Count sample_count, |
| 722 std::string* output) const { | 723 std::string* output) const { |
| 723 StringAppendF(output, | 724 StringAppendF(output, "Histogram: %s recorded %d samples", histogram_name(), |
| 724 "Histogram: %s recorded %d samples", | |
| 725 histogram_name().c_str(), | |
| 726 sample_count); | 725 sample_count); |
| 727 if (sample_count == 0) { | 726 if (sample_count == 0) { |
| 728 DCHECK_EQ(samples.sum(), 0); | 727 DCHECK_EQ(samples.sum(), 0); |
| 729 } else { | 728 } else { |
| 730 double mean = static_cast<float>(samples.sum()) / sample_count; | 729 double mean = static_cast<float>(samples.sum()) / sample_count; |
| 731 StringAppendF(output, ", mean = %.1f", mean); | 730 StringAppendF(output, ", mean = %.1f", mean); |
| 732 } | 731 } |
| 733 if (flags()) | 732 if (flags()) |
| 734 StringAppendF(output, " (flags = 0x%x)", flags()); | 733 StringAppendF(output, " (flags = 0x%x)", flags()); |
| 735 } | 734 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 protected: | 795 protected: |
| 797 BucketRanges* CreateRanges() override { | 796 BucketRanges* CreateRanges() override { |
| 798 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 797 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
| 799 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 798 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
| 800 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. | 799 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. |
| 801 return ranges; | 800 return ranges; |
| 802 } | 801 } |
| 803 | 802 |
| 804 std::unique_ptr<HistogramBase> HeapAlloc( | 803 std::unique_ptr<HistogramBase> HeapAlloc( |
| 805 const BucketRanges* ranges) override { | 804 const BucketRanges* ranges) override { |
| 806 return WrapUnique(new LinearHistogram(name_, minimum_, maximum_, ranges)); | 805 return WrapUnique(new LinearHistogram(GetPermanentName(name_), minimum_, |
| 806 maximum_, ranges)); |
| 807 } | 807 } |
| 808 | 808 |
| 809 void FillHistogram(HistogramBase* base_histogram) override { | 809 void FillHistogram(HistogramBase* base_histogram) override { |
| 810 Histogram::Factory::FillHistogram(base_histogram); | 810 Histogram::Factory::FillHistogram(base_histogram); |
| 811 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); | 811 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); |
| 812 // Set range descriptions. | 812 // Set range descriptions. |
| 813 if (descriptions_) { | 813 if (descriptions_) { |
| 814 for (int i = 0; descriptions_[i].description; ++i) { | 814 for (int i = 0; descriptions_[i].description; ++i) { |
| 815 histogram->bucket_description_[descriptions_[i].sample] = | 815 histogram->bucket_description_[descriptions_[i].sample] = |
| 816 descriptions_[i].description; | 816 descriptions_[i].description; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, | 856 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, |
| 857 TimeDelta minimum, | 857 TimeDelta minimum, |
| 858 TimeDelta maximum, | 858 TimeDelta maximum, |
| 859 uint32_t bucket_count, | 859 uint32_t bucket_count, |
| 860 int32_t flags) { | 860 int32_t flags) { |
| 861 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, | 861 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
| 862 flags); | 862 flags); |
| 863 } | 863 } |
| 864 | 864 |
| 865 std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate( | 865 std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate( |
| 866 const std::string& name, | 866 const char* name, |
| 867 Sample minimum, | 867 Sample minimum, |
| 868 Sample maximum, | 868 Sample maximum, |
| 869 const BucketRanges* ranges, | 869 const BucketRanges* ranges, |
| 870 const DelayedPersistentAllocation& counts, | 870 const DelayedPersistentAllocation& counts, |
| 871 const DelayedPersistentAllocation& logged_counts, | 871 const DelayedPersistentAllocation& logged_counts, |
| 872 HistogramSamples::Metadata* meta, | 872 HistogramSamples::Metadata* meta, |
| 873 HistogramSamples::Metadata* logged_meta) { | 873 HistogramSamples::Metadata* logged_meta) { |
| 874 return WrapUnique(new LinearHistogram(name, minimum, maximum, ranges, counts, | 874 return WrapUnique(new LinearHistogram(name, minimum, maximum, ranges, counts, |
| 875 logged_counts, meta, logged_meta)); | 875 logged_counts, meta, logged_meta)); |
| 876 } | 876 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 887 DCHECK(valid_arguments); | 887 DCHECK(valid_arguments); |
| 888 | 888 |
| 889 return Factory(name, minimum, maximum, bucket_count, flags, descriptions) | 889 return Factory(name, minimum, maximum, bucket_count, flags, descriptions) |
| 890 .Build(); | 890 .Build(); |
| 891 } | 891 } |
| 892 | 892 |
| 893 HistogramType LinearHistogram::GetHistogramType() const { | 893 HistogramType LinearHistogram::GetHistogramType() const { |
| 894 return LINEAR_HISTOGRAM; | 894 return LINEAR_HISTOGRAM; |
| 895 } | 895 } |
| 896 | 896 |
| 897 LinearHistogram::LinearHistogram(const std::string& name, | 897 LinearHistogram::LinearHistogram(const char* name, |
| 898 Sample minimum, | 898 Sample minimum, |
| 899 Sample maximum, | 899 Sample maximum, |
| 900 const BucketRanges* ranges) | 900 const BucketRanges* ranges) |
| 901 : Histogram(name, minimum, maximum, ranges) { | 901 : Histogram(name, minimum, maximum, ranges) {} |
| 902 } | |
| 903 | 902 |
| 904 LinearHistogram::LinearHistogram( | 903 LinearHistogram::LinearHistogram( |
| 905 const std::string& name, | 904 const char* name, |
| 906 Sample minimum, | 905 Sample minimum, |
| 907 Sample maximum, | 906 Sample maximum, |
| 908 const BucketRanges* ranges, | 907 const BucketRanges* ranges, |
| 909 const DelayedPersistentAllocation& counts, | 908 const DelayedPersistentAllocation& counts, |
| 910 const DelayedPersistentAllocation& logged_counts, | 909 const DelayedPersistentAllocation& logged_counts, |
| 911 HistogramSamples::Metadata* meta, | 910 HistogramSamples::Metadata* meta, |
| 912 HistogramSamples::Metadata* logged_meta) | 911 HistogramSamples::Metadata* logged_meta) |
| 913 : Histogram(name, | 912 : Histogram(name, |
| 914 minimum, | 913 minimum, |
| 915 maximum, | 914 maximum, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 protected: | 991 protected: |
| 993 BucketRanges* CreateRanges() override { | 992 BucketRanges* CreateRanges() override { |
| 994 BucketRanges* ranges = new BucketRanges(3 + 1); | 993 BucketRanges* ranges = new BucketRanges(3 + 1); |
| 995 LinearHistogram::InitializeBucketRanges(1, 2, ranges); | 994 LinearHistogram::InitializeBucketRanges(1, 2, ranges); |
| 996 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. | 995 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. |
| 997 return ranges; | 996 return ranges; |
| 998 } | 997 } |
| 999 | 998 |
| 1000 std::unique_ptr<HistogramBase> HeapAlloc( | 999 std::unique_ptr<HistogramBase> HeapAlloc( |
| 1001 const BucketRanges* ranges) override { | 1000 const BucketRanges* ranges) override { |
| 1002 return WrapUnique(new BooleanHistogram(name_, ranges)); | 1001 return WrapUnique(new BooleanHistogram(GetPermanentName(name_), ranges)); |
| 1003 } | 1002 } |
| 1004 | 1003 |
| 1005 private: | 1004 private: |
| 1006 DISALLOW_COPY_AND_ASSIGN(Factory); | 1005 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 1007 }; | 1006 }; |
| 1008 | 1007 |
| 1009 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, | 1008 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, |
| 1010 int32_t flags) { | 1009 int32_t flags) { |
| 1011 return Factory(name, flags).Build(); | 1010 return Factory(name, flags).Build(); |
| 1012 } | 1011 } |
| 1013 | 1012 |
| 1014 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { | 1013 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { |
| 1015 return FactoryGet(std::string(name), flags); | 1014 return FactoryGet(std::string(name), flags); |
| 1016 } | 1015 } |
| 1017 | 1016 |
| 1018 std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate( | 1017 std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate( |
| 1019 const std::string& name, | 1018 const char* name, |
| 1020 const BucketRanges* ranges, | 1019 const BucketRanges* ranges, |
| 1021 const DelayedPersistentAllocation& counts, | 1020 const DelayedPersistentAllocation& counts, |
| 1022 const DelayedPersistentAllocation& logged_counts, | 1021 const DelayedPersistentAllocation& logged_counts, |
| 1023 HistogramSamples::Metadata* meta, | 1022 HistogramSamples::Metadata* meta, |
| 1024 HistogramSamples::Metadata* logged_meta) { | 1023 HistogramSamples::Metadata* logged_meta) { |
| 1025 return WrapUnique(new BooleanHistogram(name, ranges, counts, logged_counts, | 1024 return WrapUnique(new BooleanHistogram(name, ranges, counts, logged_counts, |
| 1026 meta, logged_meta)); | 1025 meta, logged_meta)); |
| 1027 } | 1026 } |
| 1028 | 1027 |
| 1029 HistogramType BooleanHistogram::GetHistogramType() const { | 1028 HistogramType BooleanHistogram::GetHistogramType() const { |
| 1030 return BOOLEAN_HISTOGRAM; | 1029 return BOOLEAN_HISTOGRAM; |
| 1031 } | 1030 } |
| 1032 | 1031 |
| 1033 BooleanHistogram::BooleanHistogram(const std::string& name, | 1032 BooleanHistogram::BooleanHistogram(const char* name, const BucketRanges* ranges) |
| 1034 const BucketRanges* ranges) | |
| 1035 : LinearHistogram(name, 1, 2, ranges) {} | 1033 : LinearHistogram(name, 1, 2, ranges) {} |
| 1036 | 1034 |
| 1037 BooleanHistogram::BooleanHistogram( | 1035 BooleanHistogram::BooleanHistogram( |
| 1038 const std::string& name, | 1036 const char* name, |
| 1039 const BucketRanges* ranges, | 1037 const BucketRanges* ranges, |
| 1040 const DelayedPersistentAllocation& counts, | 1038 const DelayedPersistentAllocation& counts, |
| 1041 const DelayedPersistentAllocation& logged_counts, | 1039 const DelayedPersistentAllocation& logged_counts, |
| 1042 HistogramSamples::Metadata* meta, | 1040 HistogramSamples::Metadata* meta, |
| 1043 HistogramSamples::Metadata* logged_meta) | 1041 HistogramSamples::Metadata* logged_meta) |
| 1044 : LinearHistogram(name, | 1042 : LinearHistogram(name, |
| 1045 1, | 1043 1, |
| 1046 2, | 1044 2, |
| 1047 ranges, | 1045 ranges, |
| 1048 counts, | 1046 counts, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 1095 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
| 1098 for (uint32_t i = 0; i < ranges.size(); i++) { | 1096 for (uint32_t i = 0; i < ranges.size(); i++) { |
| 1099 bucket_ranges->set_range(i, ranges[i]); | 1097 bucket_ranges->set_range(i, ranges[i]); |
| 1100 } | 1098 } |
| 1101 bucket_ranges->ResetChecksum(); | 1099 bucket_ranges->ResetChecksum(); |
| 1102 return bucket_ranges; | 1100 return bucket_ranges; |
| 1103 } | 1101 } |
| 1104 | 1102 |
| 1105 std::unique_ptr<HistogramBase> HeapAlloc( | 1103 std::unique_ptr<HistogramBase> HeapAlloc( |
| 1106 const BucketRanges* ranges) override { | 1104 const BucketRanges* ranges) override { |
| 1107 return WrapUnique(new CustomHistogram(name_, ranges)); | 1105 return WrapUnique(new CustomHistogram(GetPermanentName(name_), ranges)); |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 private: | 1108 private: |
| 1111 const std::vector<Sample>* custom_ranges_; | 1109 const std::vector<Sample>* custom_ranges_; |
| 1112 | 1110 |
| 1113 DISALLOW_COPY_AND_ASSIGN(Factory); | 1111 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 1114 }; | 1112 }; |
| 1115 | 1113 |
| 1116 HistogramBase* CustomHistogram::FactoryGet( | 1114 HistogramBase* CustomHistogram::FactoryGet( |
| 1117 const std::string& name, | 1115 const std::string& name, |
| 1118 const std::vector<Sample>& custom_ranges, | 1116 const std::vector<Sample>& custom_ranges, |
| 1119 int32_t flags) { | 1117 int32_t flags) { |
| 1120 CHECK(ValidateCustomRanges(custom_ranges)); | 1118 CHECK(ValidateCustomRanges(custom_ranges)); |
| 1121 | 1119 |
| 1122 return Factory(name, &custom_ranges, flags).Build(); | 1120 return Factory(name, &custom_ranges, flags).Build(); |
| 1123 } | 1121 } |
| 1124 | 1122 |
| 1125 HistogramBase* CustomHistogram::FactoryGet( | 1123 HistogramBase* CustomHistogram::FactoryGet( |
| 1126 const char* name, | 1124 const char* name, |
| 1127 const std::vector<Sample>& custom_ranges, | 1125 const std::vector<Sample>& custom_ranges, |
| 1128 int32_t flags) { | 1126 int32_t flags) { |
| 1129 return FactoryGet(std::string(name), custom_ranges, flags); | 1127 return FactoryGet(std::string(name), custom_ranges, flags); |
| 1130 } | 1128 } |
| 1131 | 1129 |
| 1132 std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate( | 1130 std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate( |
| 1133 const std::string& name, | 1131 const char* name, |
| 1134 const BucketRanges* ranges, | 1132 const BucketRanges* ranges, |
| 1135 const DelayedPersistentAllocation& counts, | 1133 const DelayedPersistentAllocation& counts, |
| 1136 const DelayedPersistentAllocation& logged_counts, | 1134 const DelayedPersistentAllocation& logged_counts, |
| 1137 HistogramSamples::Metadata* meta, | 1135 HistogramSamples::Metadata* meta, |
| 1138 HistogramSamples::Metadata* logged_meta) { | 1136 HistogramSamples::Metadata* logged_meta) { |
| 1139 return WrapUnique(new CustomHistogram(name, ranges, counts, logged_counts, | 1137 return WrapUnique(new CustomHistogram(name, ranges, counts, logged_counts, |
| 1140 meta, logged_meta)); | 1138 meta, logged_meta)); |
| 1141 } | 1139 } |
| 1142 | 1140 |
| 1143 HistogramType CustomHistogram::GetHistogramType() const { | 1141 HistogramType CustomHistogram::GetHistogramType() const { |
| 1144 return CUSTOM_HISTOGRAM; | 1142 return CUSTOM_HISTOGRAM; |
| 1145 } | 1143 } |
| 1146 | 1144 |
| 1147 // static | 1145 // static |
| 1148 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( | 1146 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( |
| 1149 const Sample* values, uint32_t num_values) { | 1147 const Sample* values, uint32_t num_values) { |
| 1150 std::vector<Sample> all_values; | 1148 std::vector<Sample> all_values; |
| 1151 for (uint32_t i = 0; i < num_values; ++i) { | 1149 for (uint32_t i = 0; i < num_values; ++i) { |
| 1152 Sample value = values[i]; | 1150 Sample value = values[i]; |
| 1153 all_values.push_back(value); | 1151 all_values.push_back(value); |
| 1154 | 1152 |
| 1155 // Ensure that a guard bucket is added. If we end up with duplicate | 1153 // Ensure that a guard bucket is added. If we end up with duplicate |
| 1156 // values, FactoryGet will take care of removing them. | 1154 // values, FactoryGet will take care of removing them. |
| 1157 all_values.push_back(value + 1); | 1155 all_values.push_back(value + 1); |
| 1158 } | 1156 } |
| 1159 return all_values; | 1157 return all_values; |
| 1160 } | 1158 } |
| 1161 | 1159 |
| 1162 CustomHistogram::CustomHistogram(const std::string& name, | 1160 CustomHistogram::CustomHistogram(const char* name, const BucketRanges* ranges) |
| 1163 const BucketRanges* ranges) | |
| 1164 : Histogram(name, | 1161 : Histogram(name, |
| 1165 ranges->range(1), | 1162 ranges->range(1), |
| 1166 ranges->range(ranges->bucket_count() - 1), | 1163 ranges->range(ranges->bucket_count() - 1), |
| 1167 ranges) {} | 1164 ranges) {} |
| 1168 | 1165 |
| 1169 CustomHistogram::CustomHistogram( | 1166 CustomHistogram::CustomHistogram( |
| 1170 const std::string& name, | 1167 const char* name, |
| 1171 const BucketRanges* ranges, | 1168 const BucketRanges* ranges, |
| 1172 const DelayedPersistentAllocation& counts, | 1169 const DelayedPersistentAllocation& counts, |
| 1173 const DelayedPersistentAllocation& logged_counts, | 1170 const DelayedPersistentAllocation& logged_counts, |
| 1174 HistogramSamples::Metadata* meta, | 1171 HistogramSamples::Metadata* meta, |
| 1175 HistogramSamples::Metadata* logged_meta) | 1172 HistogramSamples::Metadata* logged_meta) |
| 1176 : Histogram(name, | 1173 : Histogram(name, |
| 1177 ranges->range(1), | 1174 ranges->range(1), |
| 1178 ranges->range(ranges->bucket_count() - 1), | 1175 ranges->range(ranges->bucket_count() - 1), |
| 1179 ranges, | 1176 ranges, |
| 1180 counts, | 1177 counts, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 Sample sample = custom_ranges[i]; | 1237 Sample sample = custom_ranges[i]; |
| 1241 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1238 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
| 1242 return false; | 1239 return false; |
| 1243 if (sample != 0) | 1240 if (sample != 0) |
| 1244 has_valid_range = true; | 1241 has_valid_range = true; |
| 1245 } | 1242 } |
| 1246 return has_valid_range; | 1243 return has_valid_range; |
| 1247 } | 1244 } |
| 1248 | 1245 |
| 1249 } // namespace base | 1246 } // namespace base |
| OLD | NEW |