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 #ifndef BASE_METRICS_HISTOGRAM_SAMPLES_H_ | 5 #ifndef BASE_METRICS_HISTOGRAM_SAMPLES_H_ |
6 #define BASE_METRICS_HISTOGRAM_SAMPLES_H_ | 6 #define BASE_METRICS_HISTOGRAM_SAMPLES_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/metrics/histogram_base.h" | 9 #include "base/metrics/histogram_base.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // Add from serialized samples. | 32 // Add from serialized samples. |
33 virtual bool AddFromPickle(PickleIterator* iter); | 33 virtual bool AddFromPickle(PickleIterator* iter); |
34 | 34 |
35 virtual void Subtract(const HistogramSamples& other); | 35 virtual void Subtract(const HistogramSamples& other); |
36 | 36 |
37 virtual scoped_ptr<SampleCountIterator> Iterator() const = 0; | 37 virtual scoped_ptr<SampleCountIterator> Iterator() const = 0; |
38 virtual bool Serialize(Pickle* pickle) const; | 38 virtual bool Serialize(Pickle* pickle) const; |
39 | 39 |
40 // Accessor fuctions. | 40 // Accessor fuctions. |
41 int64 sum() const { return sum_; } | 41 int64 sum() const { return sum_; } |
42 HistogramBase::Count redundant_count() const { return redundant_count_; } | 42 HistogramBase::Count redundant_count() const { |
| 43 return subtle::NoBarrier_Load(&redundant_count_); |
| 44 } |
43 | 45 |
44 protected: | 46 protected: |
45 // Based on |op| type, add or subtract sample counts data from the iterator. | 47 // Based on |op| type, add or subtract sample counts data from the iterator. |
46 enum Operator { ADD, SUBTRACT }; | 48 enum Operator { ADD, SUBTRACT }; |
47 virtual bool AddSubtractImpl(SampleCountIterator* iter, Operator op) = 0; | 49 virtual bool AddSubtractImpl(SampleCountIterator* iter, Operator op) = 0; |
48 | 50 |
49 void IncreaseSum(int64 diff); | 51 void IncreaseSum(int64 diff); |
50 void IncreaseRedundantCount(HistogramBase::Count diff); | 52 void IncreaseRedundantCount(HistogramBase::Count diff); |
51 | 53 |
52 private: | 54 private: |
53 int64 sum_; | 55 int64 sum_; |
54 | 56 |
55 // |redundant_count_| helps identify memory corruption. It redundantly stores | 57 // |redundant_count_| helps identify memory corruption. It redundantly stores |
56 // the total number of samples accumulated in the histogram. We can compare | 58 // the total number of samples accumulated in the histogram. We can compare |
57 // this count to the sum of the counts (TotalCount() function), and detect | 59 // this count to the sum of the counts (TotalCount() function), and detect |
58 // problems. Note, depending on the implementation of different histogram | 60 // problems. Note, depending on the implementation of different histogram |
59 // types, there might be races during histogram accumulation and snapshotting | 61 // types, there might be races during histogram accumulation and snapshotting |
60 // that we choose to accept. In this case, the tallies might mismatch even | 62 // that we choose to accept. In this case, the tallies might mismatch even |
61 // when no memory corruption has happened. | 63 // when no memory corruption has happened. |
62 HistogramBase::Count redundant_count_; | 64 HistogramBase::AtomicCount redundant_count_; |
63 }; | 65 }; |
64 | 66 |
65 class BASE_EXPORT SampleCountIterator { | 67 class BASE_EXPORT SampleCountIterator { |
66 public: | 68 public: |
67 virtual ~SampleCountIterator(); | 69 virtual ~SampleCountIterator(); |
68 | 70 |
69 virtual bool Done() const = 0; | 71 virtual bool Done() const = 0; |
70 virtual void Next() = 0; | 72 virtual void Next() = 0; |
71 | 73 |
72 // Get the sample and count at current position. | 74 // Get the sample and count at current position. |
73 // |min| |max| and |count| can be NULL if the value is not of interest. | 75 // |min| |max| and |count| can be NULL if the value is not of interest. |
74 // Requires: !Done(); | 76 // Requires: !Done(); |
75 virtual void Get(HistogramBase::Sample* min, | 77 virtual void Get(HistogramBase::Sample* min, |
76 HistogramBase::Sample* max, | 78 HistogramBase::Sample* max, |
77 HistogramBase::Count* count) const = 0; | 79 HistogramBase::Count* count) const = 0; |
78 | 80 |
79 // Get the index of current histogram bucket. | 81 // Get the index of current histogram bucket. |
80 // For histograms that don't use predefined buckets, it returns false. | 82 // For histograms that don't use predefined buckets, it returns false. |
81 // Requires: !Done(); | 83 // Requires: !Done(); |
82 virtual bool GetBucketIndex(size_t* index) const; | 84 virtual bool GetBucketIndex(size_t* index) const; |
83 }; | 85 }; |
84 | 86 |
85 } // namespace base | 87 } // namespace base |
86 | 88 |
87 #endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_ | 89 #endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_ |
OLD | NEW |