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