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 // SampleMap implements HistogramSamples interface. It is used by the | 5 // SampleMap implements HistogramSamples interface. It is used by the |
6 // SparseHistogram class to store samples. | 6 // SparseHistogram class to store samples. |
7 | 7 |
8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ | 8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ |
9 #define BASE_METRICS_SAMPLE_MAP_H_ | 9 #define BASE_METRICS_SAMPLE_MAP_H_ |
10 | 10 |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 | 14 |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/metrics/histogram_base.h" | 18 #include "base/metrics/histogram_base.h" |
19 #include "base/metrics/histogram_samples.h" | 19 #include "base/metrics/histogram_samples.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 | 22 |
23 class BASE_EXPORT SampleMap : public HistogramSamples { | 23 class BASE_EXPORT SampleMap : public HistogramSamples { |
24 public: | 24 public: |
25 SampleMap(); | 25 SampleMap(); |
26 explicit SampleMap(uint64_t id); | 26 explicit SampleMap(uint64_t id); |
27 ~SampleMap() override; | 27 ~SampleMap() override; |
28 | 28 |
29 // HistogramSamples implementation: | 29 // HistogramSamples: |
30 void Accumulate(HistogramBase::Sample value, | 30 void Accumulate(HistogramBase::Sample value, |
31 HistogramBase::Count count) override; | 31 HistogramBase::Count count) override; |
32 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; | 32 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; |
33 HistogramBase::Count TotalCount() const override; | 33 HistogramBase::Count TotalCount() const override; |
34 scoped_ptr<SampleCountIterator> Iterator() const override; | 34 scoped_ptr<SampleCountIterator> Iterator() const override; |
35 | 35 |
36 protected: | 36 protected: |
37 bool AddSubtractImpl( | 37 // Performs arithemetic. |op| is ADD or SUBTRACT. |
38 SampleCountIterator* iter, | 38 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override; |
39 HistogramSamples::Operator op) override; // |op| is ADD or SUBTRACT. | |
40 | 39 |
41 private: | 40 private: |
42 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; | 41 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; |
43 | 42 |
44 DISALLOW_COPY_AND_ASSIGN(SampleMap); | 43 DISALLOW_COPY_AND_ASSIGN(SampleMap); |
45 }; | 44 }; |
46 | 45 |
47 class BASE_EXPORT SampleMapIterator : public SampleCountIterator { | 46 class BASE_EXPORT SampleMapIterator : public SampleCountIterator { |
48 public: | 47 public: |
49 typedef std::map<HistogramBase::Sample, HistogramBase::Count> | 48 typedef std::map<HistogramBase::Sample, HistogramBase::Count> |
50 SampleToCountMap; | 49 SampleToCountMap; |
51 | 50 |
52 explicit SampleMapIterator(const SampleToCountMap& sample_counts); | 51 explicit SampleMapIterator(const SampleToCountMap& sample_counts); |
53 ~SampleMapIterator() override; | 52 ~SampleMapIterator() override; |
54 | 53 |
55 // SampleCountIterator implementation: | 54 // SampleCountIterator: |
56 bool Done() const override; | 55 bool Done() const override; |
57 void Next() override; | 56 void Next() override; |
58 void Get(HistogramBase::Sample* min, | 57 void Get(HistogramBase::Sample* min, |
59 HistogramBase::Sample* max, | 58 HistogramBase::Sample* max, |
60 HistogramBase::Count* count) const override; | 59 HistogramBase::Count* count) const override; |
61 | 60 |
62 private: | 61 private: |
63 void SkipEmptyBuckets(); | 62 void SkipEmptyBuckets(); |
64 | 63 |
65 SampleToCountMap::const_iterator iter_; | 64 SampleToCountMap::const_iterator iter_; |
66 const SampleToCountMap::const_iterator end_; | 65 const SampleToCountMap::const_iterator end_; |
67 }; | 66 }; |
68 | 67 |
69 } // namespace base | 68 } // namespace base |
70 | 69 |
71 #endif // BASE_METRICS_SAMPLE_MAP_H_ | 70 #endif // BASE_METRICS_SAMPLE_MAP_H_ |
OLD | NEW |