diff options
-rw-r--r-- | base/metrics/histogram.h | 4 | ||||
-rw-r--r-- | base/metrics/histogram_base.cc | 6 | ||||
-rw-r--r-- | base/metrics/histogram_base.h | 12 |
3 files changed, 16 insertions, 6 deletions
diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h index 7a6c688..02f3ac4 100644 --- a/base/metrics/histogram.h +++ b/base/metrics/histogram.h @@ -155,8 +155,8 @@ class Lock; base::subtle::Release_Store(&atomic_histogram_pointer, \ reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); \ } \ - DCHECK_EQ(histogram_pointer->histogram_name(), \ - std::string(constant_histogram_name)); \ + if (DCHECK_IS_ON()) \ + histogram_pointer->CheckName(constant_histogram_name); \ histogram_pointer->histogram_add_method_invocation; \ } while (0) diff --git a/base/metrics/histogram_base.cc b/base/metrics/histogram_base.cc index 5c6e2d2..6e7e69e 100644 --- a/base/metrics/histogram_base.cc +++ b/base/metrics/histogram_base.cc @@ -20,7 +20,7 @@ namespace base { std::string HistogramTypeToString(HistogramType type) { - switch(type) { + switch (type) { case HISTOGRAM: return "HISTOGRAM"; case LINEAR_HISTOGRAM: @@ -66,6 +66,10 @@ HistogramBase::HistogramBase(const std::string& name) HistogramBase::~HistogramBase() {} +void HistogramBase::CheckName(const StringPiece& name) const { + DCHECK_EQ(histogram_name(), name); +} + void HistogramBase::SetFlags(int32 flags) { flags_ |= flags; } diff --git a/base/metrics/histogram_base.h b/base/metrics/histogram_base.h index f3e9b46..be07fc6 100644 --- a/base/metrics/histogram_base.h +++ b/base/metrics/histogram_base.h @@ -12,6 +12,7 @@ #include "base/base_export.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "base/strings/string_piece.h" #include "base/time/time.h" class Pickle; @@ -48,8 +49,8 @@ BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( class BASE_EXPORT HistogramBase { public: - typedef int Sample; // Used for samples. - typedef subtle::Atomic32 AtomicCount; // Used to count samples. + typedef int Sample; // Used for samples. + typedef subtle::Atomic32 AtomicCount; // Used to count samples. typedef int32 Count; // Used to manipulate counts in temporaries. static const Sample kSampleType_MAX; // INT_MAX @@ -92,6 +93,11 @@ class BASE_EXPORT HistogramBase { std::string histogram_name() const { return histogram_name_; } + // Comapres |name| to the histogram name and triggers a DCHECK if they do not + // match. This is a helper function used by histogram macros, which results in + // in more compact machine code being generated by the macros. + void CheckName(const StringPiece& name) const; + // Operations with Flags enum. int32 flags() const { return flags_; } void SetFlags(int32 flags); @@ -137,7 +143,7 @@ class BASE_EXPORT HistogramBase { // customize the output. void WriteJSON(std::string* output) const; -protected: + protected: // Subclasses should implement this function to make SerializeInfo work. virtual bool SerializeInfoImpl(Pickle* pickle) const = 0; |