diff mbox

[v3,4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging

Message ID 1406811992-6766-5-git-send-email-alex.bennee@linaro.org
State Superseded
Headers show

Commit Message

Alex Bennée July 31, 2014, 1:06 p.m. UTC
From: Peter Maydell <peter.maydell@linaro.org>

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 <peter.maydell@linaro.org>

Comments

Andreas Färber Aug. 11, 2014, 11:14 a.m. UTC | #1
Am 31.07.2014 14:06, schrieb Alex Bennée:
> From: Peter Maydell <peter.maydell@linaro.org>
> 
> 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 <peter.maydell@linaro.org>

Lacking your Sob as submitter. If you fix that,
Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas
diff mbox

Patch

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)
 {