diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 07:31:09 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 07:31:09 +0000 |
commit | ddb9b33b95c5fe0224c92292ea53d8bcd5637a54 (patch) | |
tree | e02b1a90c101e5e18d16bf2adfdd30341a101ce5 /base/logging.h | |
parent | 5310c4cfc1cd1b3d5e7c5a066703b1f2c528d2e9 (diff) | |
download | chromium_src-ddb9b33b95c5fe0224c92292ea53d8bcd5637a54.zip chromium_src-ddb9b33b95c5fe0224c92292ea53d8bcd5637a54.tar.gz chromium_src-ddb9b33b95c5fe0224c92292ea53d8bcd5637a54.tar.bz2 |
Make CHECK not print messages in official builds
This cuts down on the number of strings in the executable, as well as
executable code to print them.
On Linux, this saves 208kb on a stripped official build
(chrome executable file went from 64569072 bytes -> 64782064 bytes)
On OS X, this saves 209kb on an official build (Google Chrome Framework went from 51483872 bytes -> 51274984 bytes)
On Windows, this saves 139kb on an official build (chrome.dll went from 28619264 bytes -> 28477440 bytes)
Fix test failure in logging_unittest.cc in official builds.
Add new executable check_example for easy testing of changes to the
CHECK macros.
BUG=101561
TEST=
Review URL: http://codereview.chromium.org/8734021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/logging.h')
-rw-r--r-- | base/logging.h | 79 |
1 files changed, 52 insertions, 27 deletions
diff --git a/base/logging.h b/base/logging.h index 647f580..ae67eac 100644 --- a/base/logging.h +++ b/base/logging.h @@ -13,6 +13,7 @@ #include "base/base_export.h" #include "base/basictypes.h" +#include "base/debug/debugger.h" #include "build/build_config.h" // @@ -442,12 +443,44 @@ const LogSeverity LOG_0 = LOG_ERROR; #define PLOG_IF(severity, condition) \ LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) +// http://crbug.com/16512 is open for a real fix for this. For now, Windows +// uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is +// defined. +#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \ + (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD)) +#define LOGGING_IS_OFFICIAL_BUILD 1 +#else +#define LOGGING_IS_OFFICIAL_BUILD 0 +#endif + +// The actual stream used isn't important. +#define EAT_STREAM_PARAMETERS \ + true ? (void) 0 : ::logging::LogMessageVoidify() & LOG_STREAM(FATAL) + // CHECK dies with a fatal error if condition is not true. It is *not* // controlled by NDEBUG, so the check will be executed regardless of // compilation mode. // // We make sure CHECK et al. always evaluates their arguments, as // doing CHECK(FunctionWithSideEffect()) is a common idiom. + +#if LOGGING_IS_OFFICIAL_BUILD + +// Make all CHECK functions discard their log strings to reduce code +// bloat for official builds. + +// TODO(akalin): This would be more valuable if there were some way to +// remove BreakDebugger() from the backtrace, perhaps by turning it +// into a macro (like __debugbreak() on Windows). +#define CHECK(condition) \ + !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS + +#define PCHECK(condition) CHECK(condition) + +#define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) + +#else + #define CHECK(condition) \ LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \ << "Check failed: " #condition ". " @@ -456,6 +489,19 @@ const LogSeverity LOG_0 = LOG_ERROR; LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ << "Check failed: " #condition ". " +// Helper macro for binary operators. +// Don't use this macro directly in your code, use CHECK_EQ et al below. +// +// TODO(akalin): Rewrite this so that constructs like if (...) +// CHECK_EQ(...) else { ... } work properly. +#define CHECK_OP(name, op, val1, val2) \ + if (std::string* _result = \ + logging::Check##name##Impl((val1), (val2), \ + #val1 " " #op " " #val2)) \ + logging::LogMessage(__FILE__, __LINE__, _result).stream() + +#endif + // Build the error message string. This is separate from the "Impl" // function template because it is not performance critical and so can // be out of line, while the "Impl" code should be inline. Caller @@ -488,17 +534,6 @@ std::string* MakeCheckOpString<std::string, std::string>( const std::string&, const std::string&, const char* name); #endif -// Helper macro for binary operators. -// Don't use this macro directly in your code, use CHECK_EQ et al below. -// -// TODO(akalin): Rewrite this so that constructs like if (...) -// CHECK_EQ(...) else { ... } work properly. -#define CHECK_OP(name, op, val1, val2) \ - if (std::string* _result = \ - logging::Check##name##Impl((val1), (val2), \ - #val1 " " #op " " #val2)) \ - logging::LogMessage(__FILE__, __LINE__, _result).stream() - // Helper functions for CHECK_OP macro. // The (int, int) specialization works around the issue that the compiler // will not instantiate the template version of the function on values of @@ -529,14 +564,7 @@ DEFINE_CHECK_OP_IMPL(GT, > ) #define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) -// http://crbug.com/16512 is open for a real fix for this. For now, Windows -// uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is -// defined. -#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \ - (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD)) -// Used by unit tests. -#define LOGGING_IS_OFFICIAL_BUILD - +#if LOGGING_IS_OFFICIAL_BUILD // In order to have optimized code for official builds, remove DLOGs and // DCHECKs. #define ENABLE_DLOG 0 @@ -572,15 +600,12 @@ DEFINE_CHECK_OP_IMPL(GT, > ) // is not defined). Contrast this with DCHECK et al., which has // different behavior. -#define DLOG_EAT_STREAM_PARAMETERS \ - true ? (void) 0 : ::logging::LogMessageVoidify() & LOG_STREAM(FATAL) - #define DLOG_IS_ON(severity) false -#define DLOG_IF(severity, condition) DLOG_EAT_STREAM_PARAMETERS -#define DLOG_ASSERT(condition) DLOG_EAT_STREAM_PARAMETERS -#define DPLOG_IF(severity, condition) DLOG_EAT_STREAM_PARAMETERS -#define DVLOG_IF(verboselevel, condition) DLOG_EAT_STREAM_PARAMETERS -#define DVPLOG_IF(verboselevel, condition) DLOG_EAT_STREAM_PARAMETERS +#define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS +#define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS +#define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS +#define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS +#define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS #endif // ENABLE_DLOG |