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/memory/scoped_ptr.h" |
15 #include "base/metrics/histogram_base.h" | 15 #include "base/metrics/histogram_base.h" |
16 #include "base/metrics/sample_map.h" | |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 class HistogramSamples; | 21 class HistogramSamples; |
21 | 22 |
22 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { | 23 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { |
23 public: | 24 public: |
24 // If there's one with same name, return the existing one. If not, create a | 25 // If there's one with same name, return the existing one. If not, create a |
25 // new one. | 26 // new one. |
26 static HistogramBase* FactoryGet(const std::string& name, int32 flags); | 27 static HistogramBase* FactoryGet(const std::string& name, int32 flags); |
27 | 28 |
28 virtual ~SparseHistogram(); | 29 virtual ~SparseHistogram(); |
29 | 30 |
30 // HistogramBase implementation: | 31 // HistogramBase implementation: |
31 virtual HistogramType GetHistogramType() const OVERRIDE; | 32 virtual HistogramType GetHistogramType() const OVERRIDE; |
32 virtual bool HasConstructionArguments(Sample minimum, | 33 virtual bool HasConstructionArguments(Sample minimum, |
33 Sample maximum, | 34 Sample maximum, |
34 size_t bucket_count) const OVERRIDE; | 35 size_t bucket_count) const OVERRIDE; |
35 virtual void Add(Sample value) OVERRIDE; | 36 virtual void Add(Sample value) OVERRIDE; |
37 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE; | |
38 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE; | |
39 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; | |
36 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; | 40 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; |
37 virtual void WriteAscii(std::string* output) const OVERRIDE; | 41 virtual void WriteAscii(std::string* output) const OVERRIDE; |
38 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; | 42 |
43 protected: | |
44 // HistogramBase implementation: | |
45 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; | |
39 | 46 |
40 private: | 47 private: |
41 // Clients should always use FactoryGet to create SparseHistogram. | 48 // Clients should always use FactoryGet to create SparseHistogram. |
42 SparseHistogram(const std::string& name); | 49 SparseHistogram(const std::string& name); |
43 | 50 |
51 friend HistogramBase* HistogramBase::DeserializeHistogramInfo( | |
52 PickleIterator* iter); | |
53 static HistogramBase* DeserializeHistogramInfo(PickleIterator* iter); | |
54 | |
44 virtual void GetParameters(DictionaryValue* params) const OVERRIDE; | 55 virtual void GetParameters(DictionaryValue* params) const OVERRIDE; |
45 virtual void GetCountAndBucketData(Count* count, | 56 virtual void GetCountAndBucketData(Count* count, |
46 ListValue* buckets) const OVERRIDE; | 57 ListValue* buckets) const OVERRIDE; |
47 | 58 |
48 friend class SparseHistogramTest; // For constuctor calling. | 59 friend class SparseHistogramTest; // For constuctor calling. |
49 | 60 |
50 // Protects access to |sample_counts_| and |redundant_count_|. | 61 // Protects access to |sample_counts_| and |redundant_count_|. |
Ilya Sherman
2012/12/29 00:17:30
nit: Please update this comment.
kaiwang
2013/01/08 00:51:40
Done.
| |
51 mutable base::Lock lock_; | 62 mutable base::Lock lock_; |
52 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; | 63 SampleMap samples_; |
53 HistogramBase::Count redundant_count_; | |
Ilya Sherman
2012/12/29 00:17:30
Could you remind me of how the redundant count was
kaiwang
2013/01/08 00:51:40
redundant_count_ is just a duplicated count to det
| |
54 | 64 |
55 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); | 65 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); |
56 }; | 66 }; |
57 | 67 |
58 } // namespace base | 68 } // namespace base |
59 | 69 |
60 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ | 70 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ |
OLD | NEW |