qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 7/9] trace: convert stderr backend to log


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 7/9] trace: convert stderr backend to log
Date: Sun, 25 Oct 2015 14:35:03 +0100

Signed-off-by: Paolo Bonzini <address@hidden>
---
 configure                                       |  4 ++--
 include/qemu/log.h                              |  1 +
 qemu-log.c                                      |  3 +++
 scripts/tracetool/backend/{stderr.py => log.py} |  9 +++++----
 trace/control.c                                 | 10 ++++++++++
 vl.c                                            |  2 ++
 6 files changed, 23 insertions(+), 6 deletions(-)
 rename scripts/tracetool/backend/{stderr.py => log.py} (78%)

diff --git a/configure b/configure
index 2a129bb..d803e67 100755
--- a/configure
+++ b/configure
@@ -5299,8 +5299,8 @@ if have_backend "simple"; then
   # Set the appropriate trace file.
   trace_file="\"$trace_file-\" FMT_pid"
 fi
-if have_backend "stderr"; then
-  echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak
+if have_backend "log"; then
+  echo "CONFIG_TRACE_LOG=y" >> $config_host_mak
 fi
 if have_backend "ust"; then
   echo "CONFIG_TRACE_UST=y" >> $config_host_mak
diff --git a/include/qemu/log.h b/include/qemu/log.h
index ed57a3d..5a0fbe3 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -38,6 +38,7 @@ static inline bool qemu_log_enabled(void)
 #define LOG_GUEST_ERROR    (1 << 11)
 #define CPU_LOG_MMU        (1 << 12)
 #define CPU_LOG_TB_NOCHAIN (1 << 13)
+#define LOG_TRACE          (1 << 14)
 
 /* Returns true if a bit is set in the current loglevel mask
  */
diff --git a/qemu-log.c b/qemu-log.c
index efd07c8..5c641a0 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -51,6 +51,9 @@ void qemu_log_mask(int mask, const char *fmt, ...)
 void do_qemu_set_log(int log_flags, bool use_own_buffers)
 {
     qemu_loglevel = log_flags;
+#ifdef CONFIG_TRACE_LOG
+    qemu_loglevel |= LOG_TRACE;
+#endif
     if (qemu_loglevel && !qemu_logfile) {
         if (logfilename) {
             qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
diff --git a/scripts/tracetool/backend/stderr.py 
b/scripts/tracetool/backend/log.py
similarity index 78%
rename from scripts/tracetool/backend/stderr.py
rename to scripts/tracetool/backend/log.py
index ca58054..a62c310 100644
--- a/scripts/tracetool/backend/stderr.py
+++ b/scripts/tracetool/backend/log.py
@@ -25,6 +25,7 @@ def generate_h_begin(events):
         '#include <sys/types.h>',
         '#include <unistd.h>',
         '#include "trace/control.h"',
+        '#include "qemu/log.h"',
         '')
 
 
@@ -36,10 +37,10 @@ def generate_h(event):
     out('    if (trace_event_get_state(%(event_id)s)) {',
         '        struct timeval _now;',
         '        gettimeofday(&_now, NULL);',
-        '        fprintf(stderr, "address@hidden:%(name)s " %(fmt)s "\\n",',
-        '                        getpid(),',
-        '                        (size_t)_now.tv_sec, (size_t)_now.tv_usec',
-        '                        %(argnames)s);',
+        '        qemu_log_mask(LOG_TRACE, "address@hidden:%(name)s " %(fmt)s 
"\\n",',
+        '                      getpid(),',
+        '                      (size_t)_now.tv_sec, (size_t)_now.tv_usec',
+        '                      %(argnames)s);',
         '    }',
         event_id="TRACE_" + event.name.upper(),
         name=event.name,
diff --git a/trace/control.c b/trace/control.c
index 7c84795..9a1e381 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -14,6 +14,9 @@
 #ifdef CONFIG_TRACE_FTRACE
 #include "trace/ftrace.h"
 #endif
+#ifdef CONFIG_TRACE_LOG
+#include "qemu/log.h"
+#endif
 #include "qemu/error-report.h"
 
 TraceEvent *trace_event_name(const char *name)
@@ -171,6 +174,13 @@ void trace_init_file(const char *file)
 {
 #ifdef CONFIG_TRACE_SIMPLE
     st_set_trace_file(file);
+#elif defined CONFIG_TRACE_LOG
+    /* If both the simple and the log backends are enabled, "-trace file"
+     * only applies to the simple backend; use "-D" for the log backend.
+     */
+    if (file) {
+        qemu_set_log_filename(file);
+    }
 #else
     if (file) {
         fprintf(stderr, "error: -trace file=...: "
diff --git a/vl.c b/vl.c
index a465f69..a45bd2b 100644
--- a/vl.c
+++ b/vl.c
@@ -4088,6 +4088,8 @@ int main(int argc, char **argv, char **envp)
             exit(1);
         }
         qemu_set_log(mask);
+    } else {
+        qemu_set_log(0);
     }
 
     if (!is_daemonized()) {
-- 
2.5.0





reply via email to

[Prev in Thread] Current Thread [Next in Thread]