eina_log optimization: allow to compile out some debug messages.

Users may opt to set EINA_LOG_LEVEL_MAXIMUM to some integer and macro
will then evaluate to check for that value before actually call
eina_log_print() macro. By using optimizations compilers will
effectivelly compile out the code if it is never reached, thus saving
the check and function call in possible critical paths.



SVN revision: 42269
This commit is contained in:
Gustavo Sverzut Barbieri 2009-09-04 21:28:50 +00:00
parent e229b25826
commit b5397eea63
2 changed files with 37 additions and 0 deletions

View File

@ -94,6 +94,23 @@ if test "x$have_safety_checks" = "xyes"; then
fi
AC_SUBST(EINA_CONFIGURE_SAFETY_CHECKS)
with_max_log_level="<unset>"
AC_ARG_WITH(internal-maximum-log-level,
[AC_HELP_STRING([--with-internal-maximum-log-level=NUMBER],
[limit eina internal log level to the given number, any call to EINA_LOG() with values greater than this will be compiled out, ignoring runtime settings, but saving function calls.])],
[
if test "x${withval}" != "xno"; then
if echo "${withval}" | grep '^[[0-9]]\+$' >/dev/null 2>/dev/null; then
AC_MSG_NOTICE([ignoring any EINA_LOG() with level greater than ${withval}])
AC_DEFINE_UNQUOTED(EINA_LOG_LEVEL_MAXIMUM, ${withval}, [if set, logging is limited to this amount.])
with_max_log_level="${withval}"
else
AC_MSG_ERROR([--with-internal-maximum-log-level takes a decimal number, got "${withval}" instead.])
fi
fi
], [:])
# Choose best memory pool
AC_ARG_ENABLE([default-mempool],
[AC_HELP_STRING([--enable-default-mempool], [Default memory allocator could be faster for some computer. @<:@default=disabled@:>@])],
@ -409,6 +426,7 @@ echo "Configuration Options Summary:"
echo
echo " Magic debug..........: ${have_magic_debug}"
echo " Safety checks........: ${have_safety_checks}"
echo " Maximum log level....: ${with_max_log_level}"
echo " Report string usage..: ${have_stringshare_usage}"
echo " Default mempool......: ${have_default_mempool}"
echo " Thread Support.......: ${have_pthread}"

View File

@ -52,9 +52,28 @@ EAPI extern int EINA_LOG_DOMAIN_GLOBAL;
/**
* @def EINA_LOG(DOM, LEVEL, fmt, ...)
* Logs a message on the specified domain, level and format.
*
* @note if @c EINA_LOG_LEVEL_MAXIMUM is defined, then messages larger
* than this value will be ignored regardless of current domain
* level, the eina_log_print() is not even called! Most
* compilers will just detect the two integers make the branch
* impossible and remove the branch and function call all
* together. Take this as optimization tip and possible remove
* debug messages from binaries to be deployed, saving on hot
* paths. Never define @c EINA_LOG_LEVEL_MAXIMUM on public
* header files.
*/
#ifdef EINA_LOG_LEVEL_MAXIMUM
#define EINA_LOG(DOM, LEVEL, fmt, ...) \
do { \
if (LEVEL <= EINA_LOG_LEVEL_MAXIMUM) \
eina_log_print(DOM, LEVEL, __FILE__, __FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__); \
} while (0)
#else
#define EINA_LOG(DOM, LEVEL, fmt, ...) \
eina_log_print(DOM, LEVEL, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#endif
/**
* @def EINA_LOG_DOM_CRIT(DOM, fmt, ...)