From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCq4I-00008X-8t for qemu-devel@nongnu.org; Thu, 31 Jul 2014 09:06:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCq47-0001EX-3w for qemu-devel@nongnu.org; Thu, 31 Jul 2014 09:06:50 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:50092 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCq46-0001EL-UF for qemu-devel@nongnu.org; Thu, 31 Jul 2014 09:06:39 -0400 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Thu, 31 Jul 2014 14:06:27 +0100 Message-Id: <1406811992-6766-5-git-send-email-alex.bennee@linaro.org> In-Reply-To: <1406811992-6766-1-git-send-email-alex.bennee@linaro.org> References: <1406811992-6766-1-git-send-email-alex.bennee@linaro.org> Subject: [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , l@dorileo.org From: Peter Maydell 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. Signed-off-by: Peter Maydell diff --git a/include/qemu/log.h b/include/qemu/log.h index d515424..da22e13 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -64,10 +64,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-log.c b/qemu-log.c index 35bbb56..83e0cb4 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -36,17 +36,6 @@ 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); -} - /* enable or disable low levels log */ void do_qemu_set_log(int log_flags, bool use_own_buffers) { -- 2.0.3