| 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 | 8 |
| 9 // It supports calls to accumulate either time intervals (which are processed | 9 // It supports calls to accumulate either time intervals (which are processed |
| 10 // as integral number of milliseconds), or arbitrary integral units. | 10 // as integral number of milliseconds), or arbitrary integral units. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // and relatively fast, set of counters. To avoid races at shutdown, the static | 63 // and relatively fast, set of counters. To avoid races at shutdown, the static |
| 64 // pointer is NOT deleted, and we leak the histograms at process termination. | 64 // pointer is NOT deleted, and we leak the histograms at process termination. |
| 65 | 65 |
| 66 #ifndef BASE_METRICS_HISTOGRAM_H_ | 66 #ifndef BASE_METRICS_HISTOGRAM_H_ |
| 67 #define BASE_METRICS_HISTOGRAM_H_ | 67 #define BASE_METRICS_HISTOGRAM_H_ |
| 68 | 68 |
| 69 #include <stddef.h> | 69 #include <stddef.h> |
| 70 #include <stdint.h> | 70 #include <stdint.h> |
| 71 | 71 |
| 72 #include <map> | 72 #include <map> |
| 73 #include <memory> |
| 73 #include <string> | 74 #include <string> |
| 74 #include <vector> | 75 #include <vector> |
| 75 | 76 |
| 76 #include "base/base_export.h" | 77 #include "base/base_export.h" |
| 77 #include "base/compiler_specific.h" | 78 #include "base/compiler_specific.h" |
| 78 #include "base/gtest_prod_util.h" | 79 #include "base/gtest_prod_util.h" |
| 79 #include "base/logging.h" | 80 #include "base/logging.h" |
| 80 #include "base/macros.h" | 81 #include "base/macros.h" |
| 81 #include "base/memory/scoped_ptr.h" | |
| 82 #include "base/metrics/bucket_ranges.h" | 82 #include "base/metrics/bucket_ranges.h" |
| 83 #include "base/metrics/histogram_base.h" | 83 #include "base/metrics/histogram_base.h" |
| 84 // TODO(asvitkine): Migrate callers to to include this directly and remove this. | 84 // TODO(asvitkine): Migrate callers to to include this directly and remove this. |
| 85 #include "base/metrics/histogram_macros.h" | 85 #include "base/metrics/histogram_macros.h" |
| 86 #include "base/metrics/histogram_samples.h" | 86 #include "base/metrics/histogram_samples.h" |
| 87 #include "base/time/time.h" | 87 #include "base/time/time.h" |
| 88 | 88 |
| 89 namespace base { | 89 namespace base { |
| 90 | 90 |
| 91 class BooleanHistogram; | 91 class BooleanHistogram; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 Sample maximum, | 135 Sample maximum, |
| 136 uint32_t bucket_count, | 136 uint32_t bucket_count, |
| 137 int32_t flags); | 137 int32_t flags); |
| 138 static HistogramBase* FactoryTimeGet(const char* name, | 138 static HistogramBase* FactoryTimeGet(const char* name, |
| 139 base::TimeDelta minimum, | 139 base::TimeDelta minimum, |
| 140 base::TimeDelta maximum, | 140 base::TimeDelta maximum, |
| 141 uint32_t bucket_count, | 141 uint32_t bucket_count, |
| 142 int32_t flags); | 142 int32_t flags); |
| 143 | 143 |
| 144 // Create a histogram using data in persistent storage. | 144 // Create a histogram using data in persistent storage. |
| 145 static scoped_ptr<HistogramBase> PersistentCreate( | 145 static std::unique_ptr<HistogramBase> PersistentCreate( |
| 146 const std::string& name, | 146 const std::string& name, |
| 147 Sample minimum, | 147 Sample minimum, |
| 148 Sample maximum, | 148 Sample maximum, |
| 149 const BucketRanges* ranges, | 149 const BucketRanges* ranges, |
| 150 HistogramBase::AtomicCount* counts, | 150 HistogramBase::AtomicCount* counts, |
| 151 HistogramBase::AtomicCount* logged_counts, | 151 HistogramBase::AtomicCount* logged_counts, |
| 152 uint32_t counts_size, | 152 uint32_t counts_size, |
| 153 HistogramSamples::Metadata* meta, | 153 HistogramSamples::Metadata* meta, |
| 154 HistogramSamples::Metadata* logged_meta); | 154 HistogramSamples::Metadata* logged_meta); |
| 155 | 155 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 uint32_t* bucket_count); | 195 uint32_t* bucket_count); |
| 196 | 196 |
| 197 // HistogramBase implementation: | 197 // HistogramBase implementation: |
| 198 uint64_t name_hash() const override; | 198 uint64_t name_hash() const override; |
| 199 HistogramType GetHistogramType() const override; | 199 HistogramType GetHistogramType() const override; |
| 200 bool HasConstructionArguments(Sample expected_minimum, | 200 bool HasConstructionArguments(Sample expected_minimum, |
| 201 Sample expected_maximum, | 201 Sample expected_maximum, |
| 202 uint32_t expected_bucket_count) const override; | 202 uint32_t expected_bucket_count) const override; |
| 203 void Add(Sample value) override; | 203 void Add(Sample value) override; |
| 204 void AddCount(Sample value, int count) override; | 204 void AddCount(Sample value, int count) override; |
| 205 scoped_ptr<HistogramSamples> SnapshotSamples() const override; | 205 std::unique_ptr<HistogramSamples> SnapshotSamples() const override; |
| 206 scoped_ptr<HistogramSamples> SnapshotDelta() override; | 206 std::unique_ptr<HistogramSamples> SnapshotDelta() override; |
| 207 void AddSamples(const HistogramSamples& samples) override; | 207 void AddSamples(const HistogramSamples& samples) override; |
| 208 bool AddSamplesFromPickle(base::PickleIterator* iter) override; | 208 bool AddSamplesFromPickle(base::PickleIterator* iter) override; |
| 209 void WriteHTMLGraph(std::string* output) const override; | 209 void WriteHTMLGraph(std::string* output) const override; |
| 210 void WriteAscii(std::string* output) const override; | 210 void WriteAscii(std::string* output) const override; |
| 211 | 211 |
| 212 protected: | 212 protected: |
| 213 // This class, defined entirely within the .cc file, contains all the | 213 // This class, defined entirely within the .cc file, contains all the |
| 214 // common logic for building a Histogram and can be overridden by more | 214 // common logic for building a Histogram and can be overridden by more |
| 215 // specific types to alter details of how the creation is done. It is | 215 // specific types to alter details of how the creation is done. It is |
| 216 // defined as an embedded class (rather than an anonymous one) so it | 216 // defined as an embedded class (rather than an anonymous one) so it |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); | 261 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); |
| 262 | 262 |
| 263 friend class StatisticsRecorder; // To allow it to delete duplicates. | 263 friend class StatisticsRecorder; // To allow it to delete duplicates. |
| 264 friend class StatisticsRecorderTest; | 264 friend class StatisticsRecorderTest; |
| 265 | 265 |
| 266 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( | 266 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( |
| 267 base::PickleIterator* iter); | 267 base::PickleIterator* iter); |
| 268 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 268 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
| 269 | 269 |
| 270 // Implementation of SnapshotSamples function. | 270 // Implementation of SnapshotSamples function. |
| 271 scoped_ptr<SampleVector> SnapshotSampleVector() const; | 271 std::unique_ptr<SampleVector> SnapshotSampleVector() const; |
| 272 | 272 |
| 273 //---------------------------------------------------------------------------- | 273 //---------------------------------------------------------------------------- |
| 274 // Helpers for emitting Ascii graphic. Each method appends data to output. | 274 // Helpers for emitting Ascii graphic. Each method appends data to output. |
| 275 | 275 |
| 276 void WriteAsciiImpl(bool graph_it, | 276 void WriteAsciiImpl(bool graph_it, |
| 277 const std::string& newline, | 277 const std::string& newline, |
| 278 std::string* output) const; | 278 std::string* output) const; |
| 279 | 279 |
| 280 // Find out how large (graphically) the largest bucket will appear to be. | 280 // Find out how large (graphically) the largest bucket will appear to be. |
| 281 double GetPeakBucketSize(const SampleVector& samples) const; | 281 double GetPeakBucketSize(const SampleVector& samples) const; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 301 ListValue* buckets) const override; | 301 ListValue* buckets) const override; |
| 302 | 302 |
| 303 // Does not own this object. Should get from StatisticsRecorder. | 303 // Does not own this object. Should get from StatisticsRecorder. |
| 304 const BucketRanges* bucket_ranges_; | 304 const BucketRanges* bucket_ranges_; |
| 305 | 305 |
| 306 Sample declared_min_; // Less than this goes into the first bucket. | 306 Sample declared_min_; // Less than this goes into the first bucket. |
| 307 Sample declared_max_; // Over this goes into the last bucket. | 307 Sample declared_max_; // Over this goes into the last bucket. |
| 308 | 308 |
| 309 // Finally, provide the state that changes with the addition of each new | 309 // Finally, provide the state that changes with the addition of each new |
| 310 // sample. | 310 // sample. |
| 311 scoped_ptr<SampleVector> samples_; | 311 std::unique_ptr<SampleVector> samples_; |
| 312 | 312 |
| 313 // Also keep a previous uploaded state for calculating deltas. | 313 // Also keep a previous uploaded state for calculating deltas. |
| 314 scoped_ptr<HistogramSamples> logged_samples_; | 314 std::unique_ptr<HistogramSamples> logged_samples_; |
| 315 | 315 |
| 316 DISALLOW_COPY_AND_ASSIGN(Histogram); | 316 DISALLOW_COPY_AND_ASSIGN(Histogram); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 //------------------------------------------------------------------------------ | 319 //------------------------------------------------------------------------------ |
| 320 | 320 |
| 321 // LinearHistogram is a more traditional histogram, with evenly spaced | 321 // LinearHistogram is a more traditional histogram, with evenly spaced |
| 322 // buckets. | 322 // buckets. |
| 323 class BASE_EXPORT LinearHistogram : public Histogram { | 323 class BASE_EXPORT LinearHistogram : public Histogram { |
| 324 public: | 324 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 345 Sample maximum, | 345 Sample maximum, |
| 346 uint32_t bucket_count, | 346 uint32_t bucket_count, |
| 347 int32_t flags); | 347 int32_t flags); |
| 348 static HistogramBase* FactoryTimeGet(const char* name, | 348 static HistogramBase* FactoryTimeGet(const char* name, |
| 349 TimeDelta minimum, | 349 TimeDelta minimum, |
| 350 TimeDelta maximum, | 350 TimeDelta maximum, |
| 351 uint32_t bucket_count, | 351 uint32_t bucket_count, |
| 352 int32_t flags); | 352 int32_t flags); |
| 353 | 353 |
| 354 // Create a histogram using data in persistent storage. | 354 // Create a histogram using data in persistent storage. |
| 355 static scoped_ptr<HistogramBase> PersistentCreate( | 355 static std::unique_ptr<HistogramBase> PersistentCreate( |
| 356 const std::string& name, | 356 const std::string& name, |
| 357 Sample minimum, | 357 Sample minimum, |
| 358 Sample maximum, | 358 Sample maximum, |
| 359 const BucketRanges* ranges, | 359 const BucketRanges* ranges, |
| 360 HistogramBase::AtomicCount* counts, | 360 HistogramBase::AtomicCount* counts, |
| 361 HistogramBase::AtomicCount* logged_counts, | 361 HistogramBase::AtomicCount* logged_counts, |
| 362 uint32_t counts_size, | 362 uint32_t counts_size, |
| 363 HistogramSamples::Metadata* meta, | 363 HistogramSamples::Metadata* meta, |
| 364 HistogramSamples::Metadata* logged_meta); | 364 HistogramSamples::Metadata* logged_meta); |
| 365 | 365 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 436 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
| 437 public: | 437 public: |
| 438 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); | 438 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); |
| 439 | 439 |
| 440 // Overload of the above function that takes a const char* |name| param, | 440 // Overload of the above function that takes a const char* |name| param, |
| 441 // to avoid code bloat from the std::string constructor being inlined into | 441 // to avoid code bloat from the std::string constructor being inlined into |
| 442 // call sites. | 442 // call sites. |
| 443 static HistogramBase* FactoryGet(const char* name, int32_t flags); | 443 static HistogramBase* FactoryGet(const char* name, int32_t flags); |
| 444 | 444 |
| 445 // Create a histogram using data in persistent storage. | 445 // Create a histogram using data in persistent storage. |
| 446 static scoped_ptr<HistogramBase> PersistentCreate( | 446 static std::unique_ptr<HistogramBase> PersistentCreate( |
| 447 const std::string& name, | 447 const std::string& name, |
| 448 const BucketRanges* ranges, | 448 const BucketRanges* ranges, |
| 449 HistogramBase::AtomicCount* counts, | 449 HistogramBase::AtomicCount* counts, |
| 450 HistogramBase::AtomicCount* logged_counts, | 450 HistogramBase::AtomicCount* logged_counts, |
| 451 HistogramSamples::Metadata* meta, | 451 HistogramSamples::Metadata* meta, |
| 452 HistogramSamples::Metadata* logged_meta); | 452 HistogramSamples::Metadata* logged_meta); |
| 453 | 453 |
| 454 HistogramType GetHistogramType() const override; | 454 HistogramType GetHistogramType() const override; |
| 455 | 455 |
| 456 protected: | 456 protected: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 486 int32_t flags); | 486 int32_t flags); |
| 487 | 487 |
| 488 // Overload of the above function that takes a const char* |name| param, | 488 // Overload of the above function that takes a const char* |name| param, |
| 489 // to avoid code bloat from the std::string constructor being inlined into | 489 // to avoid code bloat from the std::string constructor being inlined into |
| 490 // call sites. | 490 // call sites. |
| 491 static HistogramBase* FactoryGet(const char* name, | 491 static HistogramBase* FactoryGet(const char* name, |
| 492 const std::vector<Sample>& custom_ranges, | 492 const std::vector<Sample>& custom_ranges, |
| 493 int32_t flags); | 493 int32_t flags); |
| 494 | 494 |
| 495 // Create a histogram using data in persistent storage. | 495 // Create a histogram using data in persistent storage. |
| 496 static scoped_ptr<HistogramBase> PersistentCreate( | 496 static std::unique_ptr<HistogramBase> PersistentCreate( |
| 497 const std::string& name, | 497 const std::string& name, |
| 498 const BucketRanges* ranges, | 498 const BucketRanges* ranges, |
| 499 HistogramBase::AtomicCount* counts, | 499 HistogramBase::AtomicCount* counts, |
| 500 HistogramBase::AtomicCount* logged_counts, | 500 HistogramBase::AtomicCount* logged_counts, |
| 501 uint32_t counts_size, | 501 uint32_t counts_size, |
| 502 HistogramSamples::Metadata* meta, | 502 HistogramSamples::Metadata* meta, |
| 503 HistogramSamples::Metadata* logged_meta); | 503 HistogramSamples::Metadata* logged_meta); |
| 504 | 504 |
| 505 // Overridden from Histogram: | 505 // Overridden from Histogram: |
| 506 HistogramType GetHistogramType() const override; | 506 HistogramType GetHistogramType() const override; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 538 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
| 539 | 539 |
| 540 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 540 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
| 541 | 541 |
| 542 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 542 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| 543 }; | 543 }; |
| 544 | 544 |
| 545 } // namespace base | 545 } // namespace base |
| 546 | 546 |
| 547 #endif // BASE_METRICS_HISTOGRAM_H_ | 547 #endif // BASE_METRICS_HISTOGRAM_H_ |
| OLD | NEW |