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 BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
| 52 PickleIterator* iter); |
| 53 static HistogramBase* DeserializeInfoImpl(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 // For constuctor calling. |
| 60 friend class SparseHistogramTest; |
49 | 61 |
50 // Protects access to |sample_counts_| and |redundant_count_|. | 62 // Protects access to |samples_|. |
51 mutable base::Lock lock_; | 63 mutable base::Lock lock_; |
52 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_; | 64 |
53 HistogramBase::Count redundant_count_; | 65 SampleMap samples_; |
54 | 66 |
55 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); | 67 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); |
56 }; | 68 }; |
57 | 69 |
58 } // namespace base | 70 } // namespace base |
59 | 71 |
60 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ | 72 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ |
OLD | NEW |