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 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_ | 5 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_ |
6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_ | 6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/metrics/histogram_base.h" | 15 #include "base/metrics/histogram_base.h" |
| 16 #include "base/metrics/sample_map.h" |
15 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 | 20 |
19 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { | 21 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { |
20 public: | 22 public: |
21 // If there's one with same name, return the existing one. If not, create a | 23 // If there's one with same name, return the existing one. If not, create a |
22 // new one. | 24 // new one. |
23 static HistogramBase* FactoryGet(const std::string& name, int32 flags); | 25 static HistogramBase* FactoryGet(const std::string& name, int32 flags); |
24 | 26 |
25 virtual ~SparseHistogram(); | 27 virtual ~SparseHistogram(); |
26 | 28 |
| 29 // HistogramBase implementation: |
27 virtual void Add(Sample value) OVERRIDE; | 30 virtual void Add(Sample value) OVERRIDE; |
28 | |
29 virtual void SnapshotSample(std::map<Sample, Count>* sample) const; | |
30 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; | 31 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; |
31 virtual void WriteAscii(std::string* output) const OVERRIDE; | 32 virtual void WriteAscii(std::string* output) const OVERRIDE; |
32 | 33 |
33 protected: | 34 virtual scoped_ptr<SampleMap> SnapshotSamples() const; |
| 35 |
| 36 private: |
34 // Clients should always use FactoryGet to create SparseHistogram. | 37 // Clients should always use FactoryGet to create SparseHistogram. |
35 SparseHistogram(const std::string& name); | 38 SparseHistogram(const std::string& name); |
36 | 39 |
37 private: | |
38 friend class SparseHistogramTest; // For constuctor calling. | 40 friend class SparseHistogramTest; // For constuctor calling. |
39 | 41 |
40 std::map<Sample, Count> samples_; | 42 // Protects access to |sample_counts_| and |redundant_count_|. |
41 | |
42 // Protects access to above map. | |
43 mutable base::Lock lock_; | 43 mutable base::Lock lock_; |
| 44 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; |
| 45 HistogramBase::Count redundant_count_; |
44 | 46 |
45 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); | 47 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); |
46 }; | 48 }; |
47 | 49 |
48 } // namespace base | 50 } // namespace base |
49 | 51 |
50 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ | 52 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ |
OLD | NEW |