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" |
11 | 11 |
12 #include <limits.h> | 12 #include <limits.h> |
13 #include <math.h> | 13 #include <math.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/debug/alias.h" | 19 #include "base/debug/alias.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/ptr_util.h" |
21 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
22 #include "base/metrics/metrics_hashes.h" | 23 #include "base/metrics/metrics_hashes.h" |
23 #include "base/metrics/persistent_histogram_allocator.h" | 24 #include "base/metrics/persistent_histogram_allocator.h" |
24 #include "base/metrics/persistent_memory_allocator.h" | 25 #include "base/metrics/persistent_memory_allocator.h" |
25 #include "base/metrics/sample_vector.h" | 26 #include "base/metrics/sample_vector.h" |
26 #include "base/metrics/statistics_recorder.h" | 27 #include "base/metrics/statistics_recorder.h" |
27 #include "base/pickle.h" | 28 #include "base/pickle.h" |
28 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
29 #include "base/strings/stringprintf.h" | 30 #include "base/strings/stringprintf.h" |
30 #include "base/synchronization/lock.h" | 31 #include "base/synchronization/lock.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 116 |
116 // Create a BucketRanges structure appropriate for this histogram. | 117 // Create a BucketRanges structure appropriate for this histogram. |
117 virtual BucketRanges* CreateRanges() { | 118 virtual BucketRanges* CreateRanges() { |
118 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 119 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
119 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 120 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
120 return ranges; | 121 return ranges; |
121 } | 122 } |
122 | 123 |
123 // Allocate the correct Histogram object off the heap (in case persistent | 124 // Allocate the correct Histogram object off the heap (in case persistent |
124 // memory is not available). | 125 // memory is not available). |
125 virtual scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { | 126 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { |
126 return make_scoped_ptr(new Histogram(name_, minimum_, maximum_, ranges)); | 127 return WrapUnique(new Histogram(name_, minimum_, maximum_, ranges)); |
127 } | 128 } |
128 | 129 |
129 // Perform any required datafill on the just-created histogram. If | 130 // Perform any required datafill on the just-created histogram. If |
130 // overridden, be sure to call the "super" version -- this method may not | 131 // overridden, be sure to call the "super" version -- this method may not |
131 // always remain empty. | 132 // always remain empty. |
132 virtual void FillHistogram(HistogramBase* histogram) {} | 133 virtual void FillHistogram(HistogramBase* histogram) {} |
133 | 134 |
134 // These values are protected (instead of private) because they need to | 135 // These values are protected (instead of private) because they need to |
135 // be accessible to methods of sub-classes in order to avoid passing | 136 // be accessible to methods of sub-classes in order to avoid passing |
136 // unnecessary parameters everywhere. | 137 // unnecessary parameters everywhere. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 minimum_ = registered_ranges->range(1); | 170 minimum_ = registered_ranges->range(1); |
170 maximum_ = registered_ranges->range(bucket_count_ - 1); | 171 maximum_ = registered_ranges->range(bucket_count_ - 1); |
171 } | 172 } |
172 | 173 |
173 // Try to create the histogram using a "persistent" allocator. As of | 174 // Try to create the histogram using a "persistent" allocator. As of |
174 // 2016-02-25, the availability of such is controlled by a base::Feature | 175 // 2016-02-25, the availability of such is controlled by a base::Feature |
175 // that is off by default. If the allocator doesn't exist or if | 176 // that is off by default. If the allocator doesn't exist or if |
176 // allocating from it fails, code below will allocate the histogram from | 177 // allocating from it fails, code below will allocate the histogram from |
177 // the process heap. | 178 // the process heap. |
178 PersistentHistogramAllocator::Reference histogram_ref = 0; | 179 PersistentHistogramAllocator::Reference histogram_ref = 0; |
179 scoped_ptr<HistogramBase> tentative_histogram; | 180 std::unique_ptr<HistogramBase> tentative_histogram; |
180 PersistentHistogramAllocator* allocator = | 181 PersistentHistogramAllocator* allocator = |
181 PersistentHistogramAllocator::GetGlobalAllocator(); | 182 PersistentHistogramAllocator::GetGlobalAllocator(); |
182 if (allocator) { | 183 if (allocator) { |
183 tentative_histogram = allocator->AllocateHistogram( | 184 tentative_histogram = allocator->AllocateHistogram( |
184 histogram_type_, | 185 histogram_type_, |
185 name_, | 186 name_, |
186 minimum_, | 187 minimum_, |
187 maximum_, | 188 maximum_, |
188 registered_ranges, | 189 registered_ranges, |
189 flags_, | 190 flags_, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 271 |
271 HistogramBase* Histogram::FactoryTimeGet(const char* name, | 272 HistogramBase* Histogram::FactoryTimeGet(const char* name, |
272 TimeDelta minimum, | 273 TimeDelta minimum, |
273 TimeDelta maximum, | 274 TimeDelta maximum, |
274 uint32_t bucket_count, | 275 uint32_t bucket_count, |
275 int32_t flags) { | 276 int32_t flags) { |
276 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, | 277 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
277 flags); | 278 flags); |
278 } | 279 } |
279 | 280 |
280 scoped_ptr<HistogramBase> Histogram::PersistentCreate( | 281 std::unique_ptr<HistogramBase> Histogram::PersistentCreate( |
281 const std::string& name, | 282 const std::string& name, |
282 Sample minimum, | 283 Sample minimum, |
283 Sample maximum, | 284 Sample maximum, |
284 const BucketRanges* ranges, | 285 const BucketRanges* ranges, |
285 HistogramBase::AtomicCount* counts, | 286 HistogramBase::AtomicCount* counts, |
286 HistogramBase::AtomicCount* logged_counts, | 287 HistogramBase::AtomicCount* logged_counts, |
287 uint32_t counts_size, | 288 uint32_t counts_size, |
288 HistogramSamples::Metadata* meta, | 289 HistogramSamples::Metadata* meta, |
289 HistogramSamples::Metadata* logged_meta) { | 290 HistogramSamples::Metadata* logged_meta) { |
290 return make_scoped_ptr(new Histogram( | 291 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts, |
291 name, minimum, maximum, ranges, counts, logged_counts, counts_size, | 292 logged_counts, counts_size, meta, |
292 meta, logged_meta)); | 293 logged_meta)); |
293 } | 294 } |
294 | 295 |
295 // Calculate what range of values are held in each bucket. | 296 // Calculate what range of values are held in each bucket. |
296 // We have to be careful that we don't pick a ratio between starting points in | 297 // We have to be careful that we don't pick a ratio between starting points in |
297 // consecutive buckets that is sooo small, that the integer bounds are the same | 298 // consecutive buckets that is sooo small, that the integer bounds are the same |
298 // (effectively making one bucket get no values). We need to avoid: | 299 // (effectively making one bucket get no values). We need to avoid: |
299 // ranges(i) == ranges(i + 1) | 300 // ranges(i) == ranges(i + 1) |
300 // To avoid that, we just do a fine-grained bucket width as far as we need to | 301 // To avoid that, we just do a fine-grained bucket width as far as we need to |
301 // until we get a ratio that moves us along at least 2 units at a time. From | 302 // until we get a ratio that moves us along at least 2 units at a time. From |
302 // that bucket onward we do use the exponential growth of buckets. | 303 // that bucket onward we do use the exponential growth of buckets. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 value = 0; | 434 value = 0; |
434 if (count <= 0) { | 435 if (count <= 0) { |
435 NOTREACHED(); | 436 NOTREACHED(); |
436 return; | 437 return; |
437 } | 438 } |
438 samples_->Accumulate(value, count); | 439 samples_->Accumulate(value, count); |
439 | 440 |
440 FindAndRunCallback(value); | 441 FindAndRunCallback(value); |
441 } | 442 } |
442 | 443 |
443 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { | 444 std::unique_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
444 return SnapshotSampleVector(); | 445 return SnapshotSampleVector(); |
445 } | 446 } |
446 | 447 |
447 scoped_ptr<HistogramSamples> Histogram::SnapshotDelta() { | 448 std::unique_ptr<HistogramSamples> Histogram::SnapshotDelta() { |
448 scoped_ptr<HistogramSamples> snapshot = SnapshotSampleVector(); | 449 std::unique_ptr<HistogramSamples> snapshot = SnapshotSampleVector(); |
449 if (!logged_samples_) { | 450 if (!logged_samples_) { |
450 // If nothing has been previously logged, save this one as | 451 // If nothing has been previously logged, save this one as |
451 // |logged_samples_| and gather another snapshot to return. | 452 // |logged_samples_| and gather another snapshot to return. |
452 logged_samples_.swap(snapshot); | 453 logged_samples_.swap(snapshot); |
453 return SnapshotSampleVector(); | 454 return SnapshotSampleVector(); |
454 } | 455 } |
455 | 456 |
456 // Subtract what was previously logged and update that information. | 457 // Subtract what was previously logged and update that information. |
457 snapshot->Subtract(*logged_samples_); | 458 snapshot->Subtract(*logged_samples_); |
458 logged_samples_->Add(*snapshot); | 459 logged_samples_->Add(*snapshot); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 HistogramBase* histogram = Histogram::FactoryGet( | 569 HistogramBase* histogram = Histogram::FactoryGet( |
569 histogram_name, declared_min, declared_max, bucket_count, flags); | 570 histogram_name, declared_min, declared_max, bucket_count, flags); |
570 | 571 |
571 if (!ValidateRangeChecksum(*histogram, range_checksum)) { | 572 if (!ValidateRangeChecksum(*histogram, range_checksum)) { |
572 // The serialized histogram might be corrupted. | 573 // The serialized histogram might be corrupted. |
573 return NULL; | 574 return NULL; |
574 } | 575 } |
575 return histogram; | 576 return histogram; |
576 } | 577 } |
577 | 578 |
578 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { | 579 std::unique_ptr<SampleVector> Histogram::SnapshotSampleVector() const { |
579 scoped_ptr<SampleVector> samples( | 580 std::unique_ptr<SampleVector> samples( |
580 new SampleVector(samples_->id(), bucket_ranges())); | 581 new SampleVector(samples_->id(), bucket_ranges())); |
581 samples->Add(*samples_); | 582 samples->Add(*samples_); |
582 return samples; | 583 return samples; |
583 } | 584 } |
584 | 585 |
585 void Histogram::WriteAsciiImpl(bool graph_it, | 586 void Histogram::WriteAsciiImpl(bool graph_it, |
586 const std::string& newline, | 587 const std::string& newline, |
587 std::string* output) const { | 588 std::string* output) const { |
588 // Get local (stack) copies of all effectively volatile class data so that we | 589 // Get local (stack) copies of all effectively volatile class data so that we |
589 // are consistent across our output activities. | 590 // are consistent across our output activities. |
590 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); | 591 std::unique_ptr<SampleVector> snapshot = SnapshotSampleVector(); |
591 Count sample_count = snapshot->TotalCount(); | 592 Count sample_count = snapshot->TotalCount(); |
592 | 593 |
593 WriteAsciiHeader(*snapshot, sample_count, output); | 594 WriteAsciiHeader(*snapshot, sample_count, output); |
594 output->append(newline); | 595 output->append(newline); |
595 | 596 |
596 // Prepare to normalize graphical rendering of bucket contents. | 597 // Prepare to normalize graphical rendering of bucket contents. |
597 double max_size = 0; | 598 double max_size = 0; |
598 if (graph_it) | 599 if (graph_it) |
599 max_size = GetPeakBucketSize(*snapshot); | 600 max_size = GetPeakBucketSize(*snapshot); |
600 | 601 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 void Histogram::GetParameters(DictionaryValue* params) const { | 694 void Histogram::GetParameters(DictionaryValue* params) const { |
694 params->SetString("type", HistogramTypeToString(GetHistogramType())); | 695 params->SetString("type", HistogramTypeToString(GetHistogramType())); |
695 params->SetInteger("min", declared_min()); | 696 params->SetInteger("min", declared_min()); |
696 params->SetInteger("max", declared_max()); | 697 params->SetInteger("max", declared_max()); |
697 params->SetInteger("bucket_count", static_cast<int>(bucket_count())); | 698 params->SetInteger("bucket_count", static_cast<int>(bucket_count())); |
698 } | 699 } |
699 | 700 |
700 void Histogram::GetCountAndBucketData(Count* count, | 701 void Histogram::GetCountAndBucketData(Count* count, |
701 int64_t* sum, | 702 int64_t* sum, |
702 ListValue* buckets) const { | 703 ListValue* buckets) const { |
703 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); | 704 std::unique_ptr<SampleVector> snapshot = SnapshotSampleVector(); |
704 *count = snapshot->TotalCount(); | 705 *count = snapshot->TotalCount(); |
705 *sum = snapshot->sum(); | 706 *sum = snapshot->sum(); |
706 uint32_t index = 0; | 707 uint32_t index = 0; |
707 for (uint32_t i = 0; i < bucket_count(); ++i) { | 708 for (uint32_t i = 0; i < bucket_count(); ++i) { |
708 Sample count_at_index = snapshot->GetCountAtIndex(i); | 709 Sample count_at_index = snapshot->GetCountAtIndex(i); |
709 if (count_at_index > 0) { | 710 if (count_at_index > 0) { |
710 scoped_ptr<DictionaryValue> bucket_value(new DictionaryValue()); | 711 std::unique_ptr<DictionaryValue> bucket_value(new DictionaryValue()); |
711 bucket_value->SetInteger("low", ranges(i)); | 712 bucket_value->SetInteger("low", ranges(i)); |
712 if (i != bucket_count() - 1) | 713 if (i != bucket_count() - 1) |
713 bucket_value->SetInteger("high", ranges(i + 1)); | 714 bucket_value->SetInteger("high", ranges(i + 1)); |
714 bucket_value->SetInteger("count", count_at_index); | 715 bucket_value->SetInteger("count", count_at_index); |
715 buckets->Set(index, bucket_value.release()); | 716 buckets->Set(index, bucket_value.release()); |
716 ++index; | 717 ++index; |
717 } | 718 } |
718 } | 719 } |
719 } | 720 } |
720 | 721 |
(...skipping 15 matching lines...) Expand all Loading... |
736 descriptions_ = descriptions; | 737 descriptions_ = descriptions; |
737 } | 738 } |
738 | 739 |
739 protected: | 740 protected: |
740 BucketRanges* CreateRanges() override { | 741 BucketRanges* CreateRanges() override { |
741 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 742 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
742 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 743 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
743 return ranges; | 744 return ranges; |
744 } | 745 } |
745 | 746 |
746 scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) override { | 747 std::unique_ptr<HistogramBase> HeapAlloc( |
747 return make_scoped_ptr( | 748 const BucketRanges* ranges) override { |
| 749 return WrapUnique( |
748 new LinearHistogram(name_, minimum_, maximum_, ranges)); | 750 new LinearHistogram(name_, minimum_, maximum_, ranges)); |
749 } | 751 } |
750 | 752 |
751 void FillHistogram(HistogramBase* base_histogram) override { | 753 void FillHistogram(HistogramBase* base_histogram) override { |
752 Histogram::Factory::FillHistogram(base_histogram); | 754 Histogram::Factory::FillHistogram(base_histogram); |
753 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); | 755 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); |
754 // Set range descriptions. | 756 // Set range descriptions. |
755 if (descriptions_) { | 757 if (descriptions_) { |
756 for (int i = 0; descriptions_[i].description; ++i) { | 758 for (int i = 0; descriptions_[i].description; ++i) { |
757 histogram->bucket_description_[descriptions_[i].sample] = | 759 histogram->bucket_description_[descriptions_[i].sample] = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 | 799 |
798 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, | 800 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, |
799 TimeDelta minimum, | 801 TimeDelta minimum, |
800 TimeDelta maximum, | 802 TimeDelta maximum, |
801 uint32_t bucket_count, | 803 uint32_t bucket_count, |
802 int32_t flags) { | 804 int32_t flags) { |
803 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, | 805 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
804 flags); | 806 flags); |
805 } | 807 } |
806 | 808 |
807 scoped_ptr<HistogramBase> LinearHistogram::PersistentCreate( | 809 std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate( |
808 const std::string& name, | 810 const std::string& name, |
809 Sample minimum, | 811 Sample minimum, |
810 Sample maximum, | 812 Sample maximum, |
811 const BucketRanges* ranges, | 813 const BucketRanges* ranges, |
812 HistogramBase::AtomicCount* counts, | 814 HistogramBase::AtomicCount* counts, |
813 HistogramBase::AtomicCount* logged_counts, | 815 HistogramBase::AtomicCount* logged_counts, |
814 uint32_t counts_size, | 816 uint32_t counts_size, |
815 HistogramSamples::Metadata* meta, | 817 HistogramSamples::Metadata* meta, |
816 HistogramSamples::Metadata* logged_meta) { | 818 HistogramSamples::Metadata* logged_meta) { |
817 return make_scoped_ptr(new LinearHistogram( | 819 return WrapUnique(new LinearHistogram(name, minimum, maximum, ranges, |
818 name, minimum, maximum, ranges, counts, logged_counts, counts_size, | 820 counts, logged_counts, |
819 meta, logged_meta)); | 821 counts_size, meta, logged_meta)); |
820 } | 822 } |
821 | 823 |
822 HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( | 824 HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( |
823 const std::string& name, | 825 const std::string& name, |
824 Sample minimum, | 826 Sample minimum, |
825 Sample maximum, | 827 Sample maximum, |
826 uint32_t bucket_count, | 828 uint32_t bucket_count, |
827 int32_t flags, | 829 int32_t flags, |
828 const DescriptionPair descriptions[]) { | 830 const DescriptionPair descriptions[]) { |
829 bool valid_arguments = Histogram::InspectConstructionArguments( | 831 bool valid_arguments = Histogram::InspectConstructionArguments( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 Factory(const std::string& name, int32_t flags) | 929 Factory(const std::string& name, int32_t flags) |
928 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {} | 930 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {} |
929 | 931 |
930 protected: | 932 protected: |
931 BucketRanges* CreateRanges() override { | 933 BucketRanges* CreateRanges() override { |
932 BucketRanges* ranges = new BucketRanges(3 + 1); | 934 BucketRanges* ranges = new BucketRanges(3 + 1); |
933 LinearHistogram::InitializeBucketRanges(1, 2, ranges); | 935 LinearHistogram::InitializeBucketRanges(1, 2, ranges); |
934 return ranges; | 936 return ranges; |
935 } | 937 } |
936 | 938 |
937 scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) override { | 939 std::unique_ptr<HistogramBase> HeapAlloc( |
938 return make_scoped_ptr(new BooleanHistogram(name_, ranges)); | 940 const BucketRanges* ranges) override { |
| 941 return WrapUnique(new BooleanHistogram(name_, ranges)); |
939 } | 942 } |
940 | 943 |
941 private: | 944 private: |
942 DISALLOW_COPY_AND_ASSIGN(Factory); | 945 DISALLOW_COPY_AND_ASSIGN(Factory); |
943 }; | 946 }; |
944 | 947 |
945 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, | 948 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, |
946 int32_t flags) { | 949 int32_t flags) { |
947 return Factory(name, flags).Build(); | 950 return Factory(name, flags).Build(); |
948 } | 951 } |
949 | 952 |
950 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { | 953 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { |
951 return FactoryGet(std::string(name), flags); | 954 return FactoryGet(std::string(name), flags); |
952 } | 955 } |
953 | 956 |
954 scoped_ptr<HistogramBase> BooleanHistogram::PersistentCreate( | 957 std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate( |
955 const std::string& name, | 958 const std::string& name, |
956 const BucketRanges* ranges, | 959 const BucketRanges* ranges, |
957 HistogramBase::AtomicCount* counts, | 960 HistogramBase::AtomicCount* counts, |
958 HistogramBase::AtomicCount* logged_counts, | 961 HistogramBase::AtomicCount* logged_counts, |
959 HistogramSamples::Metadata* meta, | 962 HistogramSamples::Metadata* meta, |
960 HistogramSamples::Metadata* logged_meta) { | 963 HistogramSamples::Metadata* logged_meta) { |
961 return make_scoped_ptr(new BooleanHistogram( | 964 return WrapUnique(new BooleanHistogram( |
962 name, ranges, counts, logged_counts, meta, logged_meta)); | 965 name, ranges, counts, logged_counts, meta, logged_meta)); |
963 } | 966 } |
964 | 967 |
965 HistogramType BooleanHistogram::GetHistogramType() const { | 968 HistogramType BooleanHistogram::GetHistogramType() const { |
966 return BOOLEAN_HISTOGRAM; | 969 return BOOLEAN_HISTOGRAM; |
967 } | 970 } |
968 | 971 |
969 BooleanHistogram::BooleanHistogram(const std::string& name, | 972 BooleanHistogram::BooleanHistogram(const std::string& name, |
970 const BucketRanges* ranges) | 973 const BucketRanges* ranges) |
971 : LinearHistogram(name, 1, 2, ranges) {} | 974 : LinearHistogram(name, 1, 2, ranges) {} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); | 1027 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); |
1025 | 1028 |
1026 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 1029 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
1027 for (uint32_t i = 0; i < ranges.size(); i++) { | 1030 for (uint32_t i = 0; i < ranges.size(); i++) { |
1028 bucket_ranges->set_range(i, ranges[i]); | 1031 bucket_ranges->set_range(i, ranges[i]); |
1029 } | 1032 } |
1030 bucket_ranges->ResetChecksum(); | 1033 bucket_ranges->ResetChecksum(); |
1031 return bucket_ranges; | 1034 return bucket_ranges; |
1032 } | 1035 } |
1033 | 1036 |
1034 scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) override { | 1037 std::unique_ptr<HistogramBase> HeapAlloc( |
1035 return make_scoped_ptr(new CustomHistogram(name_, ranges)); | 1038 const BucketRanges* ranges) override { |
| 1039 return WrapUnique(new CustomHistogram(name_, ranges)); |
1036 } | 1040 } |
1037 | 1041 |
1038 private: | 1042 private: |
1039 const std::vector<Sample>* custom_ranges_; | 1043 const std::vector<Sample>* custom_ranges_; |
1040 | 1044 |
1041 DISALLOW_COPY_AND_ASSIGN(Factory); | 1045 DISALLOW_COPY_AND_ASSIGN(Factory); |
1042 }; | 1046 }; |
1043 | 1047 |
1044 HistogramBase* CustomHistogram::FactoryGet( | 1048 HistogramBase* CustomHistogram::FactoryGet( |
1045 const std::string& name, | 1049 const std::string& name, |
1046 const std::vector<Sample>& custom_ranges, | 1050 const std::vector<Sample>& custom_ranges, |
1047 int32_t flags) { | 1051 int32_t flags) { |
1048 CHECK(ValidateCustomRanges(custom_ranges)); | 1052 CHECK(ValidateCustomRanges(custom_ranges)); |
1049 | 1053 |
1050 return Factory(name, &custom_ranges, flags).Build(); | 1054 return Factory(name, &custom_ranges, flags).Build(); |
1051 } | 1055 } |
1052 | 1056 |
1053 HistogramBase* CustomHistogram::FactoryGet( | 1057 HistogramBase* CustomHistogram::FactoryGet( |
1054 const char* name, | 1058 const char* name, |
1055 const std::vector<Sample>& custom_ranges, | 1059 const std::vector<Sample>& custom_ranges, |
1056 int32_t flags) { | 1060 int32_t flags) { |
1057 return FactoryGet(std::string(name), custom_ranges, flags); | 1061 return FactoryGet(std::string(name), custom_ranges, flags); |
1058 } | 1062 } |
1059 | 1063 |
1060 scoped_ptr<HistogramBase> CustomHistogram::PersistentCreate( | 1064 std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate( |
1061 const std::string& name, | 1065 const std::string& name, |
1062 const BucketRanges* ranges, | 1066 const BucketRanges* ranges, |
1063 HistogramBase::AtomicCount* counts, | 1067 HistogramBase::AtomicCount* counts, |
1064 HistogramBase::AtomicCount* logged_counts, | 1068 HistogramBase::AtomicCount* logged_counts, |
1065 uint32_t counts_size, | 1069 uint32_t counts_size, |
1066 HistogramSamples::Metadata* meta, | 1070 HistogramSamples::Metadata* meta, |
1067 HistogramSamples::Metadata* logged_meta) { | 1071 HistogramSamples::Metadata* logged_meta) { |
1068 return make_scoped_ptr(new CustomHistogram( | 1072 return WrapUnique(new CustomHistogram( |
1069 name, ranges, counts, logged_counts, counts_size, meta, logged_meta)); | 1073 name, ranges, counts, logged_counts, counts_size, meta, logged_meta)); |
1070 } | 1074 } |
1071 | 1075 |
1072 HistogramType CustomHistogram::GetHistogramType() const { | 1076 HistogramType CustomHistogram::GetHistogramType() const { |
1073 return CUSTOM_HISTOGRAM; | 1077 return CUSTOM_HISTOGRAM; |
1074 } | 1078 } |
1075 | 1079 |
1076 // static | 1080 // static |
1077 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( | 1081 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( |
1078 const Sample* values, uint32_t num_values) { | 1082 const Sample* values, uint32_t num_values) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 Sample sample = custom_ranges[i]; | 1172 Sample sample = custom_ranges[i]; |
1169 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1173 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
1170 return false; | 1174 return false; |
1171 if (sample != 0) | 1175 if (sample != 0) |
1172 has_valid_range = true; | 1176 has_valid_range = true; |
1173 } | 1177 } |
1174 return has_valid_range; | 1178 return has_valid_range; |
1175 } | 1179 } |
1176 | 1180 |
1177 } // namespace base | 1181 } // namespace base |
OLD | NEW |