diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-15 03:11:45 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-15 03:11:45 +0000 |
commit | 5bfd0a44f68943ec285d9453e4ed7097b668c3de (patch) | |
tree | 369feacb755052e5c88cd44f3bc3babd61dcce0e | |
parent | 471021725505ede2d3b057a9d5363e20869b6bee (diff) | |
download | chromium_src-5bfd0a44f68943ec285d9453e4ed7097b668c3de.zip chromium_src-5bfd0a44f68943ec285d9453e4ed7097b668c3de.tar.gz chromium_src-5bfd0a44f68943ec285d9453e4ed7097b668c3de.tar.bz2 |
Make code generated for histogram macros more compact.
In builds where DCHECKs are compiled in (e.g. developer
builds and Chrome Canaries), the DCHECK_EQ() in the
histogram macro was expanding to a lot of generated
machine code.
This CL moves that DCHECK() to a function instead, so that the
code is not duplicated in every call site. The function call is
wrapped behind a DCHECK_IS_ON() conditional, so that it will
still be omitted if DCHECKs are not compiled into the build.
Makes my Chromium release build smaller by over 1MB,
measuring size of Chromium Framework.
Before size: 146547380
After size: 145400692
BUG=343946
TEST=No functional changes.
Review URL: https://codereview.chromium.org/167343002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251486 0039d316-1c4b-4281-b951-d872f2087c98
-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; |