| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // Write textual description of the bucket contents (relative to histogram). | 256 // Write textual description of the bucket contents (relative to histogram). |
| 255 // Output is the count in the buckets, as well as the percentage. | 257 // Output is the count in the buckets, as well as the percentage. |
| 256 void WriteAsciiBucketValue(Count current, | 258 void WriteAsciiBucketValue(Count current, |
| 257 double scaled_sum, | 259 double scaled_sum, |
| 258 std::string* output) const; | 260 std::string* output) const; |
| 259 | 261 |
| 260 // Retrieves the callback for this histogram, if one exists, and runs it | 262 // Retrieves the callback for this histogram, if one exists, and runs it |
| 261 // passing |sample| as the parameter. | 263 // passing |sample| as the parameter. |
| 262 void FindAndRunCallback(Sample sample) const; | 264 void FindAndRunCallback(Sample sample) const; |
| 263 | 265 |
| 266 // Gets a permanent string that can be used for histogram objects when the |
| 267 // original is not a code constant or held in persistent memory. |
| 268 static const char* GetPermanentName(const std::string& name); |
| 269 |
| 264 // Update report with an |activity| that occurred for |histogram|. | 270 // Update report with an |activity| that occurred for |histogram|. |
| 265 static void ReportHistogramActivity(const HistogramBase& histogram, | 271 static void ReportHistogramActivity(const HistogramBase& histogram, |
| 266 ReportActivity activicty); | 272 ReportActivity activicty); |
| 267 | 273 |
| 268 // Retrieves the global histogram reporting what histograms are created. | 274 // Retrieves the global histogram reporting what histograms are created. |
| 269 static HistogramBase* report_histogram_; | 275 static HistogramBase* report_histogram_; |
| 270 | 276 |
| 271 private: | 277 private: |
| 272 friend class HistogramBaseTest; | 278 friend class HistogramBaseTest; |
| 273 | 279 |
| 274 const std::string histogram_name_; | 280 // A pointer to permanent storage where the histogram name is held. This can |
| 281 // be code space or the output of GetPermanentName() or any other storage |
| 282 // that is known to never change. This is not StringPiece because (a) char* |
| 283 // is 1/2 the size and (b) StringPiece transparently casts from std::string |
| 284 // which can easily lead to a pointer to non-permanent space. |
| 285 const char* const histogram_name_; |
| 286 |
| 287 // Additional information about the histogram. |
| 275 AtomicCount flags_; | 288 AtomicCount flags_; |
| 276 | 289 |
| 277 DISALLOW_COPY_AND_ASSIGN(HistogramBase); | 290 DISALLOW_COPY_AND_ASSIGN(HistogramBase); |
| 278 }; | 291 }; |
| 279 | 292 |
| 280 } // namespace base | 293 } // namespace base |
| 281 | 294 |
| 282 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ | 295 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |
| OLD | NEW |