From patchwork Thu Oct 15 07:30:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 530538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 53FCA1402D0 for ; Thu, 15 Oct 2015 18:32:27 +1100 (AEDT) Received: from localhost ([::1]:46200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmd1V-0003Np-C4 for incoming@patchwork.ozlabs.org; Thu, 15 Oct 2015 03:32:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmczw-00027x-Fs for qemu-devel@nongnu.org; Thu, 15 Oct 2015 03:30:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zmczo-00033K-Gu for qemu-devel@nongnu.org; Thu, 15 Oct 2015 03:30:43 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:26227 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmczo-0002vF-3e for qemu-devel@nongnu.org; Thu, 15 Oct 2015 03:30:40 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t9F7UOwo018866; Thu, 15 Oct 2015 10:30:28 +0300 (MSK) From: "Denis V. Lunev" To: Date: Thu, 15 Oct 2015 10:30:22 +0300 Message-Id: <1444894224-9542-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444894224-9542-1-git-send-email-den@openvz.org> References: <1444894224-9542-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Peter Maydell , Pavel Butsykin , Markus Armbruster , qemu-devel@nongnu.org, Luiz Capitulino , "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The patch is intended to avoid to perform any operation including calculation of log function arguments when the log is not enabled due to various reasons. Functions qemu_log and qemu_log_mask are replaced with variadic macros. Unfortunately the code is not C99 compatible and we can not use portable __VA_ARGS__ way. There are a lot of warnings in the other places with --std=c99. Thus the only way to achive the result is to use args.. GCC extension. Format checking performed by compiler will not suffer by this patch. It will be done inside in fprintf arguments checking. Signed-off-by: Denis V. Lunev Signed-off-by: Pavel Butsykin CC: Markus Armbruster CC: Luiz Capitulino CC: Eric Blake CC: Peter Maydell --- include/qemu/log.h | 17 ++++++++++++++--- qemu-log.c | 21 --------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index f880e66..57b8c96 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -53,7 +53,13 @@ static inline bool qemu_loglevel_mask(int mask) /* main logging function */ -void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); +#define qemu_log(args...) \ + do { \ + if (!qemu_log_enabled()) { \ + break; \ + } \ + fprintf(qemu_logfile, args); \ + } while (0) /* vfprintf-like logging function */ @@ -67,8 +73,13 @@ qemu_log_vprintf(const char *fmt, va_list va) /* log only if a bit is set on the current loglevel mask */ -void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); - +#define qemu_log_mask(mask, args...) \ + do { \ + if (!qemu_loglevel_mask(mask)) { \ + break; \ + } \ + qemu_log(args); \ + } while (0) /* Special cases: */ diff --git a/qemu-log.c b/qemu-log.c index 13f3813..e6d2b3f 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -25,27 +25,6 @@ FILE *qemu_logfile; int qemu_loglevel; static int log_append = 0; -void qemu_log(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - if (qemu_logfile) { - vfprintf(qemu_logfile, fmt, ap); - } - 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)