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 // SampleVector implements HistogramSamples interface. It is used by all | 5 // SampleVector implements HistogramSamples interface. It is used by all |
6 // Histogram based classes to store samples. | 6 // Histogram based classes to store samples. |
7 | 7 |
8 #ifndef BASE_METRICS_SAMPLE_VECTOR_H_ | 8 #ifndef BASE_METRICS_SAMPLE_VECTOR_H_ |
9 #define BASE_METRICS_SAMPLE_VECTOR_H_ | 9 #define BASE_METRICS_SAMPLE_VECTOR_H_ |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram_base.h" | 16 #include "base/metrics/histogram_base.h" |
17 #include "base/metrics/histogram_samples.h" | 17 #include "base/metrics/histogram_samples.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 | 20 |
21 class BucketRanges; | 21 class BucketRanges; |
22 | 22 |
23 class BASE_EXPORT_PRIVATE SampleVector : public HistogramSamples { | 23 class BASE_EXPORT_PRIVATE SampleVector : public HistogramSamples { |
24 public: | 24 public: |
25 explicit SampleVector(const BucketRanges* bucket_ranges); | 25 explicit SampleVector(const BucketRanges* bucket_ranges); |
26 virtual ~SampleVector(); | 26 virtual ~SampleVector(); |
27 | 27 |
28 // HistogramSamples implementation: | 28 // HistogramSamples implementation: |
29 virtual void Accumulate(HistogramBase::Sample value, | 29 void Accumulate(HistogramBase::Sample value, |
30 HistogramBase::Count count) OVERRIDE; | 30 HistogramBase::Count count) override; |
31 virtual HistogramBase::Count GetCount( | 31 virtual HistogramBase::Count GetCount( |
32 HistogramBase::Sample value) const OVERRIDE; | 32 HistogramBase::Sample value) const override; |
33 virtual HistogramBase::Count TotalCount() const OVERRIDE; | 33 HistogramBase::Count TotalCount() const override; |
34 virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE; | 34 scoped_ptr<SampleCountIterator> Iterator() const override; |
35 | 35 |
36 // Get count of a specific bucket. | 36 // Get count of a specific bucket. |
37 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const; | 37 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const; |
38 | 38 |
39 protected: | 39 protected: |
40 virtual bool AddSubtractImpl( | 40 bool AddSubtractImpl(SampleCountIterator* iter, HistogramSamples::Operator op) |
41 SampleCountIterator* iter, | 41 override; // |op| is ADD or SUBTRACT. |
42 HistogramSamples::Operator op) OVERRIDE; // |op| is ADD or SUBTRACT. | |
43 | 42 |
44 virtual size_t GetBucketIndex(HistogramBase::Sample value) const; | 43 virtual size_t GetBucketIndex(HistogramBase::Sample value) const; |
45 | 44 |
46 private: | 45 private: |
47 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); | 46 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); |
48 | 47 |
49 std::vector<HistogramBase::AtomicCount> counts_; | 48 std::vector<HistogramBase::AtomicCount> counts_; |
50 | 49 |
51 // Shares the same BucketRanges with Histogram object. | 50 // Shares the same BucketRanges with Histogram object. |
52 const BucketRanges* const bucket_ranges_; | 51 const BucketRanges* const bucket_ranges_; |
53 | 52 |
54 DISALLOW_COPY_AND_ASSIGN(SampleVector); | 53 DISALLOW_COPY_AND_ASSIGN(SampleVector); |
55 }; | 54 }; |
56 | 55 |
57 class BASE_EXPORT_PRIVATE SampleVectorIterator : public SampleCountIterator { | 56 class BASE_EXPORT_PRIVATE SampleVectorIterator : public SampleCountIterator { |
58 public: | 57 public: |
59 SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts, | 58 SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts, |
60 const BucketRanges* bucket_ranges); | 59 const BucketRanges* bucket_ranges); |
61 virtual ~SampleVectorIterator(); | 60 virtual ~SampleVectorIterator(); |
62 | 61 |
63 // SampleCountIterator implementation: | 62 // SampleCountIterator implementation: |
64 virtual bool Done() const OVERRIDE; | 63 bool Done() const override; |
65 virtual void Next() OVERRIDE; | 64 void Next() override; |
66 virtual void Get(HistogramBase::Sample* min, | 65 void Get(HistogramBase::Sample* min, |
67 HistogramBase::Sample* max, | 66 HistogramBase::Sample* max, |
68 HistogramBase::Count* count) const OVERRIDE; | 67 HistogramBase::Count* count) const override; |
69 | 68 |
70 // SampleVector uses predefined buckets, so iterator can return bucket index. | 69 // SampleVector uses predefined buckets, so iterator can return bucket index. |
71 virtual bool GetBucketIndex(size_t* index) const OVERRIDE; | 70 bool GetBucketIndex(size_t* index) const override; |
72 | 71 |
73 private: | 72 private: |
74 void SkipEmptyBuckets(); | 73 void SkipEmptyBuckets(); |
75 | 74 |
76 const std::vector<HistogramBase::AtomicCount>* counts_; | 75 const std::vector<HistogramBase::AtomicCount>* counts_; |
77 const BucketRanges* bucket_ranges_; | 76 const BucketRanges* bucket_ranges_; |
78 | 77 |
79 size_t index_; | 78 size_t index_; |
80 }; | 79 }; |
81 | 80 |
82 } // namespace base | 81 } // namespace base |
83 | 82 |
84 #endif // BASE_METRICS_SAMPLE_VECTOR_H_ | 83 #endif // BASE_METRICS_SAMPLE_VECTOR_H_ |
OLD | NEW |