qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Prerna Saxena <prerna@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm@vger.kernel.org, Jan Kiszka <jan.kiszka@siemens.com>,
	Luiz Capitulino <lcapitulino@redhat.com>,
	Soni <maneesh@linux.vnet.ibm.com>,
	Ananth Narayan <ananth@linux.vnet.ibm.com>,
	Maneesh@gnu.org
Subject: [Qemu-devel] [RFC v4][PATCH 3/3] Support for dynamically enabling/disabling trace events.
Date: Thu, 24 Jun 2010 17:04:53 +0530	[thread overview]
Message-ID: <20100624170453.344fb729@zephyr> (raw)
In-Reply-To: <20100624164930.7859b779@zephyr>

This patch adds support for dynamically enabling/disabling of trace events.
This is done by internally maintaining each trace event's state, and 
permitting logging of data from a trace event only if it is in an 
'active' state.

Monitor commands added :
1) info trace-events 		: to view all available trace events and 
				  their state.
2) trace-event NAME on|off 	: to enable/disable data logging from a 
				  given trace event.
				  Eg, trace-event paio_submit off 
				  	disables logging of data when 
					paio_submit is hit.

By default, all trace-events are disabled. One can enable desired trace-events 
via the monitor.

Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
---
 monitor.c       |   16 ++++++++++++++++
 qemu-monitor.hx |   18 ++++++++++++++++++
 simpletrace.c   |   41 +++++++++++++++++++++++++++++++++++++++++
 tracetool       |   33 +++++++++++++++++++++++++++++----
 4 files changed, 104 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 8b60830..19b1ed7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -548,6 +548,15 @@ static void do_commit(Monitor *mon, const QDict *qdict)
     }
 }
 
+#ifdef CONFIG_SIMPLE_TRACE
+static void do_change_trace_event_state(Monitor *mon, const QDict *qdict)
+{
+    const char *tp_name = qdict_get_str(qdict, "name");
+    bool new_state = qdict_get_bool(qdict, "option");
+    change_trace_event_state(tp_name, new_state);
+}
+#endif
+
 static void user_monitor_complete(void *opaque, QObject *ret_data)
 {
     MonitorCompletionData *data = (MonitorCompletionData *)opaque; 
@@ -2791,6 +2800,13 @@ static const mon_cmd_t info_cmds[] = {
         .help       = "show current contents of trace buffer",
         .mhandler.info = do_info_trace,
     },
+    {
+        .name       = "trace-events",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show available trace-events & their state",
+        .mhandler.info = do_info_all_trace_events,
+    },
 #endif
     {
         .name       = NULL,
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 766c30f..0fedcf9 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -117,6 +117,8 @@ show device tree
 #ifdef CONFIG_SIMPLE_TRACE
 @item info trace
 show contents of trace buffer
+@item info trace-events
+show available trace events and their state
 #endif
 @end table
 ETEXI
@@ -225,6 +227,22 @@ STEXI
 @item logfile @var{filename}
 @findex logfile
 Output logs to @var{filename}.
+#ifdef CONFIG_SIMPLE_TRACE
+ETEXI
+
+    {
+        .name       = "trace-event",
+        .args_type  = "name:s,option:b",
+        .params     = "name on|off",
+        .help       = "changes status of a specific trace event",
+        .mhandler.cmd = do_change_trace_event_state,
+    },
+
+STEXI
+@item trace-event
+@findex trace-event
+changes status of a trace event
+#endif
 ETEXI
 
     {
diff --git a/simpletrace.c b/simpletrace.c
index 5734d15..57c41fc 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -24,6 +24,11 @@ static void trace(TraceEventID event, unsigned long x1,
                   unsigned long x2, unsigned long x3,
                   unsigned long x4, unsigned long x5) {
     TraceRecord *rec = &trace_buf[trace_idx];
+
+    if (!trace_list[event].state) {
+        return;
+    }
+
     rec->event = event;
     rec->x1 = x1;
     rec->x2 = x2;
@@ -74,3 +79,39 @@ void do_info_trace(Monitor *mon)
                             trace_buf[i].x3, trace_buf[i].x4, trace_buf[i].x5);
     }
 }
+
+void do_info_all_trace_events(Monitor *mon)
+{
+    unsigned int i;
+
+    for (i = 0; i < NR_TRACE_EVENTS; i++) {
+        monitor_printf(mon, "%s [Event ID %u] : state %u\n",
+                                trace_list[i].tp_name, i, trace_list[i].state);
+    }
+}
+
+static TraceEvent* find_trace_event_by_name(const char *tname)
+{
+    unsigned int i;
+
+    if (!tname) {
+        return NULL;
+    }
+
+    for (i = 0; i < NR_TRACE_EVENTS; i++) {
+        if (!strcmp(trace_list[i].tp_name, tname)) {
+            return &trace_list[i];
+        }
+    }
+    return NULL; /* indicates end of list reached without a match */
+}
+
+void change_trace_event_state(const char *tname, bool tstate)
+{
+    TraceEvent *tp;
+
+    tp = find_trace_event_by_name(tname);
+    if (tp) {
+        tp->state = tstate;
+    }
+}
diff --git a/tracetool b/tracetool
index 6f8f8a9..9e8dbd8 100755
--- a/tracetool
+++ b/tracetool
@@ -123,14 +123,23 @@ linetoc_end_nop()
 linetoh_begin_simple()
 {
     cat <<EOF
+#include <stdbool.h>
+
 typedef unsigned int TraceEventID;
 
+typedef struct {
+    const char *tp_name;
+    bool state;
+} TraceEvent;
+
 void trace1(TraceEventID event, unsigned long x1);
 void trace2(TraceEventID event, unsigned long x1, unsigned long x2);
 void trace3(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3);
 void trace4(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4);
 void trace5(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4, unsigned long x5);
 void do_info_trace(Monitor *mon);
+void do_info_all_trace_events(Monitor *mon);
+void change_trace_event_state(const char *tname, bool tstate);
 EOF
 
     simple_event_num=0
@@ -163,22 +172,38 @@ EOF
 
 linetoh_end_simple()
 {
-    return
+    cat <<EOF
+#define NR_TRACE_EVENTS $simple_event_num
+extern TraceEvent trace_list[NR_TRACE_EVENTS];
+EOF
 }
 
 linetoc_begin_simple()
 {
-    return
+    cat <<EOF
+#include "trace.h"
+
+TraceEvent trace_list[] = {
+EOF
+    simple_event_num=0
+
 }
 
 linetoc_simple()
 {
-    return
+    local name
+    name=$(get_name "$1")
+    cat <<EOF
+{.tp_name = "$name", .state=0},
+EOF
+    simple_event_num=$((simple_event_num + 1))
 }
 
 linetoc_end_simple()
 {
-    return
+    cat <<EOF
+};
+EOF
 }
 
 linetoh_begin_ust()
-- 
1.6.2.5



-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India

  parent reply	other threads:[~2010-06-24 11:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-24 11:19 [Qemu-devel] [RFC v4][PATCH 0/3] Monitor support for Qemu tracing Prerna Saxena
2010-06-24 11:28 ` [Qemu-devel] [RFC v4][PATCH 1/3] Change type declarations Prerna Saxena
2010-06-24 11:31 ` [Qemu-devel] [RFC v4][PATCH 2/3] Monitor command 'info trace' Prerna Saxena
2010-06-24 11:34 ` Prerna Saxena [this message]
2010-06-24 15:13 ` [Qemu-devel] Re: [RFC v4][PATCH 0/3] Monitor support for Qemu tracing Stefan Hajnoczi

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=20100624170453.344fb729@zephyr \
    --to=prerna@linux.vnet.ibm.com \
    --cc=Maneesh@gnu.org \
    --cc=aliguori@us.ibm.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=lcapitulino@redhat.com \
    --cc=maneesh@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /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).