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 // The logic here is similar to that of PersistentSampleMap but with different |
| 24 // data structures. Changes here likely need to be duplicated there. |
23 class BASE_EXPORT SampleMap : public HistogramSamples { | 25 class BASE_EXPORT SampleMap : public HistogramSamples { |
24 public: | 26 public: |
25 SampleMap(); | 27 SampleMap(); |
26 explicit SampleMap(uint64_t id); | 28 explicit SampleMap(uint64_t id); |
27 ~SampleMap() override; | 29 ~SampleMap() override; |
28 | 30 |
29 // HistogramSamples implementation: | 31 // HistogramSamples: |
30 void Accumulate(HistogramBase::Sample value, | 32 void Accumulate(HistogramBase::Sample value, |
31 HistogramBase::Count count) override; | 33 HistogramBase::Count count) override; |
32 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; | 34 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; |
33 HistogramBase::Count TotalCount() const override; | 35 HistogramBase::Count TotalCount() const override; |
34 scoped_ptr<SampleCountIterator> Iterator() const override; | 36 scoped_ptr<SampleCountIterator> Iterator() const override; |
35 | 37 |
36 protected: | 38 protected: |
37 bool AddSubtractImpl( | 39 // Performs arithemetic. |op| is ADD or SUBTRACT. |
38 SampleCountIterator* iter, | 40 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override; |
39 HistogramSamples::Operator op) override; // |op| is ADD or SUBTRACT. | |
40 | 41 |
41 private: | 42 private: |
42 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; | 43 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; |
43 | 44 |
44 DISALLOW_COPY_AND_ASSIGN(SampleMap); | 45 DISALLOW_COPY_AND_ASSIGN(SampleMap); |
45 }; | 46 }; |
46 | 47 |
47 class BASE_EXPORT SampleMapIterator : public SampleCountIterator { | |
48 public: | |
49 typedef std::map<HistogramBase::Sample, HistogramBase::Count> | |
50 SampleToCountMap; | |
51 | |
52 explicit SampleMapIterator(const SampleToCountMap& sample_counts); | |
53 ~SampleMapIterator() override; | |
54 | |
55 // SampleCountIterator implementation: | |
56 bool Done() const override; | |
57 void Next() override; | |
58 void Get(HistogramBase::Sample* min, | |
59 HistogramBase::Sample* max, | |
60 HistogramBase::Count* count) const override; | |
61 | |
62 private: | |
63 void SkipEmptyBuckets(); | |
64 | |
65 SampleToCountMap::const_iterator iter_; | |
66 const SampleToCountMap::const_iterator end_; | |
67 }; | |
68 | |
69 } // namespace base | 48 } // namespace base |
70 | 49 |
71 #endif // BASE_METRICS_SAMPLE_MAP_H_ | 50 #endif // BASE_METRICS_SAMPLE_MAP_H_ |
OLD | NEW |