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
parent 47102172
...@@ -155,8 +155,8 @@ class Lock; ...@@ -155,8 +155,8 @@ class Lock;
base::subtle::Release_Store(&atomic_histogram_pointer, \ base::subtle::Release_Store(&atomic_histogram_pointer, \
reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); \ reinterpret_cast<base::subtle::AtomicWord>(histogram_pointer)); \
} \ } \
DCHECK_EQ(histogram_pointer->histogram_name(), \ if (DCHECK_IS_ON()) \
std::string(constant_histogram_name)); \ histogram_pointer->CheckName(constant_histogram_name); \
histogram_pointer->histogram_add_method_invocation; \ histogram_pointer->histogram_add_method_invocation; \
} while (0) } while (0)
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
namespace base { namespace base {
std::string HistogramTypeToString(HistogramType type) { std::string HistogramTypeToString(HistogramType type) {
switch(type) { switch (type) {
case HISTOGRAM: case HISTOGRAM:
return "HISTOGRAM"; return "HISTOGRAM";
case LINEAR_HISTOGRAM: case LINEAR_HISTOGRAM:
...@@ -66,6 +66,10 @@ HistogramBase::HistogramBase(const std::string& name) ...@@ -66,6 +66,10 @@ HistogramBase::HistogramBase(const std::string& name)
HistogramBase::~HistogramBase() {} HistogramBase::~HistogramBase() {}
void HistogramBase::CheckName(const StringPiece& name) const {
DCHECK_EQ(histogram_name(), name);
}
void HistogramBase::SetFlags(int32 flags) { void HistogramBase::SetFlags(int32 flags) {
flags_ |= flags; flags_ |= flags;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
#include "base/time/time.h" #include "base/time/time.h"
class Pickle; class Pickle;
...@@ -48,8 +49,8 @@ BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( ...@@ -48,8 +49,8 @@ BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
class BASE_EXPORT HistogramBase { class BASE_EXPORT HistogramBase {
public: public:
typedef int Sample; // Used for samples. typedef int Sample; // Used for samples.
typedef subtle::Atomic32 AtomicCount; // Used to count samples. typedef subtle::Atomic32 AtomicCount; // Used to count samples.
typedef int32 Count; // Used to manipulate counts in temporaries. typedef int32 Count; // Used to manipulate counts in temporaries.
static const Sample kSampleType_MAX; // INT_MAX static const Sample kSampleType_MAX; // INT_MAX
...@@ -92,6 +93,11 @@ class BASE_EXPORT HistogramBase { ...@@ -92,6 +93,11 @@ class BASE_EXPORT HistogramBase {
std::string histogram_name() const { return histogram_name_; } 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. // Operations with Flags enum.
int32 flags() const { return flags_; } int32 flags() const { return flags_; }
void SetFlags(int32 flags); void SetFlags(int32 flags);
...@@ -137,7 +143,7 @@ class BASE_EXPORT HistogramBase { ...@@ -137,7 +143,7 @@ class BASE_EXPORT HistogramBase {
// customize the output. // customize the output.
void WriteJSON(std::string* output) const; void WriteJSON(std::string* output) const;
protected: protected:
// Subclasses should implement this function to make SerializeInfo work. // Subclasses should implement this function to make SerializeInfo work.
virtual bool SerializeInfoImpl(Pickle* pickle) const = 0; virtual bool SerializeInfoImpl(Pickle* pickle) const = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment