qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH v6 10/14] trace-state: add "-trace events" argument


From: Lluís
Subject: [Qemu-devel] [PATCH v6 10/14] trace-state: add "-trace events" argument to control initial state
Date: Thu, 25 Aug 2011 17:52:37 +0200
User-agent: StGit/0.15

The "-trace events" argument can be used to provide a file with a list of trace
event names that will be enabled prior to starting execution, thus providing
early tracing.

This saves the user from manually toggling event states through the monitor
interface or whichever backend-specific interface.

Signed-off-by: Lluís Vilanova <address@hidden>
---
 docs/tracing.txt |    4 ++++
 qemu-config.c    |    3 +++
 qemu-options.hx  |   26 +++++++++++++++++++-------
 trace/control.c  |   30 ++++++++++++++++++++++++++++++
 trace/control.h  |    2 ++
 vl.c             |    1 +
 6 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/docs/tracing.txt b/docs/tracing.txt
index 017ff59..963d002 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -129,6 +129,10 @@ This functionality is also provided through monitor 
commands:
 * trace-event NAME on|off
   Enable/disable a given trace event.
 
+The "-trace events=<file>" command line argument can be used to enable the
+events listed in <file> from the very beginning of the program. This file must
+contain one event name per line.
+
 == Trace backends ==
 
 The "tracetool" script automates tedious trace event code generation and also
diff --git a/qemu-config.c b/qemu-config.c
index f67d3a5..cd519ec 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -308,6 +308,9 @@ static QemuOptsList qemu_trace_opts = {
     .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
     .desc = {
         {
+            .name = "events",
+            .type = QEMU_OPT_STRING,
+        },{
             .name = "file",
             .type = QEMU_OPT_STRING,
         },
diff --git a/qemu-options.hx b/qemu-options.hx
index d6421b9..91144d9 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2433,17 +2433,29 @@ Normally QEMU loads a configuration file from 
@var{sysconfdir}/qemu.conf and
 option will prevent QEMU from loading these configuration files at startup.
 ETEXI
 DEF("trace", HAS_ARG, QEMU_OPTION_trace,
-    "-trace\n"
-    "                Specify a trace file to log traces to\n",
+    "-trace [events=<file>][,file=<file>]\n"
+    "                specify tracing options\n",
     QEMU_ARCH_ALL)
 STEXI
-HXCOMM This line is not accurate, as the option is backend-specific but HX does
-HXCOMM not support conditional compilation of text.
address@hidden -trace
+HXCOMM This line is not accurate, as some sub-options are backend-specific but
+HXCOMM HX does not support conditional compilation of text.
address@hidden -trace address@hidden,address@hidden
 @findex -trace
-Specify a trace file to log output traces to.
 
-This option is available only when using the @var{simple} tracing backend.
+Specify tracing options.
+
address@hidden @option
address@hidden address@hidden
+Immediately enable events listed in @var{file}.
+The file must contain one event name (as listed in the @var{trace-events} file)
+per line.
+
+This option is only available when using the @var{simple} tracing backend.
address@hidden address@hidden
+Log output traces to @var{file}.
+
+This option is only available when using the @var{simple} tracing backend.
address@hidden table
 ETEXI
 
 HXCOMM This is the last statement. Insert new options before this line!
diff --git a/trace/control.c b/trace/control.c
index b27ba30..1ba451b 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -32,3 +32,33 @@ bool trace_config_init_file (const char *file)
 {
     return false;
 }
+
+void trace_config_init_events (const char *fname)
+{
+    if (fname == NULL) {
+        return;
+    }
+
+    FILE *fp = fopen(fname, "r");
+    if (!fp) {
+        fprintf(stderr, "could not open trace events file '%s': %s\n",
+                fname, strerror(errno));
+        exit(1);
+    }
+    char line_buf[1024];
+    while (fgets(line_buf, sizeof(line_buf), fp)) {
+        size_t len = strlen(line_buf);
+        if (len > 1) {              /* skip empty lines */
+            line_buf[len - 1] = '\0';
+            if (!trace_event_set_state(line_buf, true)) {
+                fprintf(stderr, "qemu: error: trace event '%s' does not 
exist\n", line_buf);
+                exit(1);
+            }
+        }
+    }
+    if (fclose(fp) != 0) {
+        fprintf(stderr, "qemu: error: closing file '%s': %s\n",
+                fname, strerror(errno));
+        exit(1);
+    }
+}
diff --git a/trace/control.h b/trace/control.h
index d1e277b..5c30489 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -31,4 +31,6 @@ bool trace_config_init (void) QEMU_WEAK;
  */
 bool trace_config_init_file (const char *file) QEMU_WEAK;
 
+void trace_config_init_events (const char *fname);
+
 #endif  /* TRACE_CONTROL_H */
diff --git a/vl.c b/vl.c
index ed2db9a..e9619a6 100644
--- a/vl.c
+++ b/vl.c
@@ -2946,6 +2946,7 @@ int main(int argc, char **argv, char **envp)
                             popt->name);
                     exit(1);
                 }
+                trace_config_init_events(qemu_opt_get(opts, "events"));
                 break;
             }
             case QEMU_OPTION_readconfig:




reply via email to

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