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 23 matching lines...) Expand all Loading... |
34 // initialization is not a problem as it is always set to point to the same | 34 // initialization is not a problem as it is always set to point to the same |
35 // value (i.e., the FactoryGet always returns the same value). FactoryGet | 35 // value (i.e., the FactoryGet always returns the same value). FactoryGet |
36 // is also completely thread safe, which results in a completely thread safe, | 36 // is also completely thread safe, which results in a completely thread safe, |
37 // and relatively fast, set of counters. To avoid races at shutdown, the static | 37 // and relatively fast, set of counters. To avoid races at shutdown, the static |
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 <list> |
44 #include <map> | 45 #include <map> |
45 #include <string> | 46 #include <string> |
46 #include <vector> | 47 #include <vector> |
47 | 48 |
48 #include "base/atomicops.h" | 49 #include "base/atomicops.h" |
49 #include "base/base_export.h" | 50 #include "base/base_export.h" |
50 #include "base/gtest_prod_util.h" | 51 #include "base/gtest_prod_util.h" |
51 #include "base/logging.h" | 52 #include "base/logging.h" |
52 #include "base/time.h" | 53 #include "base/time.h" |
53 | 54 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag)) | 310 boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag)) |
310 | 311 |
311 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ | 312 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ |
312 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ | 313 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ |
313 base::CustomHistogram::FactoryGet(name, custom_ranges, \ | 314 base::CustomHistogram::FactoryGet(name, custom_ranges, \ |
314 base::Histogram::kUmaTargetedHistogramFlag)) | 315 base::Histogram::kUmaTargetedHistogramFlag)) |
315 | 316 |
316 //------------------------------------------------------------------------------ | 317 //------------------------------------------------------------------------------ |
317 | 318 |
318 class BooleanHistogram; | 319 class BooleanHistogram; |
| 320 class CachedRanges; |
319 class CustomHistogram; | 321 class CustomHistogram; |
320 class Histogram; | 322 class Histogram; |
321 class LinearHistogram; | 323 class LinearHistogram; |
322 | 324 |
323 class BASE_EXPORT Histogram { | 325 class BASE_EXPORT Histogram { |
324 public: | 326 public: |
325 typedef int Sample; // Used for samples (and ranges of samples). | 327 typedef int Sample; // Used for samples (and ranges of samples). |
326 typedef int Count; // Used to count samples in a bucket. | 328 typedef int Count; // Used to count samples in a bucket. |
327 static const Sample kSampleType_MAX = INT_MAX; | 329 static const Sample kSampleType_MAX = INT_MAX; |
328 // Initialize maximum number of buckets in histograms as 16,384. | 330 // Initialize maximum number of buckets in histograms as 16,384. |
329 static const size_t kBucketCount_MAX; | 331 static const size_t kBucketCount_MAX; |
330 | 332 |
331 typedef std::vector<Count> Counts; | 333 typedef std::vector<Count> Counts; |
332 typedef std::vector<Sample> Ranges; | |
333 | 334 |
334 // These enums are used to facilitate deserialization of renderer histograms | 335 // These enums are used to facilitate deserialization of renderer histograms |
335 // into the browser. | 336 // into the browser. |
336 enum ClassType { | 337 enum ClassType { |
337 HISTOGRAM, | 338 HISTOGRAM, |
338 LINEAR_HISTOGRAM, | 339 LINEAR_HISTOGRAM, |
339 BOOLEAN_HISTOGRAM, | 340 BOOLEAN_HISTOGRAM, |
340 CUSTOM_HISTOGRAM, | 341 CUSTOM_HISTOGRAM, |
341 NOT_VALID_IN_RENDERER | 342 NOT_VALID_IN_RENDERER |
342 }; | 343 }; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 //---------------------------------------------------------------------------- | 497 //---------------------------------------------------------------------------- |
497 // Accessors for factory constuction, serialization and testing. | 498 // Accessors for factory constuction, serialization and testing. |
498 //---------------------------------------------------------------------------- | 499 //---------------------------------------------------------------------------- |
499 virtual ClassType histogram_type() const; | 500 virtual ClassType histogram_type() const; |
500 const std::string& histogram_name() const { return histogram_name_; } | 501 const std::string& histogram_name() const { return histogram_name_; } |
501 Sample declared_min() const { return declared_min_; } | 502 Sample declared_min() const { return declared_min_; } |
502 Sample declared_max() const { return declared_max_; } | 503 Sample declared_max() const { return declared_max_; } |
503 virtual Sample ranges(size_t i) const; | 504 virtual Sample ranges(size_t i) const; |
504 uint32 range_checksum() const { return range_checksum_; } | 505 uint32 range_checksum() const { return range_checksum_; } |
505 virtual size_t bucket_count() const; | 506 virtual size_t bucket_count() const; |
| 507 CachedRanges* cached_ranges() const { return cached_ranges_; } |
| 508 void set_cached_ranges(CachedRanges* cached_ranges) { |
| 509 cached_ranges_ = cached_ranges; |
| 510 } |
506 // Snapshot the current complete set of sample data. | 511 // Snapshot the current complete set of sample data. |
507 // Override with atomic/locked snapshot if needed. | 512 // Override with atomic/locked snapshot if needed. |
508 virtual void SnapshotSample(SampleSet* sample) const; | 513 virtual void SnapshotSample(SampleSet* sample) const; |
509 | 514 |
510 virtual bool HasConstructorArguments(Sample minimum, Sample maximum, | 515 virtual bool HasConstructorArguments(Sample minimum, Sample maximum, |
511 size_t bucket_count); | 516 size_t bucket_count); |
512 | 517 |
513 virtual bool HasConstructorTimeDeltaArguments(TimeDelta minimum, | 518 virtual bool HasConstructorTimeDeltaArguments(TimeDelta minimum, |
514 TimeDelta maximum, | 519 TimeDelta maximum, |
515 size_t bucket_count); | 520 size_t bucket_count); |
516 // Return true iff the range_checksum_ matches current ranges_ vector. | 521 // Return true iff the range_checksum_ matches current |ranges_| vector in |
| 522 // |cached_ranges_|. |
517 bool HasValidRangeChecksum() const; | 523 bool HasValidRangeChecksum() const; |
518 | 524 |
519 protected: | 525 protected: |
520 Histogram(const std::string& name, Sample minimum, | 526 Histogram(const std::string& name, Sample minimum, |
521 Sample maximum, size_t bucket_count); | 527 Sample maximum, size_t bucket_count); |
522 Histogram(const std::string& name, TimeDelta minimum, | 528 Histogram(const std::string& name, TimeDelta minimum, |
523 TimeDelta maximum, size_t bucket_count); | 529 TimeDelta maximum, size_t bucket_count); |
524 | 530 |
525 virtual ~Histogram(); | 531 virtual ~Histogram(); |
526 | 532 |
527 // Initialize ranges_ mapping. | 533 // Initialize ranges_ mapping in cached_ranges_. |
528 void InitializeBucketRange(); | 534 void InitializeBucketRange(); |
529 | 535 |
530 // Method to override to skip the display of the i'th bucket if it's empty. | 536 // Method to override to skip the display of the i'th bucket if it's empty. |
531 virtual bool PrintEmptyBucket(size_t index) const; | 537 virtual bool PrintEmptyBucket(size_t index) const; |
532 | 538 |
533 //---------------------------------------------------------------------------- | 539 //---------------------------------------------------------------------------- |
534 // Methods to override to create histogram with different bucket widths. | 540 // Methods to override to create histogram with different bucket widths. |
535 //---------------------------------------------------------------------------- | 541 //---------------------------------------------------------------------------- |
536 // Find bucket to increment for sample value. | 542 // Find bucket to increment for sample value. |
537 virtual size_t BucketIndex(Sample value) const; | 543 virtual size_t BucketIndex(Sample value) const; |
538 // Get normalized size, relative to the ranges_[i]. | 544 // Get normalized size, relative to the ranges(i). |
539 virtual double GetBucketSize(Count current, size_t i) const; | 545 virtual double GetBucketSize(Count current, size_t i) const; |
540 | 546 |
541 // Recalculate range_checksum_. | 547 // Recalculate range_checksum_. |
542 void ResetRangeChecksum(); | 548 void ResetRangeChecksum(); |
543 | 549 |
544 // Return a string description of what goes in a given bucket. | 550 // Return a string description of what goes in a given bucket. |
545 // Most commonly this is the numeric value, but in derived classes it may | 551 // Most commonly this is the numeric value, but in derived classes it may |
546 // be a name (or string description) given to the bucket. | 552 // be a name (or string description) given to the bucket. |
547 virtual const std::string GetAsciiBucketRange(size_t it) const; | 553 virtual const std::string GetAsciiBucketRange(size_t it) const; |
548 | 554 |
549 //---------------------------------------------------------------------------- | 555 //---------------------------------------------------------------------------- |
550 // Methods to override to create thread safe histogram. | 556 // Methods to override to create thread safe histogram. |
551 //---------------------------------------------------------------------------- | 557 //---------------------------------------------------------------------------- |
552 // Update all our internal data, including histogram | 558 // Update all our internal data, including histogram |
553 virtual void Accumulate(Sample value, Count count, size_t index); | 559 virtual void Accumulate(Sample value, Count count, size_t index); |
554 | 560 |
555 //---------------------------------------------------------------------------- | 561 //---------------------------------------------------------------------------- |
556 // Accessors for derived classes. | 562 // Accessors for derived classes. |
557 //---------------------------------------------------------------------------- | 563 //---------------------------------------------------------------------------- |
558 void SetBucketRange(size_t i, Sample value); | 564 void SetBucketRange(size_t i, Sample value); |
559 | 565 |
560 // Validate that ranges_ was created sensibly (top and bottom range | 566 // Validate that ranges_ in cached_ranges_ was created sensibly (top and |
561 // values relate properly to the declared_min_ and declared_max_).. | 567 // bottom range values relate properly to the declared_min_ and |
| 568 // declared_max_). |
562 bool ValidateBucketRanges() const; | 569 bool ValidateBucketRanges() const; |
563 | 570 |
564 virtual uint32 CalculateRangeChecksum() const; | 571 virtual uint32 CalculateRangeChecksum() const; |
565 | 572 |
566 private: | 573 private: |
567 // Allow tests to corrupt our innards for testing purposes. | 574 // Allow tests to corrupt our innards for testing purposes. |
568 FRIEND_TEST(HistogramTest, CorruptBucketBounds); | 575 FRIEND_TEST(HistogramTest, CorruptBucketBounds); |
569 FRIEND_TEST(HistogramTest, CorruptSampleCounts); | 576 FRIEND_TEST(HistogramTest, CorruptSampleCounts); |
570 FRIEND_TEST(HistogramTest, Crc32SampleHash); | 577 FRIEND_TEST(HistogramTest, Crc32SampleHash); |
571 FRIEND_TEST(HistogramTest, Crc32TableTest); | 578 FRIEND_TEST(HistogramTest, Crc32TableTest); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 Sample declared_min_; // Less than this goes into counts_[0] | 622 Sample declared_min_; // Less than this goes into counts_[0] |
616 Sample declared_max_; // Over this goes into counts_[bucket_count_ - 1]. | 623 Sample declared_max_; // Over this goes into counts_[bucket_count_ - 1]. |
617 size_t bucket_count_; // Dimension of counts_[]. | 624 size_t bucket_count_; // Dimension of counts_[]. |
618 | 625 |
619 // Flag the histogram for recording by UMA via metric_services.h. | 626 // Flag the histogram for recording by UMA via metric_services.h. |
620 Flags flags_; | 627 Flags flags_; |
621 | 628 |
622 // For each index, show the least value that can be stored in the | 629 // For each index, show the least value that can be stored in the |
623 // corresponding bucket. We also append one extra element in this array, | 630 // corresponding bucket. We also append one extra element in this array, |
624 // containing kSampleType_MAX, to make calculations easy. | 631 // containing kSampleType_MAX, to make calculations easy. |
625 // The dimension of ranges_ is bucket_count + 1. | 632 // The dimension of ranges_ in cached_ranges_ is bucket_count + 1. |
626 Ranges ranges_; | 633 CachedRanges* cached_ranges_; |
627 | 634 |
628 // For redundancy, we store a checksum of all the sample ranges when ranges | 635 // For redundancy, we store a checksum of all the sample ranges when ranges |
629 // are generated. If ever there is ever a difference, then the histogram must | 636 // are generated. If ever there is ever a difference, then the histogram must |
630 // have been corrupted. | 637 // have been corrupted. |
631 uint32 range_checksum_; | 638 uint32 range_checksum_; |
632 | 639 |
633 // Finally, provide the state that changes with the addition of each new | 640 // Finally, provide the state that changes with the addition of each new |
634 // sample. | 641 // sample. |
635 SampleSet sample_; | 642 SampleSet sample_; |
636 | 643 |
(...skipping 28 matching lines...) Expand all Loading... |
665 // The last element in the array has a null in its "description" slot. | 672 // The last element in the array has a null in its "description" slot. |
666 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); | 673 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); |
667 | 674 |
668 protected: | 675 protected: |
669 LinearHistogram(const std::string& name, Sample minimum, | 676 LinearHistogram(const std::string& name, Sample minimum, |
670 Sample maximum, size_t bucket_count); | 677 Sample maximum, size_t bucket_count); |
671 | 678 |
672 LinearHistogram(const std::string& name, TimeDelta minimum, | 679 LinearHistogram(const std::string& name, TimeDelta minimum, |
673 TimeDelta maximum, size_t bucket_count); | 680 TimeDelta maximum, size_t bucket_count); |
674 | 681 |
675 // Initialize ranges_ mapping. | 682 // Initialize ranges_ mapping in cached_ranges_. |
676 void InitializeBucketRange(); | 683 void InitializeBucketRange(); |
677 virtual double GetBucketSize(Count current, size_t i) const; | 684 virtual double GetBucketSize(Count current, size_t i) const; |
678 | 685 |
679 // If we have a description for a bucket, then return that. Otherwise | 686 // If we have a description for a bucket, then return that. Otherwise |
680 // let parent class provide a (numeric) description. | 687 // let parent class provide a (numeric) description. |
681 virtual const std::string GetAsciiBucketRange(size_t i) const; | 688 virtual const std::string GetAsciiBucketRange(size_t i) const; |
682 | 689 |
683 // Skip printing of name for numeric range if we have a name (and if this is | 690 // Skip printing of name for numeric range if we have a name (and if this is |
684 // an empty bucket). | 691 // an empty bucket). |
685 virtual bool PrintEmptyBucket(size_t index) const; | 692 virtual bool PrintEmptyBucket(size_t index) const; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 // This function ensures that a guard bucket exists right after any | 736 // This function ensures that a guard bucket exists right after any |
730 // valid sample value (unless the next higher sample is also a valid value), | 737 // valid sample value (unless the next higher sample is also a valid value), |
731 // so that invalid samples never fall into the same bucket as valid samples. | 738 // so that invalid samples never fall into the same bucket as valid samples. |
732 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 739 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
733 size_t num_values); | 740 size_t num_values); |
734 | 741 |
735 protected: | 742 protected: |
736 CustomHistogram(const std::string& name, | 743 CustomHistogram(const std::string& name, |
737 const std::vector<Sample>& custom_ranges); | 744 const std::vector<Sample>& custom_ranges); |
738 | 745 |
739 // Initialize ranges_ mapping. | 746 // Initialize ranges_ mapping in cached_ranges_. |
740 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); | 747 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); |
741 virtual double GetBucketSize(Count current, size_t i) const; | 748 virtual double GetBucketSize(Count current, size_t i) const; |
742 | 749 |
743 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 750 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
744 }; | 751 }; |
745 | 752 |
746 //------------------------------------------------------------------------------ | 753 //------------------------------------------------------------------------------ |
747 // StatisticsRecorder handles all histograms in the system. It provides a | 754 // StatisticsRecorder handles all histograms in the system. It provides a |
748 // general place for histograms to register, and supports a global API for | 755 // general place for histograms to register, and supports a global API for |
749 // accessing (i.e., dumping, or graphing) the data in all the histograms. | 756 // accessing (i.e., dumping, or graphing) the data in all the histograms. |
750 | 757 |
751 class BASE_EXPORT StatisticsRecorder { | 758 class BASE_EXPORT StatisticsRecorder { |
752 public: | 759 public: |
753 typedef std::vector<Histogram*> Histograms; | 760 typedef std::vector<Histogram*> Histograms; |
754 | 761 |
755 StatisticsRecorder(); | 762 StatisticsRecorder(); |
756 | 763 |
757 ~StatisticsRecorder(); | 764 ~StatisticsRecorder(); |
758 | 765 |
759 // Find out if histograms can now be registered into our list. | 766 // Find out if histograms can now be registered into our list. |
760 static bool IsActive(); | 767 static bool IsActive(); |
761 | 768 |
762 // Register, or add a new histogram to the collection of statistics. If an | 769 // Register, or add a new histogram to the collection of statistics. If an |
763 // identically named histogram is already registered, then the argument | 770 // identically named histogram is already registered, then the argument |
764 // |histogram| will deleted. The returned value is always the registered | 771 // |histogram| will deleted. The returned value is always the registered |
765 // histogram (either the argument, or the pre-existing registered histogram). | 772 // histogram (either the argument, or the pre-existing registered histogram). |
766 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram); | 773 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram); |
767 | 774 |
| 775 // Register, or add a new cached_ranges_ of |histogram|. If an identical |
| 776 // cached_ranges_ is already registered, then the cached_ranges_ of |
| 777 // |histogram| is deleted and the |histogram|'s cached_ranges_ is reset to the |
| 778 // registered cached_ranges_. The cached_ranges_ of |histogram| is always the |
| 779 // registered CachedRanges (either the argument's cached_ranges_, or the |
| 780 // pre-existing registered cached_ranges_). |
| 781 static void RegisterOrDeleteDuplicateRanges(Histogram* histogram); |
| 782 |
| 783 // Method for collecting stats about histograms created in browser and |
| 784 // renderer processes. |suffix| is appended to histogram names. |suffix| could |
| 785 // be either browser or renderer. |
| 786 static void CollectHistogramStats(const std::string& suffix); |
| 787 |
768 // Methods for printing histograms. Only histograms which have query as | 788 // Methods for printing histograms. Only histograms which have query as |
769 // a substring are written to output (an empty string will process all | 789 // a substring are written to output (an empty string will process all |
770 // registered histograms). | 790 // registered histograms). |
771 static void WriteHTMLGraph(const std::string& query, std::string* output); | 791 static void WriteHTMLGraph(const std::string& query, std::string* output); |
772 static void WriteGraph(const std::string& query, std::string* output); | 792 static void WriteGraph(const std::string& query, std::string* output); |
773 | 793 |
774 // Method for extracting histograms which were marked for use by UMA. | 794 // Method for extracting histograms which were marked for use by UMA. |
775 static void GetHistograms(Histograms* output); | 795 static void GetHistograms(Histograms* output); |
776 | 796 |
777 // Find a histogram by name. It matches the exact name. This method is thread | 797 // Find a histogram by name. It matches the exact name. This method is thread |
778 // safe. If a matching histogram is not found, then the |histogram| is | 798 // safe. If a matching histogram is not found, then the |histogram| is |
779 // not changed. | 799 // not changed. |
780 static bool FindHistogram(const std::string& query, Histogram** histogram); | 800 static bool FindHistogram(const std::string& query, Histogram** histogram); |
781 | 801 |
782 static bool dump_on_exit() { return dump_on_exit_; } | 802 static bool dump_on_exit() { return dump_on_exit_; } |
783 | 803 |
784 static void set_dump_on_exit(bool enable) { dump_on_exit_ = enable; } | 804 static void set_dump_on_exit(bool enable) { dump_on_exit_ = enable; } |
785 | 805 |
786 // GetSnapshot copies some of the pointers to registered histograms into the | 806 // GetSnapshot copies some of the pointers to registered histograms into the |
787 // caller supplied vector (Histograms). Only histograms with names matching | 807 // caller supplied vector (Histograms). Only histograms with names matching |
788 // query are returned. The query must be a substring of histogram name for its | 808 // query are returned. The query must be a substring of histogram name for its |
789 // pointer to be copied. | 809 // pointer to be copied. |
790 static void GetSnapshot(const std::string& query, Histograms* snapshot); | 810 static void GetSnapshot(const std::string& query, Histograms* snapshot); |
791 | 811 |
792 | 812 |
793 private: | 813 private: |
794 // We keep all registered histograms in a map, from name to histogram. | 814 // We keep all registered histograms in a map, from name to histogram. |
795 typedef std::map<std::string, Histogram*> HistogramMap; | 815 typedef std::map<std::string, Histogram*> HistogramMap; |
796 | 816 |
| 817 // We keep all |cached_ranges_| in a map, from checksum to a list of |
| 818 // |cached_ranges_|. Checksum is calculated from the |ranges_| in |
| 819 // |cached_ranges_|. |
| 820 typedef std::map<uint32, std::list<CachedRanges*>*> RangesMap; |
| 821 |
797 static HistogramMap* histograms_; | 822 static HistogramMap* histograms_; |
798 | 823 |
| 824 static RangesMap* ranges_; |
| 825 |
799 // lock protects access to the above map. | 826 // lock protects access to the above map. |
800 static base::Lock* lock_; | 827 static base::Lock* lock_; |
801 | 828 |
802 // Dump all known histograms to log. | 829 // Dump all known histograms to log. |
803 static bool dump_on_exit_; | 830 static bool dump_on_exit_; |
804 | 831 |
805 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 832 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
806 }; | 833 }; |
807 | 834 |
| 835 //------------------------------------------------------------------------------ |
| 836 |
| 837 // CachedRanges stores the Ranges vector. Histograms that have same Ranges |
| 838 // vector will use the same CachedRanges object. |
| 839 class BASE_EXPORT CachedRanges { |
| 840 public: |
| 841 typedef std::vector<Histogram::Sample> Ranges; |
| 842 |
| 843 CachedRanges(size_t bucket_count, int initial_value); |
| 844 ~CachedRanges(); |
| 845 |
| 846 //---------------------------------------------------------------------------- |
| 847 // Accessors methods for ranges_ and range_checksum_. |
| 848 //---------------------------------------------------------------------------- |
| 849 size_t size() const { return ranges_.size(); } |
| 850 Histogram::Sample ranges(size_t i) const { return ranges_[i]; } |
| 851 void SetBucketRange(size_t i, Histogram::Sample value); |
| 852 uint32 range_checksum(uint32 checksum) const { return range_checksum_; } |
| 853 void SetRangeChecksum(uint32 checksum) { range_checksum_ = checksum; } |
| 854 |
| 855 // Return true iff |other| object has same ranges_ as |this| object's ranges_. |
| 856 bool Equals(CachedRanges* other) const; |
| 857 |
| 858 private: |
| 859 // Allow tests to corrupt our innards for testing purposes. |
| 860 FRIEND_TEST(HistogramTest, CorruptBucketBounds); |
| 861 |
| 862 // A monotonically increasing list of values which determine which bucket to |
| 863 // put a sample into. For each index, show the smallest sample that can be |
| 864 // added to the corresponding bucket. |
| 865 Ranges ranges_; |
| 866 |
| 867 // Checksum for the conntents of ranges_. Used to detect random over-writes |
| 868 // of our data, and to quickly see if some other CachedRanges instance is |
| 869 // possibly Equal() to this instance. |
| 870 uint32 range_checksum_; |
| 871 |
| 872 DISALLOW_COPY_AND_ASSIGN(CachedRanges); |
| 873 }; |
| 874 |
808 } // namespace base | 875 } // namespace base |
809 | 876 |
810 #endif // BASE_METRICS_HISTOGRAM_H_ | 877 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |