From 66e1bacd643207e4b51b254f4c5f7f18094cf6c8 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 22 Feb 2018 09:32:40 -0500 Subject: [PATCH] qemu-log: Avoid function call for disabled qemu_log_mask logging Make qemu_log_mask() a macro which only calls the function to do the actual work if the logging is enabled. This avoids making a function call in possible fast paths where logging is disabled. Backports commit 7ee606230e6b7645d92365d9b39179368e83ac54 from qemu --- qemu/include/qemu/log.h | 13 ++++++++++--- qemu/qemu-log.c | 12 ------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/qemu/include/qemu/log.h b/qemu/include/qemu/log.h index 22700eab..0d68e2e4 100644 --- a/qemu/include/qemu/log.h +++ b/qemu/include/qemu/log.h @@ -62,10 +62,17 @@ qemu_log_vprintf(const char *fmt, va_list va) } } -/* log only if a bit is set on the current loglevel mask +/* log only if a bit is set on the current loglevel mask: + * @mask: bit to check in the mask + * @fmt: printf-style format string + * @args: optional arguments for format string */ -void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); - +#define qemu_log_mask(MASK, FMT, ...) \ + do { \ + if (unlikely(qemu_loglevel_mask(MASK))) { \ + qemu_log(FMT, ## __VA_ARGS__); \ + } \ + } while (0) /* Special cases: */ diff --git a/qemu/qemu-log.c b/qemu/qemu-log.c index a8be9274..39432fdb 100644 --- a/qemu/qemu-log.c +++ b/qemu/qemu-log.c @@ -34,15 +34,3 @@ void qemu_log(const char *fmt, ...) } va_end(ap); } - -void qemu_log_mask(int mask, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - if ((qemu_loglevel & mask) && qemu_logfile) { - vfprintf(qemu_logfile, fmt, ap); - } - va_end(ap); -} -