| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 enum Inconsistency : uint32_t { | 126 enum Inconsistency : uint32_t { |
| 127 NO_INCONSISTENCIES = 0x0, | 127 NO_INCONSISTENCIES = 0x0, |
| 128 RANGE_CHECKSUM_ERROR = 0x1, | 128 RANGE_CHECKSUM_ERROR = 0x1, |
| 129 BUCKET_ORDER_ERROR = 0x2, | 129 BUCKET_ORDER_ERROR = 0x2, |
| 130 COUNT_HIGH_ERROR = 0x4, | 130 COUNT_HIGH_ERROR = 0x4, |
| 131 COUNT_LOW_ERROR = 0x8, | 131 COUNT_LOW_ERROR = 0x8, |
| 132 | 132 |
| 133 NEVER_EXCEEDED_VALUE = 0x10, | 133 NEVER_EXCEEDED_VALUE = 0x10, |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 explicit HistogramBase(const std::string& name); | 136 // Construct the base histogram. The name is not copied; it's up to the |
| 137 // caller to ensure that it lives at least as long as this object. |
| 138 explicit HistogramBase(const char* name); |
| 137 virtual ~HistogramBase(); | 139 virtual ~HistogramBase(); |
| 138 | 140 |
| 139 const std::string& histogram_name() const { return histogram_name_; } | 141 const char* histogram_name() const { return histogram_name_; } |
| 140 | 142 |
| 141 // Comapres |name| to the histogram name and triggers a DCHECK if they do not | 143 // Comapres |name| to the histogram name and triggers a DCHECK if they do not |
| 142 // match. This is a helper function used by histogram macros, which results in | 144 // match. This is a helper function used by histogram macros, which results in |
| 143 // in more compact machine code being generated by the macros. | 145 // in more compact machine code being generated by the macros. |
| 144 void CheckName(const StringPiece& name) const; | 146 void CheckName(const StringPiece& name) const; |
| 145 | 147 |
| 146 // Get a unique ID for this histogram's samples. | 148 // Get a unique ID for this histogram's samples. |
| 147 virtual uint64_t name_hash() const = 0; | 149 virtual uint64_t name_hash() const = 0; |
| 148 | 150 |
| 149 // Operations with Flags enum. | 151 // Operations with Flags enum. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Write textual description of the bucket contents (relative to histogram). | 252 // Write textual description of the bucket contents (relative to histogram). |
| 251 // Output is the count in the buckets, as well as the percentage. | 253 // Output is the count in the buckets, as well as the percentage. |
| 252 void WriteAsciiBucketValue(Count current, | 254 void WriteAsciiBucketValue(Count current, |
| 253 double scaled_sum, | 255 double scaled_sum, |
| 254 std::string* output) const; | 256 std::string* output) const; |
| 255 | 257 |
| 256 // Retrieves the callback for this histogram, if one exists, and runs it | 258 // Retrieves the callback for this histogram, if one exists, and runs it |
| 257 // passing |sample| as the parameter. | 259 // passing |sample| as the parameter. |
| 258 void FindAndRunCallback(Sample sample) const; | 260 void FindAndRunCallback(Sample sample) const; |
| 259 | 261 |
| 262 // Gets a permanent string that can be used for histogram objects when the |
| 263 // original is not a code constant or held in persistent memory. |
| 264 static const char* GetPermanentName(const std::string& name); |
| 265 |
| 260 // Update report with an |activity| that occurred for |histogram|. | 266 // Update report with an |activity| that occurred for |histogram|. |
| 261 static void ReportHistogramActivity(const HistogramBase& histogram, | 267 static void ReportHistogramActivity(const HistogramBase& histogram, |
| 262 ReportActivity activicty); | 268 ReportActivity activicty); |
| 263 | 269 |
| 264 // Retrieves the global histogram reporting what histograms are created. | 270 // Retrieves the global histogram reporting what histograms are created. |
| 265 static HistogramBase* report_histogram_; | 271 static HistogramBase* report_histogram_; |
| 266 | 272 |
| 267 private: | 273 private: |
| 268 friend class HistogramBaseTest; | 274 friend class HistogramBaseTest; |
| 269 | 275 |
| 270 const std::string histogram_name_; | 276 // A pointer to permanent storage where the histogram name is held. This can |
| 277 // be code space or the output of GetPermanentName() or any other storage |
| 278 // that is known to never change. This is not StringPiece because (a) char* |
| 279 // is 1/2 the size and (b) StringPiece transparently casts from std::string |
| 280 // which can easily lead to a pointer to non-permanent space. |
| 281 const char* const histogram_name_; |
| 282 |
| 283 // Additional information about the histogram. |
| 271 AtomicCount flags_; | 284 AtomicCount flags_; |
| 272 | 285 |
| 273 DISALLOW_COPY_AND_ASSIGN(HistogramBase); | 286 DISALLOW_COPY_AND_ASSIGN(HistogramBase); |
| 274 }; | 287 }; |
| 275 | 288 |
| 276 } // namespace base | 289 } // namespace base |
| 277 | 290 |
| 278 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ | 291 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |
| OLD | NEW |