trace: add "-trace enable=..."

Allow enabling events without going through a file, for example:

   qemu-system-x86_64 -trace bdrv_aio_writev -trace bdrv_aio_readv

or with globbing too:

   qemu-system-x86_64 -trace 'bdrv_aio_*'

if an appropriate backend is enabled (simple, stderr, ftrace).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Message-id: 1452174932-28657-6-git-send-email-den@openvz.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Paolo Bonzini
2016-01-07 16:55:26 +03:00
committed by Stefan Hajnoczi
parent f246b86672
commit 10578a257d
4 changed files with 54 additions and 24 deletions

View File

@@ -88,6 +88,32 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
return NULL;
}
void trace_enable_events(const char *line_buf)
{
const bool enable = ('-' != line_buf[0]);
const char *line_ptr = enable ? line_buf : line_buf + 1;
if (trace_event_is_pattern(line_ptr)) {
TraceEvent *ev = NULL;
while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
if (trace_event_get_state_static(ev)) {
trace_event_set_state_dynamic(ev, enable);
}
}
} else {
TraceEvent *ev = trace_event_name(line_ptr);
if (ev == NULL) {
error_report("WARNING: trace event '%s' does not exist",
line_ptr);
} else if (!trace_event_get_state_static(ev)) {
error_report("WARNING: trace event '%s' is not traceable",
line_ptr);
} else {
trace_event_set_state_dynamic(ev, enable);
}
}
}
void trace_init_events(const char *fname)
{
Location loc;
@@ -114,27 +140,7 @@ void trace_init_events(const char *fname)
if ('#' == line_buf[0]) { /* skip commented lines */
continue;
}
const bool enable = ('-' != line_buf[0]);
char *line_ptr = enable ? line_buf : line_buf + 1;
if (trace_event_is_pattern(line_ptr)) {
TraceEvent *ev = NULL;
while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
if (trace_event_get_state_static(ev)) {
trace_event_set_state_dynamic(ev, enable);
}
}
} else {
TraceEvent *ev = trace_event_name(line_ptr);
if (ev == NULL) {
error_report("WARNING: trace event '%s' does not exist",
line_ptr);
} else if (!trace_event_get_state_static(ev)) {
error_report("WARNING: trace event '%s' is not traceable",
line_ptr);
} else {
trace_event_set_state_dynamic(ev, enable);
}
}
trace_enable_events(line_buf);
}
}
if (fclose(fp) != 0) {