* [Qemu-devel] [PATCH] Add wildcard trace event support
@ 2011-10-20 9:38 Mark Wu
2011-10-21 1:37 ` Mars.Cao
2011-10-28 9:47 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Mark Wu @ 2011-10-20 9:38 UTC (permalink / raw)
To: stefanha; +Cc: qemu-devel
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
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
---
docs/tracing.txt | 9 ++++++++-
trace/simple.c | 19 +++++++++++++++++--
trace/stderr.c | 17 ++++++++++++++++-
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/docs/tracing.txt b/docs/tracing.txt
index 95ca16c..ea29f2c 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -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
diff --git a/trace/simple.c b/trace/simple.c
index b639dda..869e315 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -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 (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
diff --git a/trace/stderr.c b/trace/stderr.c
index 7107c4a..6a12977 100644
--- a/trace/stderr.c
+++ b/trace/stderr.c
@@ -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 (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)
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Add wildcard trace event support
2011-10-20 9:38 [Qemu-devel] [PATCH] Add wildcard trace event support Mark Wu
@ 2011-10-21 1:37 ` Mars.Cao
2011-10-28 9:47 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Mars.Cao @ 2011-10-21 1:37 UTC (permalink / raw)
To: Mark Wu; +Cc: stefanha, qemu-devel
On 10/20/2011 05:38 PM, Mark Wu wrote:
> 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
>
> Signed-off-by: Mark Wu<wudxw@linux.vnet.ibm.com>
> ---
> docs/tracing.txt | 9 ++++++++-
> trace/simple.c | 19 +++++++++++++++++--
> trace/stderr.c | 17 ++++++++++++++++-
> 3 files changed, 41 insertions(+), 4 deletions(-)
>
> diff --git a/docs/tracing.txt b/docs/tracing.txt
> index 95ca16c..ea29f2c 100644
> --- a/docs/tracing.txt
> +++ b/docs/tracing.txt
> @@ -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
> diff --git a/trace/simple.c b/trace/simple.c
> index b639dda..869e315 100644
> --- a/trace/simple.c
> +++ b/trace/simple.c
> @@ -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 (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
> diff --git a/trace/stderr.c b/trace/stderr.c
> index 7107c4a..6a12977 100644
> --- a/trace/stderr.c
> +++ b/trace/stderr.c
> @@ -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 (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)
I do think this idea of using wildcard (from Stefanha) is smarter than
trace groups.
I did not find anything wrong with the code although it does not support
events with wildcard like "virtio_*_init".
Reviewed-by: Cao,Bing Bu <mars@linux.vnet.ibm.com>
Tested-by: Cao,Bing Bu <mars@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Add wildcard trace event support
2011-10-20 9:38 [Qemu-devel] [PATCH] Add wildcard trace event support Mark Wu
2011-10-21 1:37 ` Mars.Cao
@ 2011-10-28 9:47 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2011-10-28 9:47 UTC (permalink / raw)
To: Mark Wu; +Cc: stefanha, qemu-devel
On Thu, Oct 20, 2011 at 10:38 AM, Mark Wu <wudxw@linux.vnet.ibm.com> wrote:
> The "tracetool" script automates tedious trace event code generation and also
> diff --git a/trace/simple.c b/trace/simple.c
> index b639dda..869e315 100644
> --- a/trace/simple.c
> +++ b/trace/simple.c
> @@ -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 (name[len-1] == '*') {
I think it's worth making a small change:
if (len > 0 && name[len - 1] == '*') {
Normally strlen(name) > 0 but just in case we should prevent accessing name[-1].
Seems fine otherwise. Perhaps we can figure out how to share code
between simple.c and stderr.c in the future.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-28 9:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-20 9:38 [Qemu-devel] [PATCH] Add wildcard trace event support Mark Wu
2011-10-21 1:37 ` Mars.Cao
2011-10-28 9:47 ` Stefan Hajnoczi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.