Patchwork [RFC,v1,1/4] qemu-log: Allow checking of the current mask

login
register
mail settings
Submitter Peter Crosthwaite
Date March 3, 2013, 6:13 a.m.
Message ID <3671922c9400f7a40c802c9a522f9b85c350340f.1362290776.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/224532/
State New
Headers show

Comments

Peter Crosthwaite - March 3, 2013, 6:13 a.m.
Useful for heavy users of qemu_log_mask that want to avoid executing expensive
logic that sets up a qemu_log_mask when that mask is disabled. E.G.

if (qemu_log_get_mask() && LOG_GUEST_ERROR) {
	/* do my expensive logging data query */
}
qemu_log_mask(LOG_GUEST_ERROR, ...)

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 include/qemu/log.h |    2 ++
 qemu-log.c         |    5 +++++
 2 files changed, 7 insertions(+), 0 deletions(-)
Peter Maydell - March 3, 2013, 10:32 a.m.
On 3 March 2013 06:13, Peter Crosthwaite <peter.crosthwaite@xilinx.com> wrote:
> Useful for heavy users of qemu_log_mask that want to avoid executing expensive
> logic that sets up a qemu_log_mask when that mask is disabled. E.G.
>
> if (qemu_log_get_mask() && LOG_GUEST_ERROR) {
>         /* do my expensive logging data query */
> }
> qemu_log_mask(LOG_GUEST_ERROR, ...)

Why can't you use the existing
  if (qemu_loglevel_mask(LOG_GUEST_ERROR) {
      /* expensive thing */
  }
?

-- PMM

Patch

diff --git a/include/qemu/log.h b/include/qemu/log.h
index 6b0db02..68188f0 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -154,6 +154,8 @@  static inline void qemu_set_log(int log_flags)
 #endif
 }
 
+int qemu_get_log_flags(void);
+
 void qemu_set_log_filename(const char *filename);
 int qemu_str_to_log_mask(const char *str);
 
diff --git a/qemu-log.c b/qemu-log.c
index 797f2af..2ffee1d 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -82,6 +82,11 @@  void do_qemu_set_log(int log_flags, bool use_own_buffers)
     }
 }
 
+int qemu_get_log_flags(void)
+{
+    return qemu_loglevel;
+}
+
 void qemu_set_log_filename(const char *filename)
 {
     g_free(logfilename);