[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qe
From: |
Alex Bennée |
Subject: |
Re: [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled |
Date: |
Thu, 15 Oct 2015 18:23:19 +0100 |
User-agent: |
mu4e 0.9.13; emacs 24.5.50.4 |
Denis V. Lunev <address@hidden> 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.
>
> 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 <address@hidden>
> Signed-off-by: Pavel Butsykin <address@hidden>
> CC: Markus Armbruster <address@hidden>
> CC: Luiz Capitulino <address@hidden>
> CC: Eric Blake <address@hidden>
> CC: Peter Maydell <address@hidden>
> ---
> 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)
>
I've had one of Peter's patches in my logging improvements queue for a
while although it uses a slightly different form which I prefer:
-/* 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__); \
+ } \
See the message:
qemu-log: Avoid function call for disabled qemu_log_mask logging
> /* 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)
--
Alex Bennée
- Re: [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event), (continued)
- Re: [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
- Re: [Qemu-devel] What's the intended use of log.h logging?, Denis V. Lunev, 2015/10/21
- Re: [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/21
- Re: [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/22
- Re: [Qemu-devel] What's the intended use of log.h logging?, Paolo Bonzini, 2015/10/22
[Qemu-devel] [PATCH 3/3] log: adds a timestamp to each log entry, Denis V. Lunev, 2015/10/15
[Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled, Denis V. Lunev, 2015/10/15
- Re: [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled,
Alex Bennée <=
Re: [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled, Markus Armbruster, 2015/10/16
Re: [Qemu-devel] [PATCH 0/3] QEMU logging improvements, Kashyap Chamarthy, 2015/10/15
Re: [Qemu-devel] [PATCH 0/3] QEMU logging improvements, Markus Armbruster, 2015/10/26