| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Likewise Sqlite.Error.* are SPARSE, because most databases generate few or no | 44 // Likewise Sqlite.Error.* are SPARSE, because most databases generate few or no |
| 45 // errors and there are large gaps in the set of possible errors. | 45 // errors and there are large gaps in the set of possible errors. |
| 46 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ | 46 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ |
| 47 do { \ | 47 do { \ |
| 48 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \ | 48 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \ |
| 49 name, base::HistogramBase::kUmaTargetedHistogramFlag); \ | 49 name, base::HistogramBase::kUmaTargetedHistogramFlag); \ |
| 50 histogram->Add(sample); \ | 50 histogram->Add(sample); \ |
| 51 } while (0) | 51 } while (0) |
| 52 | 52 |
| 53 class HistogramSamples; | 53 class HistogramSamples; |
| 54 class PersistentMemoryAllocator; |
| 54 | 55 |
| 55 class BASE_EXPORT SparseHistogram : public HistogramBase { | 56 class BASE_EXPORT SparseHistogram : public HistogramBase { |
| 56 public: | 57 public: |
| 57 // If there's one with same name, return the existing one. If not, create a | 58 // If there's one with same name, return the existing one. If not, create a |
| 58 // new one. | 59 // new one. |
| 59 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); | 60 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); |
| 60 | 61 |
| 62 // Create a histogram using data in persistent storage. |
| 63 static scoped_ptr<HistogramBase> PersistentCreate( |
| 64 PersistentMemoryAllocator* allocator, |
| 65 const std::string& name, |
| 66 HistogramSamples::Metadata* meta, |
| 67 HistogramSamples::Metadata* logged_meta); |
| 68 |
| 61 ~SparseHistogram() override; | 69 ~SparseHistogram() override; |
| 62 | 70 |
| 63 // HistogramBase implementation: | 71 // HistogramBase implementation: |
| 64 uint64_t name_hash() const override; | 72 uint64_t name_hash() const override; |
| 65 HistogramType GetHistogramType() const override; | 73 HistogramType GetHistogramType() const override; |
| 66 bool HasConstructionArguments(Sample expected_minimum, | 74 bool HasConstructionArguments(Sample expected_minimum, |
| 67 Sample expected_maximum, | 75 Sample expected_maximum, |
| 68 uint32_t expected_bucket_count) const override; | 76 uint32_t expected_bucket_count) const override; |
| 69 void Add(Sample value) override; | 77 void Add(Sample value) override; |
| 70 void AddCount(Sample value, int count) override; | 78 void AddCount(Sample value, int count) override; |
| 71 void AddSamples(const HistogramSamples& samples) override; | 79 void AddSamples(const HistogramSamples& samples) override; |
| 72 bool AddSamplesFromPickle(base::PickleIterator* iter) override; | 80 bool AddSamplesFromPickle(base::PickleIterator* iter) override; |
| 73 scoped_ptr<HistogramSamples> SnapshotSamples() const override; | 81 scoped_ptr<HistogramSamples> SnapshotSamples() const override; |
| 74 scoped_ptr<HistogramSamples> SnapshotDelta() override; | 82 scoped_ptr<HistogramSamples> SnapshotDelta() override; |
| 75 void WriteHTMLGraph(std::string* output) const override; | 83 void WriteHTMLGraph(std::string* output) const override; |
| 76 void WriteAscii(std::string* output) const override; | 84 void WriteAscii(std::string* output) const override; |
| 77 | 85 |
| 78 protected: | 86 protected: |
| 79 // HistogramBase implementation: | 87 // HistogramBase implementation: |
| 80 bool SerializeInfoImpl(base::Pickle* pickle) const override; | 88 bool SerializeInfoImpl(base::Pickle* pickle) const override; |
| 81 | 89 |
| 82 private: | 90 private: |
| 83 // Clients should always use FactoryGet to create SparseHistogram. | 91 // Clients should always use FactoryGet to create SparseHistogram. |
| 84 explicit SparseHistogram(const std::string& name); | 92 explicit SparseHistogram(const std::string& name); |
| 85 | 93 |
| 94 SparseHistogram(PersistentMemoryAllocator* allocator, |
| 95 const std::string& name, |
| 96 HistogramSamples::Metadata* meta, |
| 97 HistogramSamples::Metadata* logged_meta); |
| 98 |
| 86 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( | 99 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( |
| 87 base::PickleIterator* iter); | 100 base::PickleIterator* iter); |
| 88 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 101 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
| 89 | 102 |
| 90 void GetParameters(DictionaryValue* params) const override; | 103 void GetParameters(DictionaryValue* params) const override; |
| 91 void GetCountAndBucketData(Count* count, | 104 void GetCountAndBucketData(Count* count, |
| 92 int64_t* sum, | 105 int64_t* sum, |
| 93 ListValue* buckets) const override; | 106 ListValue* buckets) const override; |
| 94 | 107 |
| 95 // Helpers for emitting Ascii graphic. Each method appends data to output. | 108 // Helpers for emitting Ascii graphic. Each method appends data to output. |
| 96 void WriteAsciiImpl(bool graph_it, | 109 void WriteAsciiImpl(bool graph_it, |
| 97 const std::string& newline, | 110 const std::string& newline, |
| 98 std::string* output) const; | 111 std::string* output) const; |
| 99 | 112 |
| 100 // Write a common header message describing this histogram. | 113 // Write a common header message describing this histogram. |
| 101 void WriteAsciiHeader(const Count total_count, | 114 void WriteAsciiHeader(const Count total_count, |
| 102 std::string* output) const; | 115 std::string* output) const; |
| 103 | 116 |
| 104 // For constuctor calling. | 117 // For constuctor calling. |
| 105 friend class SparseHistogramTest; | 118 friend class SparseHistogramTest; |
| 106 | 119 |
| 107 // Protects access to |samples_|. | 120 // Protects access to |samples_|. |
| 108 mutable base::Lock lock_; | 121 mutable base::Lock lock_; |
| 109 | 122 |
| 110 SampleMap samples_; | 123 scoped_ptr<HistogramSamples> samples_; |
| 111 SampleMap logged_samples_; | 124 scoped_ptr<HistogramSamples> logged_samples_; |
| 112 | 125 |
| 113 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); | 126 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); |
| 114 }; | 127 }; |
| 115 | 128 |
| 116 } // namespace base | 129 } // namespace base |
| 117 | 130 |
| 118 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ | 131 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ |
| OLD | NEW |