Chromium Code Reviews| 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_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 Loading... | |
| 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_GENERAL, | |
| 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 Loading... | |
| 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 EnableCreationReportHistogram(StringPiece process_type); | |
| 221 | |
| 181 protected: | 222 protected: |
| 182 // Subclasses should implement this function to make SerializeInfo work. | 223 // Subclasses should implement this function to make SerializeInfo work. |
| 183 virtual bool SerializeInfoImpl(base::Pickle* pickle) const = 0; | 224 virtual bool SerializeInfoImpl(base::Pickle* pickle) const = 0; |
| 184 | 225 |
| 185 // Writes information about the construction parameters in |params|. | 226 // Writes information about the construction parameters in |params|. |
| 186 virtual void GetParameters(DictionaryValue* params) const = 0; | 227 virtual void GetParameters(DictionaryValue* params) const = 0; |
| 187 | 228 |
| 188 // Writes information about the current (non-empty) buckets and their sample | 229 // 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 | 230 // counts to |buckets|, the total sample count to |count| and the total sum |
| 190 // to |sum|. | 231 // to |sum|. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 203 // Write textual description of the bucket contents (relative to histogram). | 244 // Write textual description of the bucket contents (relative to histogram). |
| 204 // Output is the count in the buckets, as well as the percentage. | 245 // Output is the count in the buckets, as well as the percentage. |
| 205 void WriteAsciiBucketValue(Count current, | 246 void WriteAsciiBucketValue(Count current, |
| 206 double scaled_sum, | 247 double scaled_sum, |
| 207 std::string* output) const; | 248 std::string* output) const; |
| 208 | 249 |
| 209 // Retrieves the callback for this histogram, if one exists, and runs it | 250 // Retrieves the callback for this histogram, if one exists, and runs it |
| 210 // passing |sample| as the parameter. | 251 // passing |sample| as the parameter. |
| 211 void FindAndRunCallback(Sample sample) const; | 252 void FindAndRunCallback(Sample sample) const; |
| 212 | 253 |
| 254 // Update the creation (or lookup) report for a histogram. | |
|
Alexei Svitkine (slow)
2016/03/01 16:41:34
Document the |created| param, please. Also I think
bcwhite
2016/03/02 19:14:19
Done.
| |
| 255 static void UpdateReportHistogram(HistogramBase* histogram, bool created); | |
| 256 | |
| 257 // Retrieves the global histogram reporting what histograms are created. | |
| 258 static HistogramBase* report_histogram_; | |
| 259 | |
| 213 private: | 260 private: |
| 261 friend class HistogramBaseTest; | |
| 262 | |
| 214 const std::string histogram_name_; | 263 const std::string histogram_name_; |
| 215 AtomicCount flags_; | 264 AtomicCount flags_; |
| 216 | 265 |
| 217 DISALLOW_COPY_AND_ASSIGN(HistogramBase); | 266 DISALLOW_COPY_AND_ASSIGN(HistogramBase); |
| 218 }; | 267 }; |
| 219 | 268 |
| 220 } // namespace base | 269 } // namespace base |
| 221 | 270 |
| 222 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ | 271 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |
| OLD | NEW |