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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 Sample maximum, | 667 Sample maximum, |
668 size_t bucket_count, | 668 size_t bucket_count, |
669 Flags flags); | 669 Flags flags); |
670 static Histogram* FactoryTimeGet(const std::string& name, | 670 static Histogram* FactoryTimeGet(const std::string& name, |
671 TimeDelta minimum, | 671 TimeDelta minimum, |
672 TimeDelta maximum, | 672 TimeDelta maximum, |
673 size_t bucket_count, | 673 size_t bucket_count, |
674 Flags flags); | 674 Flags flags); |
675 | 675 |
676 // Overridden from Histogram: | 676 // Overridden from Histogram: |
677 virtual ClassType histogram_type() const; | 677 virtual ClassType histogram_type() const OVERRIDE; |
678 | 678 |
679 // Store a list of number/text values for use in rendering the histogram. | 679 // Store a list of number/text values for use in rendering the histogram. |
680 // The last element in the array has a null in its "description" slot. | 680 // The last element in the array has a null in its "description" slot. |
681 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); | 681 virtual void SetRangeDescriptions( |
| 682 const DescriptionPair descriptions[]) OVERRIDE; |
682 | 683 |
683 protected: | 684 protected: |
684 LinearHistogram(const std::string& name, Sample minimum, | 685 LinearHistogram(const std::string& name, Sample minimum, |
685 Sample maximum, size_t bucket_count); | 686 Sample maximum, size_t bucket_count); |
686 | 687 |
687 LinearHistogram(const std::string& name, TimeDelta minimum, | 688 LinearHistogram(const std::string& name, TimeDelta minimum, |
688 TimeDelta maximum, size_t bucket_count); | 689 TimeDelta maximum, size_t bucket_count); |
689 | 690 |
690 // Initialize ranges_ mapping in cached_ranges_. | 691 // Initialize ranges_ mapping in cached_ranges_. |
691 void InitializeBucketRange(); | 692 void InitializeBucketRange(); |
692 virtual double GetBucketSize(Count current, size_t i) const; | 693 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; |
693 | 694 |
694 // If we have a description for a bucket, then return that. Otherwise | 695 // If we have a description for a bucket, then return that. Otherwise |
695 // let parent class provide a (numeric) description. | 696 // let parent class provide a (numeric) description. |
696 virtual const std::string GetAsciiBucketRange(size_t i) const; | 697 virtual const std::string GetAsciiBucketRange(size_t i) const OVERRIDE; |
697 | 698 |
698 // Skip printing of name for numeric range if we have a name (and if this is | 699 // Skip printing of name for numeric range if we have a name (and if this is |
699 // an empty bucket). | 700 // an empty bucket). |
700 virtual bool PrintEmptyBucket(size_t index) const; | 701 virtual bool PrintEmptyBucket(size_t index) const OVERRIDE; |
701 | 702 |
702 private: | 703 private: |
703 // For some ranges, we store a printable description of a bucket range. | 704 // For some ranges, we store a printable description of a bucket range. |
704 // If there is no desciption, then GetAsciiBucketRange() uses parent class | 705 // If there is no desciption, then GetAsciiBucketRange() uses parent class |
705 // to provide a description. | 706 // to provide a description. |
706 typedef std::map<Sample, std::string> BucketDescriptionMap; | 707 typedef std::map<Sample, std::string> BucketDescriptionMap; |
707 BucketDescriptionMap bucket_description_; | 708 BucketDescriptionMap bucket_description_; |
708 | 709 |
709 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); | 710 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); |
710 }; | 711 }; |
711 | 712 |
712 //------------------------------------------------------------------------------ | 713 //------------------------------------------------------------------------------ |
713 | 714 |
714 // BooleanHistogram is a histogram for booleans. | 715 // BooleanHistogram is a histogram for booleans. |
715 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 716 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
716 public: | 717 public: |
717 static Histogram* FactoryGet(const std::string& name, Flags flags); | 718 static Histogram* FactoryGet(const std::string& name, Flags flags); |
718 | 719 |
719 virtual ClassType histogram_type() const; | 720 virtual ClassType histogram_type() const OVERRIDE; |
720 | 721 |
721 virtual void AddBoolean(bool value); | 722 virtual void AddBoolean(bool value) OVERRIDE; |
722 | 723 |
723 private: | 724 private: |
724 explicit BooleanHistogram(const std::string& name); | 725 explicit BooleanHistogram(const std::string& name); |
725 | 726 |
726 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 727 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
727 }; | 728 }; |
728 | 729 |
729 //------------------------------------------------------------------------------ | 730 //------------------------------------------------------------------------------ |
730 | 731 |
731 // CustomHistogram is a histogram for a set of custom integers. | 732 // CustomHistogram is a histogram for a set of custom integers. |
732 class BASE_EXPORT CustomHistogram : public Histogram { | 733 class BASE_EXPORT CustomHistogram : public Histogram { |
733 public: | 734 public: |
734 | 735 |
735 static Histogram* FactoryGet(const std::string& name, | 736 static Histogram* FactoryGet(const std::string& name, |
736 const std::vector<Sample>& custom_ranges, | 737 const std::vector<Sample>& custom_ranges, |
737 Flags flags); | 738 Flags flags); |
738 | 739 |
739 // Overridden from Histogram: | 740 // Overridden from Histogram: |
740 virtual ClassType histogram_type() const; | 741 virtual ClassType histogram_type() const OVERRIDE; |
741 | 742 |
742 // Helper method for transforming an array of valid enumeration values | 743 // Helper method for transforming an array of valid enumeration values |
743 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. | 744 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. |
744 // This function ensures that a guard bucket exists right after any | 745 // This function ensures that a guard bucket exists right after any |
745 // valid sample value (unless the next higher sample is also a valid value), | 746 // valid sample value (unless the next higher sample is also a valid value), |
746 // so that invalid samples never fall into the same bucket as valid samples. | 747 // so that invalid samples never fall into the same bucket as valid samples. |
747 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 748 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
748 size_t num_values); | 749 size_t num_values); |
749 | 750 |
750 // Helper for deserializing CustomHistograms. |*ranges| should already be | 751 // Helper for deserializing CustomHistograms. |*ranges| should already be |
751 // correctly sized before this call. Return true on success. | 752 // correctly sized before this call. Return true on success. |
752 static bool DeserializeRanges(void** iter, const Pickle& pickle, | 753 static bool DeserializeRanges(void** iter, const Pickle& pickle, |
753 std::vector<Histogram::Sample>* ranges); | 754 std::vector<Histogram::Sample>* ranges); |
754 | 755 |
755 | 756 |
756 protected: | 757 protected: |
757 CustomHistogram(const std::string& name, | 758 CustomHistogram(const std::string& name, |
758 const std::vector<Sample>& custom_ranges); | 759 const std::vector<Sample>& custom_ranges); |
759 | 760 |
760 virtual bool SerializeRanges(Pickle* pickle) const OVERRIDE; | 761 virtual bool SerializeRanges(Pickle* pickle) const OVERRIDE; |
761 | 762 |
762 // Initialize ranges_ mapping in cached_ranges_. | 763 // Initialize ranges_ mapping in cached_ranges_. |
763 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); | 764 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); |
764 virtual double GetBucketSize(Count current, size_t i) const; | 765 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; |
765 | 766 |
766 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 767 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
767 }; | 768 }; |
768 | 769 |
769 //------------------------------------------------------------------------------ | 770 //------------------------------------------------------------------------------ |
770 // StatisticsRecorder handles all histograms in the system. It provides a | 771 // StatisticsRecorder handles all histograms in the system. It provides a |
771 // general place for histograms to register, and supports a global API for | 772 // general place for histograms to register, and supports a global API for |
772 // accessing (i.e., dumping, or graphing) the data in all the histograms. | 773 // accessing (i.e., dumping, or graphing) the data in all the histograms. |
773 | 774 |
774 class BASE_EXPORT StatisticsRecorder { | 775 class BASE_EXPORT StatisticsRecorder { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 // of our data, and to quickly see if some other CachedRanges instance is | 885 // of our data, and to quickly see if some other CachedRanges instance is |
885 // possibly Equal() to this instance. | 886 // possibly Equal() to this instance. |
886 uint32 range_checksum_; | 887 uint32 range_checksum_; |
887 | 888 |
888 DISALLOW_COPY_AND_ASSIGN(CachedRanges); | 889 DISALLOW_COPY_AND_ASSIGN(CachedRanges); |
889 }; | 890 }; |
890 | 891 |
891 } // namespace base | 892 } // namespace base |
892 | 893 |
893 #endif // BASE_METRICS_HISTOGRAM_H_ | 894 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |