From: Markus Armbruster <armbru@redhat.com>
To: "Denis V. Lunev" <den@openvz.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Luiz Capitulino <lcapitulino@redhat.com>,
qemu-devel@nongnu.org, Pavel Butsykin <pbutsykin@virtuozzo.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled
Date: Fri, 16 Oct 2015 09:17:57 +0200 [thread overview]
Message-ID: <871tcvth7e.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1444894224-9542-2-git-send-email-den@openvz.org> (Denis V. Lunev's message of "Thu, 15 Oct 2015 10:30:22 +0300")
"Denis V. Lunev" <den@openvz.org> writes:
> 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.
Really? We use __VA_ARGS__ all over the place, why won't it work here?
> 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 <den@openvz.org>
> Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
> CC: Markus Armbruster <armbru@redhat.com>
> CC: Luiz Capitulino <lcapitulino@redhat.com>
> CC: Eric Blake <eblake@redhat.com>
> CC: Peter Maydell <peter.maydell@linaro.org>
> ---
> 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)
Feels stilted. Like Alex's, I'd prefer something like
#define qemu_log(fmt, ...) \
do { \
if (unlikely(qemu_log_enabled())) { \
fprintf(qemu_logfile, fmt, ## __VA_ARGS__); \
} \
} while (0)
I'm no fan of hiding qemu_logfile in qemu_log_enabled(), then using it
directly to print to it, but that's a different conversation.
However, we already have
static inline void GCC_FMT_ATTR(1, 0)
qemu_log_vprintf(const char *fmt, va_list va)
{
if (qemu_logfile) {
vfprintf(qemu_logfile, fmt, va);
}
}
Wouldn't static inline work for qemu_log(), too?
> /* 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)
I support the general approach to inline the "is logging on" test
somehow.
next prev parent reply other threads:[~2015-10-16 7:18 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 7:30 [Qemu-devel] [PATCH 0/3] QEMU logging improvements Denis V. Lunev
2015-10-15 7:30 ` [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled Denis V. Lunev
2015-10-15 17:23 ` Alex Bennée
2015-10-15 17:40 ` Denis V. Lunev
2015-10-15 18:36 ` Alex Bennée
2015-10-16 7:17 ` Markus Armbruster [this message]
2015-10-16 7:45 ` Denis V. Lunev
2015-10-16 11:02 ` Markus Armbruster
2015-10-16 11:08 ` Denis V. Lunev
2015-10-15 7:30 ` [Qemu-devel] [PATCH 2/3] log: report hmp/qmp command and qmp event Denis V. Lunev
2015-10-16 7:34 ` Markus Armbruster
2015-10-16 9:51 ` Pavel Butsykin
2015-10-16 12:35 ` Markus Armbruster
2015-10-16 12:33 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Markus Armbruster
2015-10-16 12:48 ` [Qemu-devel] What's the intended use of log.h logging? Paolo Bonzini
2015-10-16 12:54 ` Peter Maydell
2015-10-16 13:00 ` Paolo Bonzini
2015-10-16 13:38 ` Denis V. Lunev
2015-10-16 13:26 ` Daniel P. Berrange
2015-10-16 13:29 ` Peter Maydell
2015-10-16 13:30 ` Paolo Bonzini
2015-10-16 13:36 ` Peter Maydell
2015-10-16 14:17 ` Paolo Bonzini
2015-10-16 14:31 ` Peter Maydell
2015-10-16 15:27 ` Paolo Bonzini
2015-10-19 13:17 ` Markus Armbruster
2015-10-19 13:19 ` Paolo Bonzini
2015-10-19 13:54 ` Peter Maydell
2015-10-16 12:51 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Peter Maydell
2015-10-19 14:29 ` [Qemu-devel] What's the intended use of log.h logging? Markus Armbruster
2015-10-19 14:41 ` Peter Maydell
2015-10-19 16:57 ` Dr. David Alan Gilbert
2015-10-19 17:02 ` Dr. David Alan Gilbert
2015-10-20 13:11 ` Kevin Wolf
2015-10-16 14:36 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Alex Bennée
2015-10-19 14:52 ` [Qemu-devel] What's the intended use of log.h logging? Markus Armbruster
2015-10-19 14:57 ` Peter Maydell
2015-10-21 10:41 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Stefan Hajnoczi
2015-10-21 11:10 ` [Qemu-devel] What's the intended use of log.h logging? Denis V. Lunev
2015-10-21 12:22 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Peter Maydell
2015-10-22 12:26 ` Stefan Hajnoczi
2015-10-22 13:05 ` [Qemu-devel] What's the intended use of log.h logging? Paolo Bonzini
2015-10-15 7:30 ` [Qemu-devel] [PATCH 3/3] log: adds a timestamp to each log entry Denis V. Lunev
2015-10-16 7:49 ` Markus Armbruster
2015-10-16 9:55 ` Pavel Butsykin
2015-10-16 11:33 ` Markus Armbruster
2015-10-15 14:49 ` [Qemu-devel] [PATCH 0/3] QEMU logging improvements Kashyap Chamarthy
2015-10-15 15:18 ` Pavel Butsykin
2015-10-15 16:02 ` Kashyap Chamarthy
2015-10-26 9:16 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871tcvth7e.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=den@openvz.org \
--cc=lcapitulino@redhat.com \
--cc=pbutsykin@virtuozzo.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.