Chromium Code Reviews| 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 SampleVector : public HistogramSamples { | 23 class BASE_EXPORT SampleVector : public HistogramSamples { |
| 24 public: | 24 public: |
| 25 explicit SampleVector(const BucketRanges* bucket_ranges); | 25 explicit SampleVector(const BucketRanges* bucket_ranges); |
| 26 SampleVector(uint64 id, const BucketRanges* bucket_ranges); | |
| 27 SampleVector(uint64 id, | |
| 28 HistogramBase::AtomicCount* counts, | |
| 29 size_t counts_size, | |
| 30 Metadata* meta, | |
| 31 const BucketRanges* bucket_ranges); | |
| 26 ~SampleVector() override; | 32 ~SampleVector() override; |
| 27 | 33 |
| 28 // HistogramSamples implementation: | 34 // HistogramSamples implementation: |
| 29 void Accumulate(HistogramBase::Sample value, | 35 void Accumulate(HistogramBase::Sample value, |
| 30 HistogramBase::Count count) override; | 36 HistogramBase::Count count) override; |
| 31 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; | 37 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; |
| 32 HistogramBase::Count TotalCount() const override; | 38 HistogramBase::Count TotalCount() const override; |
| 33 scoped_ptr<SampleCountIterator> Iterator() const override; | 39 scoped_ptr<SampleCountIterator> Iterator() const override; |
| 34 | 40 |
| 35 // Get count of a specific bucket. | 41 // Get count of a specific bucket. |
| 36 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const; | 42 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const; |
| 37 | 43 |
| 38 protected: | 44 protected: |
| 39 bool AddSubtractImpl( | 45 bool AddSubtractImpl( |
| 40 SampleCountIterator* iter, | 46 SampleCountIterator* iter, |
| 41 HistogramSamples::Operator op) override; // |op| is ADD or SUBTRACT. | 47 HistogramSamples::Operator op) override; // |op| is ADD or SUBTRACT. |
| 42 | 48 |
| 43 virtual size_t GetBucketIndex(HistogramBase::Sample value) const; | 49 virtual size_t GetBucketIndex(HistogramBase::Sample value) const; |
| 44 | 50 |
| 45 private: | 51 private: |
| 46 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); | 52 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); |
| 47 | 53 |
| 48 std::vector<HistogramBase::AtomicCount> counts_; | 54 // In the case where this class manages the memory, here it is. |
| 55 std::vector<HistogramBase::AtomicCount> local_counts_; | |
| 56 | |
| 57 // These are raw pointers rather than objects for flexibility. The actual | |
| 58 // memory is either managed by local_counts_ above or by an external object | |
| 59 // and passed in directly. | |
| 60 HistogramBase::AtomicCount* counts_; | |
| 61 size_t counts_size_; | |
| 49 | 62 |
| 50 // Shares the same BucketRanges with Histogram object. | 63 // Shares the same BucketRanges with Histogram object. |
| 51 const BucketRanges* const bucket_ranges_; | 64 const BucketRanges* const bucket_ranges_; |
| 52 | 65 |
| 53 DISALLOW_COPY_AND_ASSIGN(SampleVector); | 66 DISALLOW_COPY_AND_ASSIGN(SampleVector); |
| 54 }; | 67 }; |
| 55 | 68 |
| 56 class BASE_EXPORT SampleVectorIterator : public SampleCountIterator { | 69 class BASE_EXPORT SampleVectorIterator : public SampleCountIterator { |
| 57 public: | 70 public: |
| 58 SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts, | 71 SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts, |
| 59 const BucketRanges* bucket_ranges); | 72 const BucketRanges* bucket_ranges); |
| 73 SampleVectorIterator(const HistogramBase::AtomicCount* counts, | |
| 74 size_t counts_size, | |
| 75 const BucketRanges* bucket_ranges); | |
| 60 ~SampleVectorIterator() override; | 76 ~SampleVectorIterator() override; |
| 61 | 77 |
| 62 // SampleCountIterator implementation: | 78 // SampleCountIterator implementation: |
| 63 bool Done() const override; | 79 bool Done() const override; |
| 64 void Next() override; | 80 void Next() override; |
| 65 void Get(HistogramBase::Sample* min, | 81 void Get(HistogramBase::Sample* min, |
| 66 HistogramBase::Sample* max, | 82 HistogramBase::Sample* max, |
| 67 HistogramBase::Count* count) const override; | 83 HistogramBase::Count* count) const override; |
| 68 | 84 |
| 69 // SampleVector uses predefined buckets, so iterator can return bucket index. | 85 // SampleVector uses predefined buckets, so iterator can return bucket index. |
| 70 bool GetBucketIndex(size_t* index) const override; | 86 bool GetBucketIndex(size_t* index) const override; |
| 71 | 87 |
| 72 private: | 88 private: |
| 73 void SkipEmptyBuckets(); | 89 void SkipEmptyBuckets(); |
| 74 | 90 |
| 75 const std::vector<HistogramBase::AtomicCount>* counts_; | 91 const HistogramBase::AtomicCount* counts_; |
|
Alexei Svitkine (slow)
2015/12/01 16:32:14
Can this be "const HistogramBase::AtomicCount* con
| |
| 92 size_t counts_size_; | |
|
Alexei Svitkine (slow)
2015/12/01 16:32:14
Make this const
| |
| 76 const BucketRanges* bucket_ranges_; | 93 const BucketRanges* bucket_ranges_; |
| 77 | 94 |
| 78 size_t index_; | 95 size_t index_; |
| 79 }; | 96 }; |
| 80 | 97 |
| 81 } // namespace base | 98 } // namespace base |
| 82 | 99 |
| 83 #endif // BASE_METRICS_SAMPLE_VECTOR_H_ | 100 #endif // BASE_METRICS_SAMPLE_VECTOR_H_ |
| OLD | NEW |