qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>, Lluís <xscript@gmx.net>,
	"Fabien Chouteau" <chouteau@adacore.com>,
	"Lluís Vilanova" <vilanova@ac.upc.edu>
Subject: [Qemu-devel] [PATCH 13/15] trace: [stderr] add support for dynamically enabling/disabling events
Date: Thu,  1 Sep 2011 09:06:24 +0100	[thread overview]
Message-ID: <1314864386-14202-14-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1314864386-14202-1-git-send-email-stefanha@linux.vnet.ibm.com>

From: Lluís <xscript@gmx.net>

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     |    2 ++
 configure         |    1 +
 docs/tracing.txt  |    5 -----
 qemu-options.hx   |    3 ++-
 scripts/tracetool |   33 ++++++++++++++++++++++++++++-----
 trace/stderr.c    |   37 +++++++++++++++++++++++++++++++++++++
 trace/stderr.h    |   11 +++++++++++
 7 files changed, 81 insertions(+), 11 deletions(-)
 create mode 100644 trace/stderr.c
 create mode 100644 trace/stderr.h

diff --git a/Makefile.objs b/Makefile.objs
index 036a4eb..26b885b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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))
diff --git a/configure b/configure
index 4f9b27c..300d34b 100755
--- 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
diff --git a/docs/tracing.txt b/docs/tracing.txt
index d1d4e8c..4b27ab0 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -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
diff --git a/qemu-options.hx b/qemu-options.hx
index edd181b..f672365 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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}.
 
diff --git a/scripts/tracetool b/scripts/tracetool
index c740080..743d246 100755
--- a/scripts/tracetool
+++ b/scripts/tracetool
@@ -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
index 0000000..7107c4a
--- /dev/null
+++ b/trace/stderr.c
@@ -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
index 0000000..d575b61
--- /dev/null
+++ b/trace/stderr.h
@@ -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 */
-- 
1.7.5.4

  parent reply	other threads:[~2011-09-01  8:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-01  8:06 [Qemu-devel] [PULL 00/15] Tracing patches Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 01/15] build: Fix linkage of QEMU_PROG Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 02/15] build: [simple] Include qemu-timer-common.o in trace-obj-y Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 03/15] trace: [configure] rename CONFIG_*_TRACE into CONFIG_TRACE_* Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 04/15] trace: [make] replace 'ifeq' with values in CONFIG_TRACE_* Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 05/15] trace: move backend-specific code into the trace/ directory Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 06/15] trace: avoid conditional code compilation during option parsing Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 07/15] trace: generalize the "property" concept in the trace-events file Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 08/15] trace: separate trace event control and query routines from the simple backend Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 09/15] trace: always compile support for controlling and querying trace event states Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 10/15] trace: add "-trace events" argument to control initial state Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 11/15] trace: always use the "nop" backend on events with the "disable" keyword Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 12/15] trace: [simple] disable all trace points by default Stefan Hajnoczi
2011-09-01  8:06 ` Stefan Hajnoczi [this message]
2011-09-01  8:06 ` [Qemu-devel] [PATCH 14/15] trace: enable all events Stefan Hajnoczi
2011-09-01  8:06 ` [Qemu-devel] [PATCH 15/15] simpletrace: fix process() argument count Stefan Hajnoczi
2011-09-01 19:08 ` [Qemu-devel] [PULL 00/15] Tracing patches Anthony Liguori
2011-09-02  9:39   ` Stefan Hajnoczi
2011-09-02 14:54     ` Anthony Liguori
2011-09-02 15:00       ` Anthony Liguori
2011-09-02 15:30       ` Lluís Vilanova

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1314864386-14202-14-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=chouteau@adacore.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vilanova@ac.upc.edu \
    --cc=xscript@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).