Skip to contentSkip to conversation

trace: Add wildcard trace event support

PATCH Applied Mark Wu 2 participants 3 messages Oct 31, 2011 – Nov 1, 2011 Networking

lore
Share & tools
lore

Mark Wu

author
#0 lore raw

PATCH v2 1/1 trace: Add wildcard trace event support

A basic wildcard matching is supported in both the monitor command "trace-event" and the events list file. That means you can enable/disable the events having a common prefix in a batch. For example, virtio-blk trace events could be enabled using:
trace-event virtio_blk_* on

---
 docs/tracing.txt |    9 ++++++++-
 net/queue.c      |    1 +
 trace/simple.c   |   19 +++++++++++++++++--
 trace/stderr.c   |   17 ++++++++++++++++-
 4 files changed, 42 insertions(+), 4 deletions(-)
docs/tracing.txt +8 -1
index 95ca16c..ea29f2c 100644
@@ -132,12 +132,19 @@ This functionality is also provided through monitor commands:
   means disabled.
 
 * trace-event NAME on|off
-  Enable/disable a given trace event.
+  Enable/disable a given trace event or a group of events having common prefix
+  through wildcard.
 
 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.
 
+A basic wildcard matching is supported in both the monitor command "trace
+-event" and the events list file. That means you can enable/disable the events
+having a common prefix in a batch. For example, virtio-blk trace events could
+be enabled using:
+  trace-event virtio_blk_* on
+
 == Trace backends ==
 
 The "tracetool" script automates tedious trace event code generation and also
net/queue.c +1 -0
index 1ab5247..41ffda8 100644
@@ -258,3 +258,4 @@ void qemu_net_queue_flush(NetQueue *queue)
         g_free(packet);
     }
 }
+/*  */
trace/simple.c +17 -2
index b639dda..6339152 100644
@@ -324,14 +324,29 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
 bool trace_event_set_state(const char *name, bool state)
 {
     unsigned int i;
-
+    unsigned int len;
+    bool wildcard = false;
+    bool matched = false;
+
+    len = strlen(name);
+    if (len > 0 && name[len - 1] == '*') {
+        wildcard = true;
+        len -= 1;
+    }
     for (i = 0; i < NR_TRACE_EVENTS; i++) {
+        if (wildcard) {
+            if (!strncmp(trace_list[i].tp_name, name, len)) {
+                trace_list[i].state = state;
+                matched = true;
+            }
+            continue;
+        }
         if (!strcmp(trace_list[i].tp_name, name)) {
             trace_list[i].state = state;
             return true;
         }
     }
-    return false;
+    return matched;
 }
 
 /* Helper function to create a thread with signals blocked.  Use glib's
trace/stderr.c +16 -1
index 7107c4a..0810d6f 100644
@@ -15,14 +15,29 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
 bool trace_event_set_state(const char *name, bool state)
 {
     unsigned int i;
+    unsigned int len;
+    bool wildcard = false;
+    bool matched = false;
 
+    len = strlen(name);
+    if (len > 0 && name[len - 1] == '*') {
+        wildcard = true;
+        len -= 1;
+    }
     for (i = 0; i < NR_TRACE_EVENTS; i++) {
+        if (wildcard) {
+            if (!strncmp(trace_list[i].tp_name, name, len)) {
+                trace_list[i].state = state;
+                matched = true;
+            }
+            continue;
+        }
         if (!strcmp(trace_list[i].tp_name, name)) {
             trace_list[i].state = state;
             return true;
         }
     }
-    return false;
+    return matched;
 }
 
 bool trace_backend_init(const char *events, const char *file)
Signature · 1 line
1.7.1
#1 lore raw
Quoted 6 lines · Mark Wu

A basic wildcard matching is supported in both the monitor command "trace-event" and the events list file. That means you can enable/disable the events having a common prefix in a batch. For example, virtio-blk trace events could be enabled using:
trace-event virtio_blk_* on

Quoted 7 lines
---
 docs/tracing.txt |    9 ++++++++-
 net/queue.c      |    1 +
 trace/simple.c   |   19 +++++++++++++++++--
 trace/stderr.c   |   17 ++++++++++++++++-
 4 files changed, 42 insertions(+), 4 deletions(-)

Thanks, applied to the tracing tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing

I removed the net/queue.c hunk from the patch.

Stefan

author
#2 lore raw
Quoted 1 line · Stefan Hajnoczi
Quoted 1 line
   net/queue.c      |    1 +

Oops!
Thanks. Very sorry for that! I will be more cautious.