From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiN80-0004z7-Ef for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiN7z-0006j0-Dx for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiN7z-0006iW-8T for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:47 -0400 From: Paolo Bonzini Date: Tue, 22 Mar 2016 15:16:58 +0100 Message-Id: <1458656229-32043-19-git-send-email-pbonzini@redhat.com> In-Reply-To: <1458656229-32043-1-git-send-email-pbonzini@redhat.com> References: <1458656229-32043-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 18/29] 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 , =?UTF-8?q?Alex=20Benn=C3=A9e?= 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 Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Andreas F=C3=A4rber Signed-off-by: Paolo Bonzini --- include/qemu/log.h | 13 ++++++++++--- util/log.c | 11 ----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index 40c24fd..523c886 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -66,10 +66,17 @@ qemu_log_vprintf(const char *fmt, va_list va) } } =20 -/* 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) =20 /* Maintenance: */ =20 diff --git a/util/log.c b/util/log.c index a14d480..4e69586 100644 --- a/util/log.c +++ b/util/log.c @@ -38,17 +38,6 @@ void qemu_log(const char *fmt, ...) va_end(ap); } =20 -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) { --=20 2.5.0