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" |
| 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/metrics/histogram_macros.h" | 21 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/metrics/histogram_persistence.h" | |
| 23 #include "base/metrics/metrics_hashes.h" | 22 #include "base/metrics/metrics_hashes.h" |
| 23 #include "base/metrics/persistent_histogram_allocator.h" | |
| 24 #include "base/metrics/persistent_memory_allocator.h" | 24 #include "base/metrics/persistent_memory_allocator.h" |
| 25 #include "base/metrics/sample_vector.h" | 25 #include "base/metrics/sample_vector.h" |
| 26 #include "base/metrics/statistics_recorder.h" | 26 #include "base/metrics/statistics_recorder.h" |
| 27 #include "base/pickle.h" | 27 #include "base/pickle.h" |
| 28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 29 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 30 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
| 31 #include "base/values.h" | 31 #include "base/values.h" |
| 32 | 32 |
| 33 namespace base { | 33 namespace base { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 115 |
| 116 // Create a BucketRanges structure appropriate for this histogram. | 116 // Create a BucketRanges structure appropriate for this histogram. |
| 117 virtual BucketRanges* CreateRanges() { | 117 virtual BucketRanges* CreateRanges() { |
| 118 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 118 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
| 119 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 119 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
| 120 return ranges; | 120 return ranges; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Allocate the correct Histogram object off the heap (in case persistent | 123 // Allocate the correct Histogram object off the heap (in case persistent |
| 124 // memory is not available). | 124 // memory is not available). |
| 125 virtual HistogramBase* HeapAlloc(const BucketRanges* ranges) { | 125 virtual scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) { |
| 126 return new Histogram(name_, minimum_, maximum_, ranges); | 126 return make_scoped_ptr(new Histogram(name_, minimum_, maximum_, ranges)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Perform any required datafill on the just-created histogram. If | 129 // Perform any required datafill on the just-created histogram. If |
| 130 // overridden, be sure to call the "super" version. | 130 // overridden, be sure to call the "super" version. |
| 131 virtual void FillHistogram(HistogramBase* histogram) { | 131 virtual void FillHistogram(HistogramBase* histogram) { |
| 132 histogram->SetFlags(flags_); | 132 histogram->SetFlags(flags_); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // These values are protected (instead of private) because they need to | 135 // These values are protected (instead of private) because they need to |
| 136 // 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 |
| 137 // unnecessary parameters everywhere. | 137 // unnecessary parameters everywhere. |
| 138 const std::string& name_; | 138 const std::string& name_; |
| 139 const HistogramType histogram_type_; | 139 const HistogramType histogram_type_; |
| 140 HistogramBase::Sample minimum_; | 140 HistogramBase::Sample minimum_; |
| 141 HistogramBase::Sample maximum_; | 141 HistogramBase::Sample maximum_; |
| 142 uint32_t bucket_count_; | 142 uint32_t bucket_count_; |
| 143 int32_t flags_; | 143 int32_t flags_; |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 DISALLOW_COPY_AND_ASSIGN(Factory); | 146 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 HistogramBase* Histogram::Factory::Build() { | 149 HistogramBase* Histogram::Factory::Build() { |
| 150 // Import histograms from known persistent storage. Histograms could have | 150 // Import histograms from known persistent storage. Histograms could have |
| 151 // been added by other processes and they must be fetched and recognized | 151 // been added by other processes and they must be fetched and recognized |
| 152 // locally in order to be found by FindHistograms() below. If the persistent | 152 // locally in order to be found by FindHistograms() below. If the persistent |
| 153 // memory segment is not shared between processes, this call does nothing. | 153 // memory segment is not shared between processes, this call does nothing. |
| 154 ImportPersistentHistograms(); | 154 PersistentHistogramAllocator::ImportGlobalHistograms(); |
| 155 | 155 |
| 156 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); | 156 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); |
| 157 if (!histogram) { | 157 if (!histogram) { |
| 158 // To avoid racy destruction at shutdown, the following will be leaked. | 158 // To avoid racy destruction at shutdown, the following will be leaked. |
| 159 const BucketRanges* created_ranges = CreateRanges(); | 159 const BucketRanges* created_ranges = CreateRanges(); |
| 160 const BucketRanges* registered_ranges = | 160 const BucketRanges* registered_ranges = |
| 161 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); | 161 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); |
| 162 | 162 |
| 163 // In most cases, the bucket-count, minimum, and maximum values are known | 163 // In most cases, the bucket-count, minimum, and maximum values are known |
| 164 // when the code is written and so are passed in explicitly. In other | 164 // when the code is written and so are passed in explicitly. In other |
| 165 // cases (such as with a CustomHistogram), they are calculated dynamically | 165 // cases (such as with a CustomHistogram), they are calculated dynamically |
| 166 // at run-time. In the latter case, those ctor parameters are zero and | 166 // at run-time. In the latter case, those ctor parameters are zero and |
| 167 // the results extracted from the result of CreateRanges(). | 167 // the results extracted from the result of CreateRanges(). |
| 168 if (bucket_count_ == 0) { | 168 if (bucket_count_ == 0) { |
| 169 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); | 169 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); |
| 170 minimum_ = registered_ranges->range(1); | 170 minimum_ = registered_ranges->range(1); |
| 171 maximum_ = registered_ranges->range(bucket_count_ - 1); | 171 maximum_ = registered_ranges->range(bucket_count_ - 1); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Try to create the histogram using a "persistent" allocator. As of | 174 // Try to create the histogram using a "persistent" allocator. As of |
| 175 // 2015-01-14, the availability of such is controlled by a base::Feature | 175 // 2015-01-14, the availability of such is controlled by a base::Feature |
| 176 // 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 |
| 177 // allocating from it fails, code below will allocate the histogram from | 177 // allocating from it fails, code below will allocate the histogram from |
| 178 // the process heap. | 178 // the process heap. |
| 179 PersistentMemoryAllocator::Reference histogram_ref = 0; | 179 PersistentHistogramAllocator::Reference histogram_ref = 0; |
| 180 HistogramBase* tentative_histogram = nullptr; | 180 scoped_ptr<HistogramBase> tentative_histogram; |
| 181 PersistentMemoryAllocator* allocator = | 181 PersistentHistogramAllocator* allocator = |
| 182 GetPersistentHistogramMemoryAllocator(); | 182 PersistentHistogramAllocator::GetGlobalAllocator(); |
| 183 if (allocator) { | 183 if (allocator) { |
| 184 flags_ |= HistogramBase::kIsPersistent; | 184 flags_ |= HistogramBase::kIsPersistent; |
| 185 tentative_histogram = AllocatePersistentHistogram( | 185 tentative_histogram = allocator->AllocateHistogram( |
| 186 allocator, | |
| 187 histogram_type_, | 186 histogram_type_, |
| 188 name_, | 187 name_, |
| 189 minimum_, | 188 minimum_, |
| 190 maximum_, | 189 maximum_, |
| 191 registered_ranges, | 190 registered_ranges, |
| 192 flags_, | 191 flags_, |
| 193 &histogram_ref); | 192 &histogram_ref); |
| 194 } | 193 } |
| 195 | 194 |
| 196 // Handle the case where no persistent allocator is present or the | 195 // Handle the case where no persistent allocator is present or the |
| 197 // persistent allocation fails (perhaps because it is full). | 196 // persistent allocation fails (perhaps because it is full). |
| 198 if (!tentative_histogram) { | 197 if (!tentative_histogram) { |
| 199 DCHECK(!histogram_ref); // Should never have been set. | 198 DCHECK(!histogram_ref); // Should never have been set. |
| 200 DCHECK(!allocator); // Shouldn't have failed. | 199 DCHECK(!allocator); // Shouldn't have failed. |
| 201 flags_ &= ~HistogramBase::kIsPersistent; | 200 flags_ &= ~HistogramBase::kIsPersistent; |
| 202 tentative_histogram = HeapAlloc(registered_ranges); | 201 tentative_histogram = HeapAlloc(registered_ranges); |
| 203 } | 202 } |
| 204 | 203 |
| 205 FillHistogram(tentative_histogram); | 204 FillHistogram(tentative_histogram.get()); |
| 206 histogram = | 205 |
| 207 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 206 // Register this histogram with the StatisticsRecorder. Keep a copy of |
| 207 // the pointer value to tell later whether the locally created histogram | |
| 208 // was registered or deleted. | |
| 209 const void* my_histogram = tentative_histogram.get(); | |
|
Alexei Svitkine (slow)
2016/03/03 18:11:28
Why cont void*? Use the actual type.
Also, rename
bcwhite
2016/03/04 21:17:16
I don't want it to have a type because it could po
| |
| 210 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate( | |
| 211 tentative_histogram.release()); | |
| 208 | 212 |
| 209 // Persistent histograms need some follow-up processing. | 213 // Persistent histograms need some follow-up processing. |
| 210 if (histogram_ref) { | 214 if (histogram_ref) { |
| 211 FinalizePersistentHistogram(histogram_ref, | 215 allocator->FinalizeHistogram(histogram_ref, histogram == my_histogram); |
| 212 histogram == tentative_histogram); | |
| 213 } | 216 } |
| 214 } | 217 } |
| 215 | 218 |
| 216 DCHECK_EQ(histogram_type_, histogram->GetHistogramType()); | 219 DCHECK_EQ(histogram_type_, histogram->GetHistogramType()); |
| 217 if (bucket_count_ != 0 && | 220 if (bucket_count_ != 0 && |
| 218 !histogram->HasConstructionArguments(minimum_, maximum_, bucket_count_)) { | 221 !histogram->HasConstructionArguments(minimum_, maximum_, bucket_count_)) { |
| 219 // The construction arguments do not match the existing histogram. This can | 222 // The construction arguments do not match the existing histogram. This can |
| 220 // come about if an extension updates in the middle of a chrome run and has | 223 // come about if an extension updates in the middle of a chrome run and has |
| 221 // changed one of them, or simply by bad code within Chrome itself. We | 224 // changed one of them, or simply by bad code within Chrome itself. We |
| 222 // return NULL here with the expectation that bad code in Chrome will crash | 225 // return NULL here with the expectation that bad code in Chrome will crash |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 | 263 |
| 261 HistogramBase* Histogram::FactoryTimeGet(const char* name, | 264 HistogramBase* Histogram::FactoryTimeGet(const char* name, |
| 262 TimeDelta minimum, | 265 TimeDelta minimum, |
| 263 TimeDelta maximum, | 266 TimeDelta maximum, |
| 264 uint32_t bucket_count, | 267 uint32_t bucket_count, |
| 265 int32_t flags) { | 268 int32_t flags) { |
| 266 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, | 269 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
| 267 flags); | 270 flags); |
| 268 } | 271 } |
| 269 | 272 |
| 270 HistogramBase* Histogram::PersistentGet( | 273 scoped_ptr<HistogramBase> Histogram::PersistentCreate( |
| 271 const std::string& name, | 274 const std::string& name, |
| 272 Sample minimum, | 275 Sample minimum, |
| 273 Sample maximum, | 276 Sample maximum, |
| 274 const BucketRanges* ranges, | 277 const BucketRanges* ranges, |
| 275 HistogramBase::AtomicCount* counts, | 278 HistogramBase::AtomicCount* counts, |
| 276 HistogramBase::AtomicCount* logged_counts, | 279 HistogramBase::AtomicCount* logged_counts, |
| 277 uint32_t counts_size, | 280 uint32_t counts_size, |
| 278 HistogramSamples::Metadata* meta, | 281 HistogramSamples::Metadata* meta, |
| 279 HistogramSamples::Metadata* logged_meta) { | 282 HistogramSamples::Metadata* logged_meta) { |
| 280 return new Histogram(name, minimum, maximum, ranges, counts, logged_counts, | 283 return make_scoped_ptr(new Histogram( |
| 281 counts_size, meta, logged_meta); | 284 name, minimum, maximum, ranges, counts, logged_counts, counts_size, |
| 285 meta, logged_meta)); | |
| 282 } | 286 } |
| 283 | 287 |
| 284 // Calculate what range of values are held in each bucket. | 288 // Calculate what range of values are held in each bucket. |
| 285 // We have to be careful that we don't pick a ratio between starting points in | 289 // We have to be careful that we don't pick a ratio between starting points in |
| 286 // consecutive buckets that is sooo small, that the integer bounds are the same | 290 // consecutive buckets that is sooo small, that the integer bounds are the same |
| 287 // (effectively making one bucket get no values). We need to avoid: | 291 // (effectively making one bucket get no values). We need to avoid: |
| 288 // ranges(i) == ranges(i + 1) | 292 // ranges(i) == ranges(i + 1) |
| 289 // To avoid that, we just do a fine-grained bucket width as far as we need to | 293 // To avoid that, we just do a fine-grained bucket width as far as we need to |
| 290 // until we get a ratio that moves us along at least 2 units at a time. From | 294 // until we get a ratio that moves us along at least 2 units at a time. From |
| 291 // that bucket onward we do use the exponential growth of buckets. | 295 // that bucket onward we do use the exponential growth of buckets. |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 descriptions_ = descriptions; | 729 descriptions_ = descriptions; |
| 726 } | 730 } |
| 727 | 731 |
| 728 protected: | 732 protected: |
| 729 BucketRanges* CreateRanges() override { | 733 BucketRanges* CreateRanges() override { |
| 730 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); | 734 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1); |
| 731 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); | 735 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges); |
| 732 return ranges; | 736 return ranges; |
| 733 } | 737 } |
| 734 | 738 |
| 735 HistogramBase* HeapAlloc(const BucketRanges* ranges) override { | 739 scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) override { |
| 736 return new LinearHistogram(name_, minimum_, maximum_, ranges); | 740 return make_scoped_ptr( |
| 741 new LinearHistogram(name_, minimum_, maximum_, ranges)); | |
| 737 } | 742 } |
| 738 | 743 |
| 739 void FillHistogram(HistogramBase* base_histogram) override { | 744 void FillHistogram(HistogramBase* base_histogram) override { |
| 740 Histogram::Factory::FillHistogram(base_histogram); | 745 Histogram::Factory::FillHistogram(base_histogram); |
| 741 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); | 746 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram); |
| 742 // Set range descriptions. | 747 // Set range descriptions. |
| 743 if (descriptions_) { | 748 if (descriptions_) { |
| 744 for (int i = 0; descriptions_[i].description; ++i) { | 749 for (int i = 0; descriptions_[i].description; ++i) { |
| 745 histogram->bucket_description_[descriptions_[i].sample] = | 750 histogram->bucket_description_[descriptions_[i].sample] = |
| 746 descriptions_[i].description; | 751 descriptions_[i].description; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 | 790 |
| 786 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, | 791 HistogramBase* LinearHistogram::FactoryTimeGet(const char* name, |
| 787 TimeDelta minimum, | 792 TimeDelta minimum, |
| 788 TimeDelta maximum, | 793 TimeDelta maximum, |
| 789 uint32_t bucket_count, | 794 uint32_t bucket_count, |
| 790 int32_t flags) { | 795 int32_t flags) { |
| 791 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, | 796 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count, |
| 792 flags); | 797 flags); |
| 793 } | 798 } |
| 794 | 799 |
| 795 HistogramBase* LinearHistogram::PersistentGet( | 800 scoped_ptr<HistogramBase> LinearHistogram::PersistentCreate( |
| 796 const std::string& name, | 801 const std::string& name, |
| 797 Sample minimum, | 802 Sample minimum, |
| 798 Sample maximum, | 803 Sample maximum, |
| 799 const BucketRanges* ranges, | 804 const BucketRanges* ranges, |
| 800 HistogramBase::AtomicCount* counts, | 805 HistogramBase::AtomicCount* counts, |
| 801 HistogramBase::AtomicCount* logged_counts, | 806 HistogramBase::AtomicCount* logged_counts, |
| 802 uint32_t counts_size, | 807 uint32_t counts_size, |
| 803 HistogramSamples::Metadata* meta, | 808 HistogramSamples::Metadata* meta, |
| 804 HistogramSamples::Metadata* logged_meta) { | 809 HistogramSamples::Metadata* logged_meta) { |
| 805 return new LinearHistogram(name, minimum, maximum, ranges, counts, | 810 return make_scoped_ptr(new LinearHistogram( |
| 806 logged_counts, counts_size, meta, logged_meta); | 811 name, minimum, maximum, ranges, counts, logged_counts, counts_size, |
| 812 meta, logged_meta)); | |
| 807 } | 813 } |
| 808 | 814 |
| 809 HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( | 815 HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( |
| 810 const std::string& name, | 816 const std::string& name, |
| 811 Sample minimum, | 817 Sample minimum, |
| 812 Sample maximum, | 818 Sample maximum, |
| 813 uint32_t bucket_count, | 819 uint32_t bucket_count, |
| 814 int32_t flags, | 820 int32_t flags, |
| 815 const DescriptionPair descriptions[]) { | 821 const DescriptionPair descriptions[]) { |
| 816 bool valid_arguments = Histogram::InspectConstructionArguments( | 822 bool valid_arguments = Histogram::InspectConstructionArguments( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 Factory(const std::string& name, int32_t flags) | 920 Factory(const std::string& name, int32_t flags) |
| 915 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {} | 921 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {} |
| 916 | 922 |
| 917 protected: | 923 protected: |
| 918 BucketRanges* CreateRanges() override { | 924 BucketRanges* CreateRanges() override { |
| 919 BucketRanges* ranges = new BucketRanges(3 + 1); | 925 BucketRanges* ranges = new BucketRanges(3 + 1); |
| 920 LinearHistogram::InitializeBucketRanges(1, 2, ranges); | 926 LinearHistogram::InitializeBucketRanges(1, 2, ranges); |
| 921 return ranges; | 927 return ranges; |
| 922 } | 928 } |
| 923 | 929 |
| 924 HistogramBase* HeapAlloc(const BucketRanges* ranges) override { | 930 scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) override { |
| 925 return new BooleanHistogram(name_, ranges); | 931 return make_scoped_ptr(new BooleanHistogram(name_, ranges)); |
| 926 } | 932 } |
| 927 | 933 |
| 928 private: | 934 private: |
| 929 DISALLOW_COPY_AND_ASSIGN(Factory); | 935 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 930 }; | 936 }; |
| 931 | 937 |
| 932 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, | 938 HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, |
| 933 int32_t flags) { | 939 int32_t flags) { |
| 934 return Factory(name, flags).Build(); | 940 return Factory(name, flags).Build(); |
| 935 } | 941 } |
| 936 | 942 |
| 937 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { | 943 HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { |
| 938 return FactoryGet(std::string(name), flags); | 944 return FactoryGet(std::string(name), flags); |
| 939 } | 945 } |
| 940 | 946 |
| 941 HistogramBase* BooleanHistogram::PersistentGet( | 947 scoped_ptr<HistogramBase> BooleanHistogram::PersistentCreate( |
| 942 const std::string& name, | 948 const std::string& name, |
| 943 const BucketRanges* ranges, | 949 const BucketRanges* ranges, |
| 944 HistogramBase::AtomicCount* counts, | 950 HistogramBase::AtomicCount* counts, |
| 945 HistogramBase::AtomicCount* logged_counts, | 951 HistogramBase::AtomicCount* logged_counts, |
| 946 HistogramSamples::Metadata* meta, | 952 HistogramSamples::Metadata* meta, |
| 947 HistogramSamples::Metadata* logged_meta) { | 953 HistogramSamples::Metadata* logged_meta) { |
| 948 return new BooleanHistogram(name, ranges, counts, logged_counts, meta, | 954 return make_scoped_ptr(new BooleanHistogram( |
| 949 logged_meta); | 955 name, ranges, counts, logged_counts, meta, logged_meta)); |
| 950 } | 956 } |
| 951 | 957 |
| 952 HistogramType BooleanHistogram::GetHistogramType() const { | 958 HistogramType BooleanHistogram::GetHistogramType() const { |
| 953 return BOOLEAN_HISTOGRAM; | 959 return BOOLEAN_HISTOGRAM; |
| 954 } | 960 } |
| 955 | 961 |
| 956 BooleanHistogram::BooleanHistogram(const std::string& name, | 962 BooleanHistogram::BooleanHistogram(const std::string& name, |
| 957 const BucketRanges* ranges) | 963 const BucketRanges* ranges) |
| 958 : LinearHistogram(name, 1, 2, ranges) {} | 964 : LinearHistogram(name, 1, 2, ranges) {} |
| 959 | 965 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); | 1017 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); |
| 1012 | 1018 |
| 1013 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 1019 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
| 1014 for (uint32_t i = 0; i < ranges.size(); i++) { | 1020 for (uint32_t i = 0; i < ranges.size(); i++) { |
| 1015 bucket_ranges->set_range(i, ranges[i]); | 1021 bucket_ranges->set_range(i, ranges[i]); |
| 1016 } | 1022 } |
| 1017 bucket_ranges->ResetChecksum(); | 1023 bucket_ranges->ResetChecksum(); |
| 1018 return bucket_ranges; | 1024 return bucket_ranges; |
| 1019 } | 1025 } |
| 1020 | 1026 |
| 1021 HistogramBase* HeapAlloc(const BucketRanges* ranges) override { | 1027 scoped_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) override { |
| 1022 return new CustomHistogram(name_, ranges); | 1028 return make_scoped_ptr(new CustomHistogram(name_, ranges)); |
| 1023 } | 1029 } |
| 1024 | 1030 |
| 1025 private: | 1031 private: |
| 1026 const std::vector<Sample>* custom_ranges_; | 1032 const std::vector<Sample>* custom_ranges_; |
| 1027 | 1033 |
| 1028 DISALLOW_COPY_AND_ASSIGN(Factory); | 1034 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 1029 }; | 1035 }; |
| 1030 | 1036 |
| 1031 HistogramBase* CustomHistogram::FactoryGet( | 1037 HistogramBase* CustomHistogram::FactoryGet( |
| 1032 const std::string& name, | 1038 const std::string& name, |
| 1033 const std::vector<Sample>& custom_ranges, | 1039 const std::vector<Sample>& custom_ranges, |
| 1034 int32_t flags) { | 1040 int32_t flags) { |
| 1035 CHECK(ValidateCustomRanges(custom_ranges)); | 1041 CHECK(ValidateCustomRanges(custom_ranges)); |
| 1036 | 1042 |
| 1037 return Factory(name, &custom_ranges, flags).Build(); | 1043 return Factory(name, &custom_ranges, flags).Build(); |
| 1038 } | 1044 } |
| 1039 | 1045 |
| 1040 HistogramBase* CustomHistogram::FactoryGet( | 1046 HistogramBase* CustomHistogram::FactoryGet( |
| 1041 const char* name, | 1047 const char* name, |
| 1042 const std::vector<Sample>& custom_ranges, | 1048 const std::vector<Sample>& custom_ranges, |
| 1043 int32_t flags) { | 1049 int32_t flags) { |
| 1044 return FactoryGet(std::string(name), custom_ranges, flags); | 1050 return FactoryGet(std::string(name), custom_ranges, flags); |
| 1045 } | 1051 } |
| 1046 | 1052 |
| 1047 HistogramBase* CustomHistogram::PersistentGet( | 1053 scoped_ptr<HistogramBase> CustomHistogram::PersistentCreate( |
| 1048 const std::string& name, | 1054 const std::string& name, |
| 1049 const BucketRanges* ranges, | 1055 const BucketRanges* ranges, |
| 1050 HistogramBase::AtomicCount* counts, | 1056 HistogramBase::AtomicCount* counts, |
| 1051 HistogramBase::AtomicCount* logged_counts, | 1057 HistogramBase::AtomicCount* logged_counts, |
| 1052 uint32_t counts_size, | 1058 uint32_t counts_size, |
| 1053 HistogramSamples::Metadata* meta, | 1059 HistogramSamples::Metadata* meta, |
| 1054 HistogramSamples::Metadata* logged_meta) { | 1060 HistogramSamples::Metadata* logged_meta) { |
| 1055 return new CustomHistogram(name, ranges, counts, logged_counts, counts_size, | 1061 return make_scoped_ptr(new CustomHistogram( |
| 1056 meta, logged_meta); | 1062 name, ranges, counts, logged_counts, counts_size, meta, logged_meta)); |
| 1057 } | 1063 } |
| 1058 | 1064 |
| 1059 HistogramType CustomHistogram::GetHistogramType() const { | 1065 HistogramType CustomHistogram::GetHistogramType() const { |
| 1060 return CUSTOM_HISTOGRAM; | 1066 return CUSTOM_HISTOGRAM; |
| 1061 } | 1067 } |
| 1062 | 1068 |
| 1063 // static | 1069 // static |
| 1064 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( | 1070 std::vector<Sample> CustomHistogram::ArrayToCustomRanges( |
| 1065 const Sample* values, uint32_t num_values) { | 1071 const Sample* values, uint32_t num_values) { |
| 1066 std::vector<Sample> all_values; | 1072 std::vector<Sample> all_values; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1155 Sample sample = custom_ranges[i]; | 1161 Sample sample = custom_ranges[i]; |
| 1156 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1162 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
| 1157 return false; | 1163 return false; |
| 1158 if (sample != 0) | 1164 if (sample != 0) |
| 1159 has_valid_range = true; | 1165 has_valid_range = true; |
| 1160 } | 1166 } |
| 1161 return has_valid_range; | 1167 return has_valid_range; |
| 1162 } | 1168 } |
| 1163 | 1169 |
| 1164 } // namespace base | 1170 } // namespace base |
| OLD | NEW |