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 30 matching lines...) Expand all Loading... |
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 <list> |
45 #include <map> | 45 #include <map> |
46 #include <string> | 46 #include <string> |
47 #include <vector> | 47 #include <vector> |
48 | 48 |
49 #include "base/atomicops.h" | 49 #include "base/atomicops.h" |
50 #include "base/base_export.h" | 50 #include "base/base_export.h" |
| 51 #include "base/compiler_specific.h" |
51 #include "base/gtest_prod_util.h" | 52 #include "base/gtest_prod_util.h" |
52 #include "base/logging.h" | 53 #include "base/logging.h" |
53 #include "base/time.h" | 54 #include "base/time.h" |
54 | 55 |
55 class Pickle; | 56 class Pickle; |
56 | 57 |
57 namespace base { | 58 namespace base { |
58 | 59 |
59 class Lock; | 60 class Lock; |
60 //------------------------------------------------------------------------------ | 61 //------------------------------------------------------------------------------ |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // Convenience methods for serializing/deserializing the histograms. | 476 // Convenience methods for serializing/deserializing the histograms. |
476 // Histograms from Renderer process are serialized and sent to the browser. | 477 // Histograms from Renderer process are serialized and sent to the browser. |
477 // Browser process reconstructs the histogram from the pickled version | 478 // Browser process reconstructs the histogram from the pickled version |
478 // accumulates the browser-side shadow copy of histograms (that mirror | 479 // accumulates the browser-side shadow copy of histograms (that mirror |
479 // histograms created in the renderer). | 480 // histograms created in the renderer). |
480 | 481 |
481 // Serialize the given snapshot of a Histogram into a String. Uses | 482 // Serialize the given snapshot of a Histogram into a String. Uses |
482 // Pickle class to flatten the object. | 483 // Pickle class to flatten the object. |
483 static std::string SerializeHistogramInfo(const Histogram& histogram, | 484 static std::string SerializeHistogramInfo(const Histogram& histogram, |
484 const SampleSet& snapshot); | 485 const SampleSet& snapshot); |
| 486 |
485 // The following method accepts a list of pickled histograms and | 487 // The following method accepts a list of pickled histograms and |
486 // builds a histogram and updates shadow copy of histogram data in the | 488 // builds a histogram and updates shadow copy of histogram data in the |
487 // browser process. | 489 // browser process. |
488 static bool DeserializeHistogramInfo(const std::string& histogram_info); | 490 static bool DeserializeHistogramInfo(const std::string& histogram_info); |
489 | 491 |
490 // Check to see if bucket ranges, counts and tallies in the snapshot are | 492 // Check to see if bucket ranges, counts and tallies in the snapshot are |
491 // consistent with the bucket ranges and checksums in our histogram. This can | 493 // consistent with the bucket ranges and checksums in our histogram. This can |
492 // produce a false-alarm if a race occurred in the reading of the data during | 494 // produce a false-alarm if a race occurred in the reading of the data during |
493 // a SnapShot process, but should otherwise be false at all times (unless we | 495 // a SnapShot process, but should otherwise be false at all times (unless we |
494 // have memory over-writes, or DRAM failures). | 496 // have memory over-writes, or DRAM failures). |
(...skipping 28 matching lines...) Expand all Loading... |
523 bool HasValidRangeChecksum() const; | 525 bool HasValidRangeChecksum() const; |
524 | 526 |
525 protected: | 527 protected: |
526 Histogram(const std::string& name, Sample minimum, | 528 Histogram(const std::string& name, Sample minimum, |
527 Sample maximum, size_t bucket_count); | 529 Sample maximum, size_t bucket_count); |
528 Histogram(const std::string& name, TimeDelta minimum, | 530 Histogram(const std::string& name, TimeDelta minimum, |
529 TimeDelta maximum, size_t bucket_count); | 531 TimeDelta maximum, size_t bucket_count); |
530 | 532 |
531 virtual ~Histogram(); | 533 virtual ~Histogram(); |
532 | 534 |
| 535 // Serialize the histogram's ranges to |*pickle|, returning true on success. |
| 536 // Most subclasses can leave this no-op implementation, but some will want to |
| 537 // override it, especially if the ranges cannot be re-derived from other |
| 538 // serialized parameters. |
| 539 virtual bool SerializeRanges(Pickle* pickle) const; |
| 540 |
533 // Initialize ranges_ mapping in cached_ranges_. | 541 // Initialize ranges_ mapping in cached_ranges_. |
534 void InitializeBucketRange(); | 542 void InitializeBucketRange(); |
535 | 543 |
536 // Method to override to skip the display of the i'th bucket if it's empty. | 544 // Method to override to skip the display of the i'th bucket if it's empty. |
537 virtual bool PrintEmptyBucket(size_t index) const; | 545 virtual bool PrintEmptyBucket(size_t index) const; |
538 | 546 |
539 //---------------------------------------------------------------------------- | 547 //---------------------------------------------------------------------------- |
540 // Methods to override to create histogram with different bucket widths. | 548 // Methods to override to create histogram with different bucket widths. |
541 //---------------------------------------------------------------------------- | 549 //---------------------------------------------------------------------------- |
542 // Find bucket to increment for sample value. | 550 // Find bucket to increment for sample value. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 virtual ClassType histogram_type() const; | 740 virtual ClassType histogram_type() const; |
733 | 741 |
734 // Helper method for transforming an array of valid enumeration values | 742 // Helper method for transforming an array of valid enumeration values |
735 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. | 743 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. |
736 // This function ensures that a guard bucket exists right after any | 744 // This function ensures that a guard bucket exists right after any |
737 // valid sample value (unless the next higher sample is also a valid value), | 745 // valid sample value (unless the next higher sample is also a valid value), |
738 // so that invalid samples never fall into the same bucket as valid samples. | 746 // so that invalid samples never fall into the same bucket as valid samples. |
739 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 747 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
740 size_t num_values); | 748 size_t num_values); |
741 | 749 |
| 750 // Helper for deserializing CustomHistograms. |*ranges| should already be |
| 751 // correctly sized before this call. Return true on success. |
| 752 static bool DeserializeRanges(void** iter, const Pickle& pickle, |
| 753 std::vector<Histogram::Sample>* ranges); |
| 754 |
| 755 |
742 protected: | 756 protected: |
743 CustomHistogram(const std::string& name, | 757 CustomHistogram(const std::string& name, |
744 const std::vector<Sample>& custom_ranges); | 758 const std::vector<Sample>& custom_ranges); |
745 | 759 |
| 760 virtual bool SerializeRanges(Pickle* pickle) const OVERRIDE; |
| 761 |
746 // Initialize ranges_ mapping in cached_ranges_. | 762 // Initialize ranges_ mapping in cached_ranges_. |
747 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); | 763 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); |
748 virtual double GetBucketSize(Count current, size_t i) const; | 764 virtual double GetBucketSize(Count current, size_t i) const; |
749 | 765 |
750 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 766 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
751 }; | 767 }; |
752 | 768 |
753 //------------------------------------------------------------------------------ | 769 //------------------------------------------------------------------------------ |
754 // StatisticsRecorder handles all histograms in the system. It provides a | 770 // StatisticsRecorder handles all histograms in the system. It provides a |
755 // general place for histograms to register, and supports a global API for | 771 // general place for histograms to register, and supports a global API for |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 // of our data, and to quickly see if some other CachedRanges instance is | 884 // of our data, and to quickly see if some other CachedRanges instance is |
869 // possibly Equal() to this instance. | 885 // possibly Equal() to this instance. |
870 uint32 range_checksum_; | 886 uint32 range_checksum_; |
871 | 887 |
872 DISALLOW_COPY_AND_ASSIGN(CachedRanges); | 888 DISALLOW_COPY_AND_ASSIGN(CachedRanges); |
873 }; | 889 }; |
874 | 890 |
875 } // namespace base | 891 } // namespace base |
876 | 892 |
877 #endif // BASE_METRICS_HISTOGRAM_H_ | 893 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |