Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: base/metrics/histogram.cc

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/histogram_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 virtual BucketRanges* CreateRanges() { 130 virtual BucketRanges* CreateRanges() {
131 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); 131 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1);
132 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); 132 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges);
133 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. 133 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622.
134 return ranges; 134 return ranges;
135 } 135 }
136 136
137 // Allocate the correct Histogram object off the heap (in case persistent 137 // Allocate the correct Histogram object off the heap (in case persistent
138 // memory is not available). 138 // memory is not available).
139 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { 139 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) {
140 return WrapUnique(new Histogram(name_, minimum_, maximum_, ranges)); 140 return WrapUnique(
141 new Histogram(GetPermanentName(name_), minimum_, maximum_, ranges));
141 } 142 }
142 143
143 // Perform any required datafill on the just-created histogram. If 144 // Perform any required datafill on the just-created histogram. If
144 // overridden, be sure to call the "super" version -- this method may not 145 // overridden, be sure to call the "super" version -- this method may not
145 // always remain empty. 146 // always remain empty.
146 virtual void FillHistogram(HistogramBase* histogram) {} 147 virtual void FillHistogram(HistogramBase* histogram) {}
147 148
148 // These values are protected (instead of private) because they need to 149 // These values are protected (instead of private) because they need to
149 // be accessible to methods of sub-classes in order to avoid passing 150 // be accessible to methods of sub-classes in order to avoid passing
150 // unnecessary parameters everywhere. 151 // unnecessary parameters everywhere.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 HistogramBase* Histogram::FactoryTimeGet(const char* name, 281 HistogramBase* Histogram::FactoryTimeGet(const char* name,
281 TimeDelta minimum, 282 TimeDelta minimum,
282 TimeDelta maximum, 283 TimeDelta maximum,
283 uint32_t bucket_count, 284 uint32_t bucket_count,
284 int32_t flags) { 285 int32_t flags) {
285 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, 286 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count,
286 flags); 287 flags);
287 } 288 }
288 289
289 std::unique_ptr<HistogramBase> Histogram::PersistentCreate( 290 std::unique_ptr<HistogramBase> Histogram::PersistentCreate(
290 const std::string& name, 291 const char* name,
291 Sample minimum, 292 Sample minimum,
292 Sample maximum, 293 Sample maximum,
293 const BucketRanges* ranges, 294 const BucketRanges* ranges,
294 const DelayedPersistentAllocation& counts, 295 const DelayedPersistentAllocation& counts,
295 const DelayedPersistentAllocation& logged_counts, 296 const DelayedPersistentAllocation& logged_counts,
296 HistogramSamples::Metadata* meta, 297 HistogramSamples::Metadata* meta,
297 HistogramSamples::Metadata* logged_meta) { 298 HistogramSamples::Metadata* logged_meta) {
298 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts, 299 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts,
299 logged_counts, meta, logged_meta)); 300 logged_counts, meta, logged_meta));
300 } 301 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 392
392 Sample Histogram::ranges(uint32_t i) const { 393 Sample Histogram::ranges(uint32_t i) const {
393 return bucket_ranges()->range(i); 394 return bucket_ranges()->range(i);
394 } 395 }
395 396
396 uint32_t Histogram::bucket_count() const { 397 uint32_t Histogram::bucket_count() const {
397 return static_cast<uint32_t>(bucket_ranges()->bucket_count()); 398 return static_cast<uint32_t>(bucket_ranges()->bucket_count());
398 } 399 }
399 400
400 // static 401 // static
401 bool Histogram::InspectConstructionArguments(const std::string& name, 402 bool Histogram::InspectConstructionArguments(StringPiece name,
402 Sample* minimum, 403 Sample* minimum,
403 Sample* maximum, 404 Sample* maximum,
404 uint32_t* bucket_count) { 405 uint32_t* bucket_count) {
405 // Defensive code for backward compatibility. 406 // Defensive code for backward compatibility.
406 if (*minimum < 1) { 407 if (*minimum < 1) {
407 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum; 408 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum;
408 *minimum = 1; 409 *minimum = 1;
409 } 410 }
410 if (*maximum >= kSampleType_MAX) { 411 if (*maximum >= kSampleType_MAX) {
411 DVLOG(1) << "Histogram: " << name << " has bad maximum: " << *maximum; 412 DVLOG(1) << "Histogram: " << name << " has bad maximum: " << *maximum;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 bad_fields |= 1 << kFlagsField; 578 bad_fields |= 1 << kFlagsField;
578 if (dummy_ != kDummyValue) 579 if (dummy_ != kDummyValue)
579 bad_fields |= 1 << kDummyField; 580 bad_fields |= 1 << kDummyField;
580 581
581 const bool is_valid = (bad_fields & ~(1 << kFlagsField)) == 0; 582 const bool is_valid = (bad_fields & ~(1 << kFlagsField)) == 0;
582 if (is_valid || !crash_if_invalid) 583 if (is_valid || !crash_if_invalid)
583 return is_valid; 584 return is_valid;
584 585
585 // Abort if a problem is found (except "flags", which could legally be zero). 586 // Abort if a problem is found (except "flags", which could legally be zero).
586 const std::string debug_string = base::StringPrintf( 587 const std::string debug_string = base::StringPrintf(
587 "%s/%" PRIu32 "#%d", histogram_name().c_str(), bad_fields, identifier); 588 "%s/%" PRIu32 "#%d", histogram_name(), bad_fields, identifier);
588 #if !defined(OS_NACL) 589 #if !defined(OS_NACL)
589 // Temporary for https://crbug.com/736675. 590 // Temporary for https://crbug.com/736675.
590 base::debug::ScopedCrashKey crash_key("bad_histogram", debug_string); 591 base::debug::ScopedCrashKey crash_key("bad_histogram", debug_string);
591 #endif 592 #endif
592 // CHECK(false) << debug_string; 593 // CHECK(false) << debug_string;
593 debug::Alias(&bad_fields); 594 debug::Alias(&bad_fields);
594 return false; 595 return false;
595 } 596 }
596 597
597 bool Histogram::SerializeInfoImpl(Pickle* pickle) const { 598 bool Histogram::SerializeInfoImpl(Pickle* pickle) const {
598 DCHECK(bucket_ranges()->HasValidChecksum()); 599 DCHECK(bucket_ranges()->HasValidChecksum());
599 return pickle->WriteString(histogram_name()) && 600 return pickle->WriteString(histogram_name()) &&
600 pickle->WriteInt(flags()) && 601 pickle->WriteInt(flags()) &&
601 pickle->WriteInt(declared_min()) && 602 pickle->WriteInt(declared_min()) &&
602 pickle->WriteInt(declared_max()) && 603 pickle->WriteInt(declared_max()) &&
603 pickle->WriteUInt32(bucket_count()) && 604 pickle->WriteUInt32(bucket_count()) &&
604 pickle->WriteUInt32(bucket_ranges()->checksum()); 605 pickle->WriteUInt32(bucket_ranges()->checksum());
605 } 606 }
606 607
607 // TODO(bcwhite): Remove minimum/maximum parameters from here and call chain. 608 // TODO(bcwhite): Remove minimum/maximum parameters from here and call chain.
608 Histogram::Histogram(const std::string& name, 609 Histogram::Histogram(const char* name,
609 Sample minimum, 610 Sample minimum,
610 Sample maximum, 611 Sample maximum,
611 const BucketRanges* ranges) 612 const BucketRanges* ranges)
612 : HistogramBase(name), dummy_(kDummyValue) { 613 : HistogramBase(name), dummy_(kDummyValue) {
613 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. 614 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved.
614 CHECK(ranges) << name << ": " << minimum << "-" << maximum; 615 CHECK(ranges) << name << ": " << minimum << "-" << maximum;
615 unlogged_samples_.reset(new SampleVector(HashMetricName(name), ranges)); 616 unlogged_samples_.reset(new SampleVector(HashMetricName(name), ranges));
616 logged_samples_.reset(new SampleVector(unlogged_samples_->id(), ranges)); 617 logged_samples_.reset(new SampleVector(unlogged_samples_->id(), ranges));
617 } 618 }
618 619
619 Histogram::Histogram(const std::string& name, 620 Histogram::Histogram(const char* name,
620 Sample minimum, 621 Sample minimum,
621 Sample maximum, 622 Sample maximum,
622 const BucketRanges* ranges, 623 const BucketRanges* ranges,
623 const DelayedPersistentAllocation& counts, 624 const DelayedPersistentAllocation& counts,
624 const DelayedPersistentAllocation& logged_counts, 625 const DelayedPersistentAllocation& logged_counts,
625 HistogramSamples::Metadata* meta, 626 HistogramSamples::Metadata* meta,
626 HistogramSamples::Metadata* logged_meta) 627 HistogramSamples::Metadata* logged_meta)
627 : HistogramBase(name), dummy_(kDummyValue) { 628 : HistogramBase(name), dummy_(kDummyValue) {
628 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved. 629 // TODO(bcwhite): Make this a DCHECK once crbug/734049 is resolved.
629 CHECK(ranges) << name << ": " << minimum << "-" << maximum; 630 CHECK(ranges) << name << ": " << minimum << "-" << maximum;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 double current_size = GetBucketSize(samples.GetCountAtIndex(i), i); 781 double current_size = GetBucketSize(samples.GetCountAtIndex(i), i);
781 if (current_size > max) 782 if (current_size > max)
782 max = current_size; 783 max = current_size;
783 } 784 }
784 return max; 785 return max;
785 } 786 }
786 787
787 void Histogram::WriteAsciiHeader(const SampleVectorBase& samples, 788 void Histogram::WriteAsciiHeader(const SampleVectorBase& samples,
788 Count sample_count, 789 Count sample_count,
789 std::string* output) const { 790 std::string* output) const {
790 StringAppendF(output, 791 StringAppendF(output, "Histogram: %s recorded %d samples", histogram_name(),
791 "Histogram: %s recorded %d samples",
792 histogram_name().c_str(),
793 sample_count); 792 sample_count);
794 if (sample_count == 0) { 793 if (sample_count == 0) {
795 DCHECK_EQ(samples.sum(), 0); 794 DCHECK_EQ(samples.sum(), 0);
796 } else { 795 } else {
797 double mean = static_cast<float>(samples.sum()) / sample_count; 796 double mean = static_cast<float>(samples.sum()) / sample_count;
798 StringAppendF(output, ", mean = %.1f", mean); 797 StringAppendF(output, ", mean = %.1f", mean);
799 } 798 }
800 if (flags()) 799 if (flags())
801 StringAppendF(output, " (flags = 0x%x)", flags()); 800 StringAppendF(output, " (flags = 0x%x)", flags());
802 } 801 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 protected: 862 protected:
864 BucketRanges* CreateRanges() override { 863 BucketRanges* CreateRanges() override {
865 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); 864 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1);
866 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); 865 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges);
867 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. 866 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622.
868 return ranges; 867 return ranges;
869 } 868 }
870 869
871 std::unique_ptr<HistogramBase> HeapAlloc( 870 std::unique_ptr<HistogramBase> HeapAlloc(
872 const BucketRanges* ranges) override { 871 const BucketRanges* ranges) override {
873 return WrapUnique(new LinearHistogram(name_, minimum_, maximum_, ranges)); 872 return WrapUnique(new LinearHistogram(GetPermanentName(name_), minimum_,
873 maximum_, ranges));
874 } 874 }
875 875
876 void FillHistogram(HistogramBase* base_histogram) override { 876 void FillHistogram(HistogramBase* base_histogram) override {
877 Histogram::Factory::FillHistogram(base_histogram); 877 Histogram::Factory::FillHistogram(base_histogram);
878 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); 878 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram);
879 // Set range descriptions. 879 // Set range descriptions.
880 if (descriptions_) { 880 if (descriptions_) {
881 for (int i = 0; descriptions_[i].description; ++i) { 881 for (int i = 0; descriptions_[i].description; ++i) {
882 histogram->bucket_description_[descriptions_[i].sample] = 882 histogram->bucket_description_[descriptions_[i].sample] =
883 descriptions_[i].description; 883 descriptions_[i].description;
884 } 884 }
885 } 885 }
886 } 886 }
887 887
888 private: 888 private:
889 const DescriptionPair* descriptions_; 889 const DescriptionPair* descriptions_;
890 890
891 DISALLOW_COPY_AND_ASSIGN(Factory); 891 DISALLOW_COPY_AND_ASSIGN(Factory);
892 }; 892 };
893 893
894 LinearHistogram::~LinearHistogram() {} 894 LinearHistogram::~LinearHistogram() {}
895 895
896 HistogramBase* LinearHistogram::FactoryGet(const std::string& name, 896 HistogramBase* LinearHistogram::FactoryGet(const std::string& name,
897 Sample minimum, 897 Sample minimum,
898 Sample maximum, 898 Sample maximum,
899 uint32_t bucket_count, 899 uint32_t bucket_count,
900 int32_t flags) { 900 int32_t flags) {
901 return FactoryGetWithRangeDescription(name, minimum, maximum, bucket_count, 901 return FactoryGetWithRangeDescription(
902 flags, nullptr); 902 name, minimum, maximum, bucket_count, flags, NULL);
903 } 903 }
904 904
905 HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name, 905 HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name,
906 TimeDelta minimum, 906 TimeDelta minimum,
907 TimeDelta maximum, 907 TimeDelta maximum,
908 uint32_t bucket_count, 908 uint32_t bucket_count,
909 int32_t flags) { 909 int32_t flags) {
910 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()), 910 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()),
911 static_cast<Sample>(maximum.InMilliseconds()), bucket_count, 911 static_cast<Sample>(maximum.InMilliseconds()), bucket_count,
912 flags); 912 flags);
(...skipping 10 matching lines...) Expand all
923 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, 923 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name,
924 TimeDelta minimum, 924 TimeDelta minimum,
925 TimeDelta maximum, 925 TimeDelta maximum,
926 uint32_t bucket_count, 926 uint32_t bucket_count,
927 int32_t flags) { 927 int32_t flags) {
928 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, 928 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count,
929 flags); 929 flags);
930 } 930 }
931 931
932 std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate( 932 std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate(
933 const std::string& name, 933 const char* name,
934 Sample minimum, 934 Sample minimum,
935 Sample maximum, 935 Sample maximum,
936 const BucketRanges* ranges, 936 const BucketRanges* ranges,
937 const DelayedPersistentAllocation& counts, 937 const DelayedPersistentAllocation& counts,
938 const DelayedPersistentAllocation& logged_counts, 938 const DelayedPersistentAllocation& logged_counts,
939 HistogramSamples::Metadata* meta, 939 HistogramSamples::Metadata* meta,
940 HistogramSamples::Metadata* logged_meta) { 940 HistogramSamples::Metadata* logged_meta) {
941 return WrapUnique(new LinearHistogram(name, minimum, maximum, ranges, counts, 941 return WrapUnique(new LinearHistogram(name, minimum, maximum, ranges, counts,
942 logged_counts, meta, logged_meta)); 942 logged_counts, meta, logged_meta));
943 } 943 }
(...skipping 10 matching lines...) Expand all
954 DCHECK(valid_arguments); 954 DCHECK(valid_arguments);
955 955
956 return Factory(name, minimum, maximum, bucket_count, flags, descriptions) 956 return Factory(name, minimum, maximum, bucket_count, flags, descriptions)
957 .Build(); 957 .Build();
958 } 958 }
959 959
960 HistogramType LinearHistogram::GetHistogramType() const { 960 HistogramType LinearHistogram::GetHistogramType() const {
961 return LINEAR_HISTOGRAM; 961 return LINEAR_HISTOGRAM;
962 } 962 }
963 963
964 LinearHistogram::LinearHistogram(const std::string& name, 964 LinearHistogram::LinearHistogram(const char* name,
965 Sample minimum, 965 Sample minimum,
966 Sample maximum, 966 Sample maximum,
967 const BucketRanges* ranges) 967 const BucketRanges* ranges)
968 : Histogram(name, minimum, maximum, ranges) { 968 : Histogram(name, minimum, maximum, ranges) {}
969 }
970 969
971 LinearHistogram::LinearHistogram( 970 LinearHistogram::LinearHistogram(
972 const std::string& name, 971 const char* name,
973 Sample minimum, 972 Sample minimum,
974 Sample maximum, 973 Sample maximum,
975 const BucketRanges* ranges, 974 const BucketRanges* ranges,
976 const DelayedPersistentAllocation& counts, 975 const DelayedPersistentAllocation& counts,
977 const DelayedPersistentAllocation& logged_counts, 976 const DelayedPersistentAllocation& logged_counts,
978 HistogramSamples::Metadata* meta, 977 HistogramSamples::Metadata* meta,
979 HistogramSamples::Metadata* logged_meta) 978 HistogramSamples::Metadata* logged_meta)
980 : Histogram(name, 979 : Histogram(name,
981 minimum, 980 minimum,
982 maximum, 981 maximum,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 protected: 1061 protected:
1063 BucketRanges* CreateRanges() override { 1062 BucketRanges* CreateRanges() override {
1064 BucketRanges* ranges = new BucketRanges(3 + 1); 1063 BucketRanges* ranges = new BucketRanges(3 + 1);
1065 LinearHistogram::InitializeBucketRanges(1, 2, ranges); 1064 LinearHistogram::InitializeBucketRanges(1, 2, ranges);
1066 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622. 1065 base::debug::Alias(&ranges); // TODO(bcwhite): Remove after crbug/586622.
1067 return ranges; 1066 return ranges;
1068 } 1067 }
1069 1068
1070 std::unique_ptr<HistogramBase> HeapAlloc( 1069 std::unique_ptr<HistogramBase> HeapAlloc(
1071 const BucketRanges* ranges) override { 1070 const BucketRanges* ranges) override {
1072 return WrapUnique(new BooleanHistogram(name_, ranges)); 1071 return WrapUnique(new BooleanHistogram(GetPermanentName(name_), ranges));
1073 } 1072 }
1074 1073
1075 private: 1074 private:
1076 DISALLOW_COPY_AND_ASSIGN(Factory); 1075 DISALLOW_COPY_AND_ASSIGN(Factory);
1077 }; 1076 };
1078 1077
1079 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, 1078 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name,
1080 int32_t flags) { 1079 int32_t flags) {
1081 return Factory(name, flags).Build(); 1080 return Factory(name, flags).Build();
1082 } 1081 }
1083 1082
1084 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { 1083 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) {
1085 return FactoryGet(std::string(name), flags); 1084 return FactoryGet(std::string(name), flags);
1086 } 1085 }
1087 1086
1088 std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate( 1087 std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate(
1089 const std::string& name, 1088 const char* name,
1090 const BucketRanges* ranges, 1089 const BucketRanges* ranges,
1091 const DelayedPersistentAllocation& counts, 1090 const DelayedPersistentAllocation& counts,
1092 const DelayedPersistentAllocation& logged_counts, 1091 const DelayedPersistentAllocation& logged_counts,
1093 HistogramSamples::Metadata* meta, 1092 HistogramSamples::Metadata* meta,
1094 HistogramSamples::Metadata* logged_meta) { 1093 HistogramSamples::Metadata* logged_meta) {
1095 return WrapUnique(new BooleanHistogram(name, ranges, counts, logged_counts, 1094 return WrapUnique(new BooleanHistogram(name, ranges, counts, logged_counts,
1096 meta, logged_meta)); 1095 meta, logged_meta));
1097 } 1096 }
1098 1097
1099 HistogramType BooleanHistogram::GetHistogramType() const { 1098 HistogramType BooleanHistogram::GetHistogramType() const {
1100 return BOOLEAN_HISTOGRAM; 1099 return BOOLEAN_HISTOGRAM;
1101 } 1100 }
1102 1101
1103 BooleanHistogram::BooleanHistogram(const std::string& name, 1102 BooleanHistogram::BooleanHistogram(const char* name, const BucketRanges* ranges)
1104 const BucketRanges* ranges)
1105 : LinearHistogram(name, 1, 2, ranges) {} 1103 : LinearHistogram(name, 1, 2, ranges) {}
1106 1104
1107 BooleanHistogram::BooleanHistogram( 1105 BooleanHistogram::BooleanHistogram(
1108 const std::string& name, 1106 const char* name,
1109 const BucketRanges* ranges, 1107 const BucketRanges* ranges,
1110 const DelayedPersistentAllocation& counts, 1108 const DelayedPersistentAllocation& counts,
1111 const DelayedPersistentAllocation& logged_counts, 1109 const DelayedPersistentAllocation& logged_counts,
1112 HistogramSamples::Metadata* meta, 1110 HistogramSamples::Metadata* meta,
1113 HistogramSamples::Metadata* logged_meta) 1111 HistogramSamples::Metadata* logged_meta)
1114 : LinearHistogram(name, 1112 : LinearHistogram(name,
1115 1, 1113 1,
1116 2, 1114 2,
1117 ranges, 1115 ranges,
1118 counts, 1116 counts,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); 1168 BucketRanges* bucket_ranges = new BucketRanges(ranges.size());
1171 for (uint32_t i = 0; i < ranges.size(); i++) { 1169 for (uint32_t i = 0; i < ranges.size(); i++) {
1172 bucket_ranges->set_range(i, ranges[i]); 1170 bucket_ranges->set_range(i, ranges[i]);
1173 } 1171 }
1174 bucket_ranges->ResetChecksum(); 1172 bucket_ranges->ResetChecksum();
1175 return bucket_ranges; 1173 return bucket_ranges;
1176 } 1174 }
1177 1175
1178 std::unique_ptr<HistogramBase> HeapAlloc( 1176 std::unique_ptr<HistogramBase> HeapAlloc(
1179 const BucketRanges* ranges) override { 1177 const BucketRanges* ranges) override {
1180 return WrapUnique(new CustomHistogram(name_, ranges)); 1178 return WrapUnique(new CustomHistogram(GetPermanentName(name_), ranges));
1181 } 1179 }
1182 1180
1183 private: 1181 private:
1184 const std::vector<Sample>* custom_ranges_; 1182 const std::vector<Sample>* custom_ranges_;
1185 1183
1186 DISALLOW_COPY_AND_ASSIGN(Factory); 1184 DISALLOW_COPY_AND_ASSIGN(Factory);
1187 }; 1185 };
1188 1186
1189 HistogramBase* CustomHistogram::FactoryGet( 1187 HistogramBase* CustomHistogram::FactoryGet(
1190 const std::string& name, 1188 const std::string& name,
1191 const std::vector<Sample>& custom_ranges, 1189 const std::vector<Sample>& custom_ranges,
1192 int32_t flags) { 1190 int32_t flags) {
1193 CHECK(ValidateCustomRanges(custom_ranges)); 1191 CHECK(ValidateCustomRanges(custom_ranges));
1194 1192
1195 return Factory(name, &custom_ranges, flags).Build(); 1193 return Factory(name, &custom_ranges, flags).Build();
1196 } 1194 }
1197 1195
1198 HistogramBase* CustomHistogram::FactoryGet( 1196 HistogramBase* CustomHistogram::FactoryGet(
1199 const char* name, 1197 const char* name,
1200 const std::vector<Sample>& custom_ranges, 1198 const std::vector<Sample>& custom_ranges,
1201 int32_t flags) { 1199 int32_t flags) {
1202 return FactoryGet(std::string(name), custom_ranges, flags); 1200 return FactoryGet(std::string(name), custom_ranges, flags);
1203 } 1201 }
1204 1202
1205 std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate( 1203 std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate(
1206 const std::string& name, 1204 const char* name,
1207 const BucketRanges* ranges, 1205 const BucketRanges* ranges,
1208 const DelayedPersistentAllocation& counts, 1206 const DelayedPersistentAllocation& counts,
1209 const DelayedPersistentAllocation& logged_counts, 1207 const DelayedPersistentAllocation& logged_counts,
1210 HistogramSamples::Metadata* meta, 1208 HistogramSamples::Metadata* meta,
1211 HistogramSamples::Metadata* logged_meta) { 1209 HistogramSamples::Metadata* logged_meta) {
1212 return WrapUnique(new CustomHistogram(name, ranges, counts, logged_counts, 1210 return WrapUnique(new CustomHistogram(name, ranges, counts, logged_counts,
1213 meta, logged_meta)); 1211 meta, logged_meta));
1214 } 1212 }
1215 1213
1216 HistogramType CustomHistogram::GetHistogramType() const { 1214 HistogramType CustomHistogram::GetHistogramType() const {
1217 return CUSTOM_HISTOGRAM; 1215 return CUSTOM_HISTOGRAM;
1218 } 1216 }
1219 1217
1220 // static 1218 // static
1221 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( 1219 std::vector<Sample> CustomHistogram::ArrayToCustomRanges(
1222 const Sample* values, uint32_t num_values) { 1220 const Sample* values, uint32_t num_values) {
1223 std::vector<Sample> all_values; 1221 std::vector<Sample> all_values;
1224 for (uint32_t i = 0; i < num_values; ++i) { 1222 for (uint32_t i = 0; i < num_values; ++i) {
1225 Sample value = values[i]; 1223 Sample value = values[i];
1226 all_values.push_back(value); 1224 all_values.push_back(value);
1227 1225
1228 // Ensure that a guard bucket is added. If we end up with duplicate 1226 // Ensure that a guard bucket is added. If we end up with duplicate
1229 // values, FactoryGet will take care of removing them. 1227 // values, FactoryGet will take care of removing them.
1230 all_values.push_back(value + 1); 1228 all_values.push_back(value + 1);
1231 } 1229 }
1232 return all_values; 1230 return all_values;
1233 } 1231 }
1234 1232
1235 CustomHistogram::CustomHistogram(const std::string& name, 1233 CustomHistogram::CustomHistogram(const char* name, const BucketRanges* ranges)
1236 const BucketRanges* ranges)
1237 : Histogram(name, 1234 : Histogram(name,
1238 ranges->range(1), 1235 ranges->range(1),
1239 ranges->range(ranges->bucket_count() - 1), 1236 ranges->range(ranges->bucket_count() - 1),
1240 ranges) {} 1237 ranges) {}
1241 1238
1242 CustomHistogram::CustomHistogram( 1239 CustomHistogram::CustomHistogram(
1243 const std::string& name, 1240 const char* name,
1244 const BucketRanges* ranges, 1241 const BucketRanges* ranges,
1245 const DelayedPersistentAllocation& counts, 1242 const DelayedPersistentAllocation& counts,
1246 const DelayedPersistentAllocation& logged_counts, 1243 const DelayedPersistentAllocation& logged_counts,
1247 HistogramSamples::Metadata* meta, 1244 HistogramSamples::Metadata* meta,
1248 HistogramSamples::Metadata* logged_meta) 1245 HistogramSamples::Metadata* logged_meta)
1249 : Histogram(name, 1246 : Histogram(name,
1250 ranges->range(1), 1247 ranges->range(1),
1251 ranges->range(ranges->bucket_count() - 1), 1248 ranges->range(ranges->bucket_count() - 1),
1252 ranges, 1249 ranges,
1253 counts, 1250 counts,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 Sample sample = custom_ranges[i]; 1313 Sample sample = custom_ranges[i];
1317 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) 1314 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1)
1318 return false; 1315 return false;
1319 if (sample != 0) 1316 if (sample != 0)
1320 has_valid_range = true; 1317 has_valid_range = true;
1321 } 1318 }
1322 return has_valid_range; 1319 return has_valid_range;
1323 } 1320 }
1324 1321
1325 } // namespace base 1322 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/histogram_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698