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

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

Issue 1726873002: Report histogram creation results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added message for why not using macro 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_HISTOGRAM_BASE_H_ 5 #ifndef BASE_METRICS_HISTOGRAM_BASE_H_
6 #define BASE_METRICS_HISTOGRAM_BASE_H_ 6 #define BASE_METRICS_HISTOGRAM_BASE_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 12 matching lines...) Expand all
23 23
24 class BucketRanges; 24 class BucketRanges;
25 class DictionaryValue; 25 class DictionaryValue;
26 class HistogramBase; 26 class HistogramBase;
27 class HistogramSamples; 27 class HistogramSamples;
28 class ListValue; 28 class ListValue;
29 class Pickle; 29 class Pickle;
30 class PickleIterator; 30 class PickleIterator;
31 31
32 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
33 // These enums are used to facilitate deserialization of histograms from other 33 // This enum is used to facilitate deserialization of histograms from other
34 // processes into the browser. If you create another class that inherits from 34 // processes into the browser. If you create another class that inherits from
35 // HistogramBase, add new histogram types and names below. 35 // HistogramBase, add new histogram types and names below.
36 36
37 enum HistogramType { 37 enum HistogramType {
38 HISTOGRAM, 38 HISTOGRAM,
39 LINEAR_HISTOGRAM, 39 LINEAR_HISTOGRAM,
40 BOOLEAN_HISTOGRAM, 40 BOOLEAN_HISTOGRAM,
41 CUSTOM_HISTOGRAM, 41 CUSTOM_HISTOGRAM,
42 SPARSE_HISTOGRAM, 42 SPARSE_HISTOGRAM,
43 }; 43 };
44 44
45 std::string HistogramTypeToString(HistogramType type); 45 std::string HistogramTypeToString(HistogramType type);
46 46
47 // This enum is used for reporting how many histograms and of what types and
48 // variations are being created. It has to be in the main .h file so it is
49 // visible to files that define the various histogram types.
50 enum HistogramReport {
51 // Count the number of reports created. The other counts divided by this
52 // number will give the average per run of the program.
53 HISTOGRAM_REPORT_CREATED,
54
55 // Count the total number of histograms created. It is the limit against
56 // which all others are compared.
57 HISTOGRAM_REPORT_HISTOGRAM_CREATED,
58
59 // Count the total number of histograms looked-up. It's better to cache
60 // the result of a single lookup rather than do it repeatedly.
61 HISTOGRAM_REPORT_HISTOGRAM_LOOKUP,
62
63 // These count the individual histogram types. This must follow the order
64 // of HistogramType above.
65 HISTOGRAM_REPORT_TYPE_LOGARITHMIC,
66 HISTOGRAM_REPORT_TYPE_LINEAR,
67 HISTOGRAM_REPORT_TYPE_BOOLEAN,
68 HISTOGRAM_REPORT_TYPE_CUSTOM,
69 HISTOGRAM_REPORT_TYPE_SPARSE,
70
71 // These indicate the individual flags that were set.
72 HISTOGRAM_REPORT_FLAG_UMA_TARGETED,
73 HISTOGRAM_REPORT_FLAG_UMA_STABILITY,
74 HISTOGRAM_REPORT_FLAG_PERSISTENT,
75
76 // This must be last.
77 HISTOGRAM_REPORT_MAX
78 };
79
47 // Create or find existing histogram that matches the pickled info. 80 // Create or find existing histogram that matches the pickled info.
48 // Returns NULL if the pickled data has problems. 81 // Returns NULL if the pickled data has problems.
49 BASE_EXPORT HistogramBase* DeserializeHistogramInfo(base::PickleIterator* iter); 82 BASE_EXPORT HistogramBase* DeserializeHistogramInfo(base::PickleIterator* iter);
50 83
51 //////////////////////////////////////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////////////
52 85
53 class BASE_EXPORT HistogramBase { 86 class BASE_EXPORT HistogramBase {
54 public: 87 public:
55 typedef int32_t Sample; // Used for samples. 88 typedef int32_t Sample; // Used for samples.
56 typedef subtle::Atomic32 AtomicCount; // Used to count samples. 89 typedef subtle::Atomic32 AtomicCount; // Used to count samples.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 204
172 // The following methods provide graphical histogram displays. 205 // The following methods provide graphical histogram displays.
173 virtual void WriteHTMLGraph(std::string* output) const = 0; 206 virtual void WriteHTMLGraph(std::string* output) const = 0;
174 virtual void WriteAscii(std::string* output) const = 0; 207 virtual void WriteAscii(std::string* output) const = 0;
175 208
176 // Produce a JSON representation of the histogram. This is implemented with 209 // Produce a JSON representation of the histogram. This is implemented with
177 // the help of GetParameters and GetCountAndBucketData; overwrite them to 210 // the help of GetParameters and GetCountAndBucketData; overwrite them to
178 // customize the output. 211 // customize the output.
179 void WriteJSON(std::string* output) const; 212 void WriteJSON(std::string* output) const;
180 213
214 // This enables a histogram that reports the what types of histograms are
215 // created and their flags. It must be called while still single-threaded.
216 //
217 // IMPORTANT: Callers must update tools/metrics/histograms/histograms.xml
218 // with the following histogram:
219 // UMA.Histograms.process_type.Creations
220 static void EnableActivityReportHistogram(const std::string& process_type);
221
181 protected: 222 protected:
223 enum ReportActivity { HISTOGRAM_CREATED, HISTOGRAM_LOOKUP };
224
182 // Subclasses should implement this function to make SerializeInfo work. 225 // Subclasses should implement this function to make SerializeInfo work.
183 virtual bool SerializeInfoImpl(base::Pickle* pickle) const = 0; 226 virtual bool SerializeInfoImpl(base::Pickle* pickle) const = 0;
184 227
185 // Writes information about the construction parameters in |params|. 228 // Writes information about the construction parameters in |params|.
186 virtual void GetParameters(DictionaryValue* params) const = 0; 229 virtual void GetParameters(DictionaryValue* params) const = 0;
187 230
188 // Writes information about the current (non-empty) buckets and their sample 231 // Writes information about the current (non-empty) buckets and their sample
189 // counts to |buckets|, the total sample count to |count| and the total sum 232 // counts to |buckets|, the total sample count to |count| and the total sum
190 // to |sum|. 233 // to |sum|.
191 virtual void GetCountAndBucketData(Count* count, 234 virtual void GetCountAndBucketData(Count* count,
(...skipping 11 matching lines...) Expand all
203 // Write textual description of the bucket contents (relative to histogram). 246 // Write textual description of the bucket contents (relative to histogram).
204 // Output is the count in the buckets, as well as the percentage. 247 // Output is the count in the buckets, as well as the percentage.
205 void WriteAsciiBucketValue(Count current, 248 void WriteAsciiBucketValue(Count current,
206 double scaled_sum, 249 double scaled_sum,
207 std::string* output) const; 250 std::string* output) const;
208 251
209 // Retrieves the callback for this histogram, if one exists, and runs it 252 // Retrieves the callback for this histogram, if one exists, and runs it
210 // passing |sample| as the parameter. 253 // passing |sample| as the parameter.
211 void FindAndRunCallback(Sample sample) const; 254 void FindAndRunCallback(Sample sample) const;
212 255
256 // Update report with an |activity| that occurred for |histogram|.
257 static void ReportHistogramActivity(HistogramBase* histogram,
258 ReportActivity activicty);
259
260 // Retrieves the global histogram reporting what histograms are created.
261 static HistogramBase* report_histogram_;
262
213 private: 263 private:
264 friend class HistogramBaseTest;
265
214 const std::string histogram_name_; 266 const std::string histogram_name_;
215 AtomicCount flags_; 267 AtomicCount flags_;
216 268
217 DISALLOW_COPY_AND_ASSIGN(HistogramBase); 269 DISALLOW_COPY_AND_ASSIGN(HistogramBase);
218 }; 270 };
219 271
220 } // namespace base 272 } // namespace base
221 273
222 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ 274 #endif // BASE_METRICS_HISTOGRAM_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698