| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 27 matching lines...) Expand all Loading... |
| 38 // pointer is NOT deleted, and we leak the histograms at process termination. | 38 // pointer is NOT deleted, and we leak the histograms at process termination. |
| 39 | 39 |
| 40 #ifndef BASE_METRICS_HISTOGRAM_H_ | 40 #ifndef BASE_METRICS_HISTOGRAM_H_ |
| 41 #define BASE_METRICS_HISTOGRAM_H_ | 41 #define BASE_METRICS_HISTOGRAM_H_ |
| 42 #pragma once | 42 #pragma once |
| 43 | 43 |
| 44 #include <map> | 44 #include <map> |
| 45 #include <string> | 45 #include <string> |
| 46 #include <vector> | 46 #include <vector> |
| 47 | 47 |
| 48 #include "base/base_api.h" | 48 #include "base/base_export.h" |
| 49 #include "base/gtest_prod_util.h" | 49 #include "base/gtest_prod_util.h" |
| 50 #include "base/logging.h" | 50 #include "base/logging.h" |
| 51 #include "base/time.h" | 51 #include "base/time.h" |
| 52 | 52 |
| 53 class Pickle; | 53 class Pickle; |
| 54 | 54 |
| 55 namespace base { | 55 namespace base { |
| 56 | 56 |
| 57 class Lock; | 57 class Lock; |
| 58 | 58 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 counter->Add(sample); \ | 259 counter->Add(sample); \ |
| 260 } while (0) | 260 } while (0) |
| 261 | 261 |
| 262 //------------------------------------------------------------------------------ | 262 //------------------------------------------------------------------------------ |
| 263 | 263 |
| 264 class BooleanHistogram; | 264 class BooleanHistogram; |
| 265 class CustomHistogram; | 265 class CustomHistogram; |
| 266 class Histogram; | 266 class Histogram; |
| 267 class LinearHistogram; | 267 class LinearHistogram; |
| 268 | 268 |
| 269 class BASE_API Histogram { | 269 class BASE_EXPORT Histogram { |
| 270 public: | 270 public: |
| 271 typedef int Sample; // Used for samples (and ranges of samples). | 271 typedef int Sample; // Used for samples (and ranges of samples). |
| 272 typedef int Count; // Used to count samples in a bucket. | 272 typedef int Count; // Used to count samples in a bucket. |
| 273 static const Sample kSampleType_MAX = INT_MAX; | 273 static const Sample kSampleType_MAX = INT_MAX; |
| 274 // Initialize maximum number of buckets in histograms as 16,384. | 274 // Initialize maximum number of buckets in histograms as 16,384. |
| 275 static const size_t kBucketCount_MAX; | 275 static const size_t kBucketCount_MAX; |
| 276 | 276 |
| 277 typedef std::vector<Count> Counts; | 277 typedef std::vector<Count> Counts; |
| 278 typedef std::vector<Sample> Ranges; | 278 typedef std::vector<Sample> Ranges; |
| 279 | 279 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 struct DescriptionPair { | 320 struct DescriptionPair { |
| 321 Sample sample; | 321 Sample sample; |
| 322 const char* description; // Null means end of a list of pairs. | 322 const char* description; // Null means end of a list of pairs. |
| 323 }; | 323 }; |
| 324 | 324 |
| 325 //---------------------------------------------------------------------------- | 325 //---------------------------------------------------------------------------- |
| 326 // Statistic values, developed over the life of the histogram. | 326 // Statistic values, developed over the life of the histogram. |
| 327 | 327 |
| 328 class BASE_API SampleSet { | 328 class BASE_EXPORT SampleSet { |
| 329 public: | 329 public: |
| 330 explicit SampleSet(); | 330 explicit SampleSet(); |
| 331 ~SampleSet(); | 331 ~SampleSet(); |
| 332 | 332 |
| 333 // Adjust size of counts_ for use with given histogram. | 333 // Adjust size of counts_ for use with given histogram. |
| 334 void Resize(const Histogram& histogram); | 334 void Resize(const Histogram& histogram); |
| 335 void CheckSize(const Histogram& histogram) const; | 335 void CheckSize(const Histogram& histogram) const; |
| 336 | 336 |
| 337 // Accessor for histogram to make routine additions. | 337 // Accessor for histogram to make routine additions. |
| 338 void Accumulate(Sample value, Count count, size_t index); | 338 void Accumulate(Sample value, Count count, size_t index); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // sample. | 577 // sample. |
| 578 SampleSet sample_; | 578 SampleSet sample_; |
| 579 | 579 |
| 580 DISALLOW_COPY_AND_ASSIGN(Histogram); | 580 DISALLOW_COPY_AND_ASSIGN(Histogram); |
| 581 }; | 581 }; |
| 582 | 582 |
| 583 //------------------------------------------------------------------------------ | 583 //------------------------------------------------------------------------------ |
| 584 | 584 |
| 585 // LinearHistogram is a more traditional histogram, with evenly spaced | 585 // LinearHistogram is a more traditional histogram, with evenly spaced |
| 586 // buckets. | 586 // buckets. |
| 587 class BASE_API LinearHistogram : public Histogram { | 587 class BASE_EXPORT LinearHistogram : public Histogram { |
| 588 public: | 588 public: |
| 589 virtual ~LinearHistogram(); | 589 virtual ~LinearHistogram(); |
| 590 | 590 |
| 591 /* minimum should start from 1. 0 is as minimum is invalid. 0 is an implicit | 591 /* minimum should start from 1. 0 is as minimum is invalid. 0 is an implicit |
| 592 default underflow bucket. */ | 592 default underflow bucket. */ |
| 593 static Histogram* FactoryGet(const std::string& name, | 593 static Histogram* FactoryGet(const std::string& name, |
| 594 Sample minimum, | 594 Sample minimum, |
| 595 Sample maximum, | 595 Sample maximum, |
| 596 size_t bucket_count, | 596 size_t bucket_count, |
| 597 Flags flags); | 597 Flags flags); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 // to provide a description. | 633 // to provide a description. |
| 634 typedef std::map<Sample, std::string> BucketDescriptionMap; | 634 typedef std::map<Sample, std::string> BucketDescriptionMap; |
| 635 BucketDescriptionMap bucket_description_; | 635 BucketDescriptionMap bucket_description_; |
| 636 | 636 |
| 637 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); | 637 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); |
| 638 }; | 638 }; |
| 639 | 639 |
| 640 //------------------------------------------------------------------------------ | 640 //------------------------------------------------------------------------------ |
| 641 | 641 |
| 642 // BooleanHistogram is a histogram for booleans. | 642 // BooleanHistogram is a histogram for booleans. |
| 643 class BASE_API BooleanHistogram : public LinearHistogram { | 643 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
| 644 public: | 644 public: |
| 645 static Histogram* FactoryGet(const std::string& name, Flags flags); | 645 static Histogram* FactoryGet(const std::string& name, Flags flags); |
| 646 | 646 |
| 647 virtual ClassType histogram_type() const; | 647 virtual ClassType histogram_type() const; |
| 648 | 648 |
| 649 virtual void AddBoolean(bool value); | 649 virtual void AddBoolean(bool value); |
| 650 | 650 |
| 651 private: | 651 private: |
| 652 explicit BooleanHistogram(const std::string& name); | 652 explicit BooleanHistogram(const std::string& name); |
| 653 | 653 |
| 654 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 654 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
| 655 }; | 655 }; |
| 656 | 656 |
| 657 //------------------------------------------------------------------------------ | 657 //------------------------------------------------------------------------------ |
| 658 | 658 |
| 659 // CustomHistogram is a histogram for a set of custom integers. | 659 // CustomHistogram is a histogram for a set of custom integers. |
| 660 class BASE_API CustomHistogram : public Histogram { | 660 class BASE_EXPORT CustomHistogram : public Histogram { |
| 661 public: | 661 public: |
| 662 | 662 |
| 663 static Histogram* FactoryGet(const std::string& name, | 663 static Histogram* FactoryGet(const std::string& name, |
| 664 const std::vector<Sample>& custom_ranges, | 664 const std::vector<Sample>& custom_ranges, |
| 665 Flags flags); | 665 Flags flags); |
| 666 | 666 |
| 667 // Overridden from Histogram: | 667 // Overridden from Histogram: |
| 668 virtual ClassType histogram_type() const; | 668 virtual ClassType histogram_type() const; |
| 669 | 669 |
| 670 // Helper method for transforming an array of valid enumeration values | 670 // Helper method for transforming an array of valid enumeration values |
| (...skipping 13 matching lines...) Expand all Loading... |
| 684 virtual double GetBucketSize(Count current, size_t i) const; | 684 virtual double GetBucketSize(Count current, size_t i) const; |
| 685 | 685 |
| 686 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 686 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| 687 }; | 687 }; |
| 688 | 688 |
| 689 //------------------------------------------------------------------------------ | 689 //------------------------------------------------------------------------------ |
| 690 // StatisticsRecorder handles all histograms in the system. It provides a | 690 // StatisticsRecorder handles all histograms in the system. It provides a |
| 691 // general place for histograms to register, and supports a global API for | 691 // general place for histograms to register, and supports a global API for |
| 692 // accessing (i.e., dumping, or graphing) the data in all the histograms. | 692 // accessing (i.e., dumping, or graphing) the data in all the histograms. |
| 693 | 693 |
| 694 class BASE_API StatisticsRecorder { | 694 class BASE_EXPORT StatisticsRecorder { |
| 695 public: | 695 public: |
| 696 typedef std::vector<Histogram*> Histograms; | 696 typedef std::vector<Histogram*> Histograms; |
| 697 | 697 |
| 698 StatisticsRecorder(); | 698 StatisticsRecorder(); |
| 699 | 699 |
| 700 ~StatisticsRecorder(); | 700 ~StatisticsRecorder(); |
| 701 | 701 |
| 702 // Find out if histograms can now be registered into our list. | 702 // Find out if histograms can now be registered into our list. |
| 703 static bool IsActive(); | 703 static bool IsActive(); |
| 704 | 704 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 744 |
| 745 // Dump all known histograms to log. | 745 // Dump all known histograms to log. |
| 746 static bool dump_on_exit_; | 746 static bool dump_on_exit_; |
| 747 | 747 |
| 748 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 748 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 749 }; | 749 }; |
| 750 | 750 |
| 751 } // namespace base | 751 } // namespace base |
| 752 | 752 |
| 753 #endif // BASE_METRICS_HISTOGRAM_H_ | 753 #endif // BASE_METRICS_HISTOGRAM_H_ |
| OLD | NEW |