diff options
Diffstat (limited to 'trace/control.c')
-rw-r--r-- | trace/control.c | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/trace/control.c b/trace/control.c index 49f61e1..9631a40 100644 --- a/trace/control.c +++ b/trace/control.c @@ -1,14 +1,20 @@ /* * Interface for configuring and controlling the state of tracing events. * - * Copyright (C) 2011-2012 Lluís Vilanova <vilanova@ac.upc.edu> + * Copyright (C) 2011-2014 Lluís Vilanova <vilanova@ac.upc.edu> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ #include "trace/control.h" - +#ifdef CONFIG_TRACE_SIMPLE +#include "trace/simple.h" +#endif +#ifdef CONFIG_TRACE_FTRACE +#include "trace/ftrace.h" +#endif +#include "qemu/error-report.h" TraceEvent *trace_event_name(const char *name) { @@ -79,20 +85,39 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev) return NULL; } -void trace_backend_init_events(const char *fname) +void trace_print_events(FILE *stream, fprintf_function stream_printf) +{ + TraceEventID i; + + for (i = 0; i < trace_event_count(); i++) { + TraceEvent *ev = trace_event_id(i); + stream_printf(stream, "%s [Event ID %u] : state %u\n", + trace_event_get_name(ev), i, + trace_event_get_state_static(ev) && + trace_event_get_state_dynamic(ev)); + } +} + +static void trace_init_events(const char *fname) { + Location loc; + FILE *fp; + char line_buf[1024]; + size_t line_idx = 0; + if (fname == NULL) { return; } - FILE *fp = fopen(fname, "r"); + loc_push_none(&loc); + loc_set_file(fname, 0); + fp = fopen(fname, "r"); if (!fp) { - fprintf(stderr, "error: could not open trace events file '%s': %s\n", - fname, strerror(errno)); + error_report("%s", strerror(errno)); exit(1); } - char line_buf[1024]; while (fgets(line_buf, sizeof(line_buf), fp)) { + loc_set_file(fname, ++line_idx); size_t len = strlen(line_buf); if (len > 1) { /* skip empty lines */ line_buf[len - 1] = '\0'; @@ -111,22 +136,47 @@ void trace_backend_init_events(const char *fname) } else { TraceEvent *ev = trace_event_name(line_ptr); if (ev == NULL) { - fprintf(stderr, - "error: trace event '%s' does not exist\n", line_ptr); - exit(1); + 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\n", + line_ptr); + } else { + trace_event_set_state_dynamic(ev, enable); } - if (!trace_event_get_state_static(ev)) { - fprintf(stderr, - "error: trace event '%s' is not traceable\n", line_ptr); - exit(1); - } - trace_event_set_state_dynamic(ev, enable); } } } if (fclose(fp) != 0) { - fprintf(stderr, "error: closing file '%s': %s\n", - fname, strerror(errno)); + loc_set_file(fname, 0); + error_report("%s", strerror(errno)); exit(1); } + loc_pop(&loc); +} + +bool trace_init_backends(const char *events, const char *file) +{ +#ifdef CONFIG_TRACE_SIMPLE + if (!st_init(file)) { + fprintf(stderr, "failed to initialize simple tracing backend.\n"); + return false; + } +#else + if (file) { + fprintf(stderr, "error: -trace file=...: " + "option not supported by the selected tracing backends\n"); + return false; + } +#endif + +#ifdef CONFIG_TRACE_FTRACE + if (!ftrace_init()) { + fprintf(stderr, "failed to initialize ftrace backend.\n"); + return false; + } +#endif + + trace_init_events(events); + return true; } |