]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
trace: [stderr] add support for dynamically enabling/disabling events
authorLluís <xscript@gmx.net>
Wed, 31 Aug 2011 18:31:51 +0000 (20:31 +0200)
committerStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Thu, 1 Sep 2011 09:34:54 +0000 (10:34 +0100)
Uses the generic interface provided in "trace/control.h" in order to provide
a programmatic interface as well as command line and monitor controls.

Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Makefile.objs
configure
docs/tracing.txt
qemu-options.hx
scripts/tracetool
trace/stderr.c [new file with mode: 0644]
trace/stderr.h [new file with mode: 0644]

index 036a4eb6abe5820b9747ac53265e1244cde5677f..26b885bfeb23b8123afdfa37ddfe0ab84f9e8613 100644 (file)
@@ -384,6 +384,8 @@ trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o
 trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o
 trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
 
+trace-nested-$(CONFIG_TRACE_STDERR) += stderr.o
+
 trace-nested-y += control.o
 
 trace-obj-y += $(addprefix trace/, $(trace-nested-y))
index 4f9b27ced4999f9686a14dd9d11ae865643ef659..300d34bd325fd9648b8149c2a18ee923ce05f908 100755 (executable)
--- a/configure
+++ b/configure
@@ -3078,6 +3078,7 @@ if test "$trace_backend" = "simple"; then
 fi
 if test "$trace_backend" = "stderr"; then
   echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak
+  trace_default=no
 fi
 if test "$trace_backend" = "ust"; then
   echo "CONFIG_TRACE_UST=y" >> $config_host_mak
index d1d4e8cba265c63ea82a4346032eff1f8b8bbdb1..4b27ab0c2a71f0a5d094fe52069f26ff8d66238c 100644 (file)
@@ -178,11 +178,6 @@ effectively turns trace events into debug printfs.
 This is the simplest backend and can be used together with existing code that
 uses DPRINTF().
 
-Note that with this backend trace events cannot be programmatically
-enabled/disabled. Thus, in order to trim down the amount of output and the
-performance impact of tracing, you might want to add the "disable" property in
-the "trace-events" file for those events you are not interested in.
-
 === Simpletrace ===
 
 The "simple" backend supports common use cases and comes as part of the QEMU
index edd181bb8e920345b8439e4920c7d3e068b7b1cb..f672365e420162969223d8e058b41430080e2b73 100644 (file)
@@ -2454,7 +2454,8 @@ 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.
+This option is only available when using the @var{simple} and @var{stderr}
+tracing backends.
 @item file=@var{file}
 Log output traces to @var{file}.
 
index c740080ebbd8536250cf670b4f515ad20b69f0f6..743d2462893c8626bd4b72f4e6bd87544dab61cd 100755 (executable)
@@ -241,7 +241,12 @@ linetoh_begin_stderr()
 {
     cat <<EOF
 #include <stdio.h>
+#include "trace/stderr.h"
+
+extern TraceEvent trace_list[];
 EOF
+
+    stderr_event_num=0
 }
 
 linetoh_stderr()
@@ -260,29 +265,47 @@ linetoh_stderr()
     cat <<EOF
 static inline void trace_$name($args)
 {
-    fprintf(stderr, "$name $fmt\n" $argnames);
+    if (trace_list[$stderr_event_num].state != 0) {
+        fprintf(stderr, "$name $fmt\n" $argnames);
+    }
 }
 EOF
+    stderr_event_num=$((stderr_event_num + 1))
+
 }
 
 linetoh_end_stderr()
 {
-return
+    cat <<EOF
+#define NR_TRACE_EVENTS $stderr_event_num
+EOF
 }
 
 linetoc_begin_stderr()
 {
-return
+    cat <<EOF
+#include "trace.h"
+
+TraceEvent trace_list[] = {
+EOF
+    stderr_event_num=0
 }
 
 linetoc_stderr()
 {
-return
+    local name
+    name=$(get_name "$1")
+    cat <<EOF
+{.tp_name = "$name", .state=0},
+EOF
+    stderr_event_num=$(($stderr_event_num + 1))
 }
 
 linetoc_end_stderr()
 {
-return
+    cat <<EOF
+};
+EOF
 }
 #END OF STDERR
 
diff --git a/trace/stderr.c b/trace/stderr.c
new file mode 100644 (file)
index 0000000..7107c4a
--- /dev/null
@@ -0,0 +1,37 @@
+#include "trace.h"
+#include "trace/control.h"
+
+
+void trace_print_events(FILE *stream, fprintf_function stream_printf)
+{
+    unsigned int i;
+
+    for (i = 0; i < NR_TRACE_EVENTS; i++) {
+        stream_printf(stream, "%s [Event ID %u] : state %u\n",
+                      trace_list[i].tp_name, i, trace_list[i].state);
+    }
+}
+
+bool trace_event_set_state(const char *name, bool state)
+{
+    unsigned int i;
+
+    for (i = 0; i < NR_TRACE_EVENTS; i++) {
+        if (!strcmp(trace_list[i].tp_name, name)) {
+            trace_list[i].state = state;
+            return true;
+        }
+    }
+    return false;
+}
+
+bool trace_backend_init(const char *events, const char *file)
+{
+    if (file) {
+        fprintf(stderr, "error: -trace file=...: "
+                "option not supported by the selected tracing backend\n");
+        return false;
+    }
+    trace_backend_init_events(events);
+    return true;
+}
diff --git a/trace/stderr.h b/trace/stderr.h
new file mode 100644 (file)
index 0000000..d575b61
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef TRACE_STDERR_H
+#define TRACE_STDERR_H
+
+typedef uint64_t TraceEventID;
+
+typedef struct {
+    const char *tp_name;
+    bool state;
+} TraceEvent;
+
+#endif /* ! TRACE_STDERR_H */