OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // SampleMap implements HistogramSamples interface. It is used by the | |
6 // SparseHistogram class to store samples. | |
7 | |
8 #ifndef BASE_METRICS_SAMPLE_MAP_H_ | |
9 #define BASE_METRICS_SAMPLE_MAP_H_ | |
10 | |
11 #include <map> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/metrics/histogram_base.h" | |
16 #include "base/metrics/histogram_samples.h" | |
17 #include "base/synchronization/lock.h" | |
18 | |
19 namespace base { | |
20 | |
21 class BASE_EXPORT_PRIVATE SampleMap : public HistogramSamples { | |
22 public: | |
23 SampleMap(); | |
24 virtual ~SampleMap(); | |
25 | |
26 // HistogramSamples implementation: | |
27 virtual void Accumulate(HistogramBase::Sample value, | |
28 HistogramBase::Count count) OVERRIDE; | |
29 virtual HistogramBase::Count GetCount( | |
30 HistogramBase::Sample value) const OVERRIDE; | |
31 virtual HistogramBase::Count TotalCount() const OVERRIDE; | |
32 virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE; | |
33 | |
34 protected: | |
35 virtual bool AddSubtractImpl( | |
36 SampleCountIterator* iter, | |
37 HistogramSamples::Instruction instruction) OVERRIDE; | |
38 | |
39 private: | |
40 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; | |
41 | |
42 // Protects access to above map. | |
43 mutable base::Lock lock_; | |
44 | |
45 friend class SparseHistogram; // To lock its samples for snapshotting. | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(SampleMap); | |
48 }; | |
49 | |
50 class BASE_EXPORT_PRIVATE SampleMapIterator : public SampleCountIterator { | |
51 public: | |
52 SampleMapIterator( | |
53 const std::map<HistogramBase::Sample, HistogramBase::Count>& | |
54 sample_counts); | |
55 | |
56 virtual ~SampleMapIterator(); | |
57 | |
58 // SampleCountIterator implementation: | |
59 virtual bool Done() const OVERRIDE; | |
60 virtual void Next() OVERRIDE; | |
61 virtual void Get(HistogramBase::Sample* min, | |
62 HistogramBase::Sample* max, | |
63 HistogramBase::Count* count) const OVERRIDE; | |
64 private: | |
65 std::map<HistogramBase::Sample, HistogramBase::Count>::const_iterator iter_; | |
66 const std::map<HistogramBase::Sample, HistogramBase::Count>::const_iterator | |
jar (doing other things)
2012/10/02 17:41:11
This seems like an implementation detail (a shortc
| |
67 end_; | |
68 }; | |
69 | |
70 } // namespace base | |
71 | |
72 #endif // BASE_METRICS_SAMPLE_MAP_H_ | |
OLD | NEW |