Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: base/metrics/sparse_histogram.h

Issue 1734033003: Add support for persistent sparse histograms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed more review comments by Alexei Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Get a histogram using data in persistent storage.
63 static HistogramBase* PersistentGet(PersistentMemoryAllocator* allocator,
64 const std::string& name,
65 HistogramSamples::Metadata* meta,
66 HistogramSamples::Metadata* logged_meta);
67
61 ~SparseHistogram() override; 68 ~SparseHistogram() override;
62 69
63 // HistogramBase implementation: 70 // HistogramBase implementation:
64 uint64_t name_hash() const override; 71 uint64_t name_hash() const override;
65 HistogramType GetHistogramType() const override; 72 HistogramType GetHistogramType() const override;
66 bool HasConstructionArguments(Sample expected_minimum, 73 bool HasConstructionArguments(Sample expected_minimum,
67 Sample expected_maximum, 74 Sample expected_maximum,
68 uint32_t expected_bucket_count) const override; 75 uint32_t expected_bucket_count) const override;
69 void Add(Sample value) override; 76 void Add(Sample value) override;
70 void AddCount(Sample value, int count) override; 77 void AddCount(Sample value, int count) override;
71 void AddSamples(const HistogramSamples& samples) override; 78 void AddSamples(const HistogramSamples& samples) override;
72 bool AddSamplesFromPickle(base::PickleIterator* iter) override; 79 bool AddSamplesFromPickle(base::PickleIterator* iter) override;
73 scoped_ptr<HistogramSamples> SnapshotSamples() const override; 80 scoped_ptr<HistogramSamples> SnapshotSamples() const override;
74 scoped_ptr<HistogramSamples> SnapshotDelta() override; 81 scoped_ptr<HistogramSamples> SnapshotDelta() override;
75 void WriteHTMLGraph(std::string* output) const override; 82 void WriteHTMLGraph(std::string* output) const override;
76 void WriteAscii(std::string* output) const override; 83 void WriteAscii(std::string* output) const override;
77 84
78 protected: 85 protected:
79 // HistogramBase implementation: 86 // HistogramBase implementation:
80 bool SerializeInfoImpl(base::Pickle* pickle) const override; 87 bool SerializeInfoImpl(base::Pickle* pickle) const override;
81 88
82 private: 89 private:
83 // Clients should always use FactoryGet to create SparseHistogram. 90 // Clients should always use FactoryGet to create SparseHistogram.
84 explicit SparseHistogram(const std::string& name); 91 explicit SparseHistogram(const std::string& name);
85 92
93 SparseHistogram(PersistentMemoryAllocator* allocator,
94 const std::string& name,
95 HistogramSamples::Metadata* meta,
96 HistogramSamples::Metadata* logged_meta);
97
86 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 98 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
87 base::PickleIterator* iter); 99 base::PickleIterator* iter);
88 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 100 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
89 101
90 void GetParameters(DictionaryValue* params) const override; 102 void GetParameters(DictionaryValue* params) const override;
91 void GetCountAndBucketData(Count* count, 103 void GetCountAndBucketData(Count* count,
92 int64_t* sum, 104 int64_t* sum,
93 ListValue* buckets) const override; 105 ListValue* buckets) const override;
94 106
95 // Helpers for emitting Ascii graphic. Each method appends data to output. 107 // Helpers for emitting Ascii graphic. Each method appends data to output.
96 void WriteAsciiImpl(bool graph_it, 108 void WriteAsciiImpl(bool graph_it,
97 const std::string& newline, 109 const std::string& newline,
98 std::string* output) const; 110 std::string* output) const;
99 111
100 // Write a common header message describing this histogram. 112 // Write a common header message describing this histogram.
101 void WriteAsciiHeader(const Count total_count, 113 void WriteAsciiHeader(const Count total_count,
102 std::string* output) const; 114 std::string* output) const;
103 115
104 // For constuctor calling. 116 // For constuctor calling.
105 friend class SparseHistogramTest; 117 friend class SparseHistogramTest;
106 118
107 // Protects access to |samples_|. 119 // Protects access to |samples_|.
108 mutable base::Lock lock_; 120 mutable base::Lock lock_;
109 121
110 SampleMap samples_; 122 scoped_ptr<HistogramSamples> samples_;
111 SampleMap logged_samples_; 123 scoped_ptr<HistogramSamples> logged_samples_;
112 124
113 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); 125 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
114 }; 126 };
115 127
116 } // namespace base 128 } // namespace base
117 129
118 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ 130 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698