aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/logging.h
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-11-17 11:52:25 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-02-29 14:30:14 +0100
commita89d22c0f08edda927ce62b071f17bd7e5edc5c6 (patch)
treea79be82af3c6b4ea5888a10b109be7f4c80e08fd /include/osmocom/core/logging.h
parentde6dd72dbbbcc7facf25c4a2521c71f653c7b1b2 (diff)
log: Add conditional logging based on log_check_level
Currently the LOGP/DEBUGP arguments are always evaluated even if no logging will happen at all. This can be expensive, for instance if hexdumps or pretty printed object names are generated. This causes high base load especially on embedded devices and is a major part of CPU usage e.g. of the osmo-pcu. This commit uses the log_check_level function to avoid the evaluation of the parameters if it is known in advance, that no logging entry will be generated. Sponsored-by: On-Waves ehf
Diffstat (limited to 'include/osmocom/core/logging.h')
-rw-r--r--include/osmocom/core/logging.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 290b33d..e51487b 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -19,8 +19,18 @@
#define DEBUG
#ifdef DEBUG
-#define DEBUGP(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 0, fmt, ## args)
-#define DEBUGPC(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 1, fmt, ## args)
+#define DEBUGP(ss, fmt, args...) \
+ do { \
+ if (log_check_level(ss, LOGL_DEBUG)) \
+ logp(ss, __FILE__, __LINE__, 0, fmt, ## args); \
+ } while(0)
+
+#define DEBUGPC(ss, fmt, args...) \
+ do { \
+ if (log_check_level(ss, LOGL_DEBUG)) \
+ logp(ss, __FILE__, __LINE__, 1, fmt, ## args); \
+ } while(0)
+
#else
#define DEBUGP(xss, fmt, args...)
#define DEBUGPC(ss, fmt, args...)
@@ -39,7 +49,10 @@ void logp(int subsys, const char *file, int line, int cont, const char *format,
* \param[in] args variable argument list
*/
#define LOGP(ss, level, fmt, args...) \
- logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args)
+ do { \
+ if (log_check_level(ss, level)) \
+ logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args); \
+ } while(0)
/*! \brief Continue a log message through the Osmocom logging framework
* \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
@@ -48,7 +61,10 @@ void logp(int subsys, const char *file, int line, int cont, const char *format,
* \param[in] args variable argument list
*/
#define LOGPC(ss, level, fmt, args...) \
- logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args)
+ do { \
+ if (log_check_level(ss, level)) \
+ logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \
+ } while(0)
/*! \brief different log levels */
#define LOGL_DEBUG 1 /*!< \brief debugging information */