2011-08-31 20:31:31 +02:00
|
|
|
/*
|
|
|
|
* Interface for configuring and controlling the state of tracing events.
|
|
|
|
*
|
2014-05-27 15:02:14 +02:00
|
|
|
* Copyright (C) 2011-2014 Lluís Vilanova <vilanova@ac.upc.edu>
|
2011-08-31 20:31:31 +02:00
|
|
|
*
|
2013-03-05 14:47:38 +01:00
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
2011-08-31 20:31:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "trace/control.h"
|
2014-05-27 15:02:14 +02:00
|
|
|
#ifdef CONFIG_TRACE_SIMPLE
|
|
|
|
#include "trace/simple.h"
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TRACE_FTRACE
|
|
|
|
#include "trace/ftrace.h"
|
|
|
|
#endif
|
2014-06-02 08:34:10 +02:00
|
|
|
#include "qemu/error-report.h"
|
2011-08-31 20:31:31 +02:00
|
|
|
|
2015-10-28 07:06:26 +01:00
|
|
|
int trace_events_enabled_count;
|
2015-10-28 07:06:27 +01:00
|
|
|
bool trace_events_dstate[TRACE_EVENT_COUNT];
|
2015-10-28 07:06:26 +01:00
|
|
|
|
2013-03-05 14:47:38 +01:00
|
|
|
TraceEvent *trace_event_name(const char *name)
|
|
|
|
{
|
|
|
|
assert(name != NULL);
|
|
|
|
|
|
|
|
TraceEventID i;
|
|
|
|
for (i = 0; i < trace_event_count(); i++) {
|
|
|
|
TraceEvent *ev = trace_event_id(i);
|
|
|
|
if (strcmp(trace_event_get_name(ev), name) == 0) {
|
|
|
|
return ev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool pattern_glob(const char *pat, const char *ev)
|
|
|
|
{
|
|
|
|
while (*pat != '\0' && *ev != '\0') {
|
|
|
|
if (*pat == *ev) {
|
|
|
|
pat++;
|
|
|
|
ev++;
|
|
|
|
}
|
|
|
|
else if (*pat == '*') {
|
|
|
|
if (pattern_glob(pat, ev+1)) {
|
|
|
|
return true;
|
|
|
|
} else if (pattern_glob(pat+1, ev)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*pat == '*') {
|
|
|
|
pat++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pat == '\0' && *ev == '\0') {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
|
2011-08-31 20:31:31 +02:00
|
|
|
{
|
2013-03-05 14:47:38 +01:00
|
|
|
assert(pat != NULL);
|
2012-10-26 13:46:34 +02:00
|
|
|
|
2013-03-05 14:47:38 +01:00
|
|
|
TraceEventID i;
|
|
|
|
|
|
|
|
if (ev == NULL) {
|
|
|
|
i = -1;
|
|
|
|
} else {
|
|
|
|
i = trace_event_get_id(ev);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
while (i < trace_event_count()) {
|
|
|
|
TraceEvent *res = trace_event_id(i);
|
|
|
|
if (pattern_glob(pat, trace_event_get_name(res))) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-07 14:55:23 +01:00
|
|
|
void trace_init_events(const char *fname)
|
2013-03-05 14:47:38 +01:00
|
|
|
{
|
2014-06-02 08:34:10 +02:00
|
|
|
Location loc;
|
|
|
|
FILE *fp;
|
|
|
|
char line_buf[1024];
|
|
|
|
size_t line_idx = 0;
|
|
|
|
|
2011-08-31 20:31:31 +02:00
|
|
|
if (fname == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-02 08:34:10 +02:00
|
|
|
loc_push_none(&loc);
|
|
|
|
loc_set_file(fname, 0);
|
|
|
|
fp = fopen(fname, "r");
|
2011-08-31 20:31:31 +02:00
|
|
|
if (!fp) {
|
2014-06-02 08:34:10 +02:00
|
|
|
error_report("%s", strerror(errno));
|
2011-08-31 20:31:31 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
while (fgets(line_buf, sizeof(line_buf), fp)) {
|
2014-06-02 08:34:10 +02:00
|
|
|
loc_set_file(fname, ++line_idx);
|
2011-08-31 20:31:31 +02:00
|
|
|
size_t len = strlen(line_buf);
|
|
|
|
if (len > 1) { /* skip empty lines */
|
|
|
|
line_buf[len - 1] = '\0';
|
2012-06-14 06:41:40 +02:00
|
|
|
if ('#' == line_buf[0]) { /* skip commented lines */
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-05 14:47:38 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2012-10-26 13:46:34 +02:00
|
|
|
} else {
|
2013-03-05 14:47:38 +01:00
|
|
|
TraceEvent *ev = trace_event_name(line_ptr);
|
|
|
|
if (ev == NULL) {
|
2014-06-02 08:34:10 +02:00
|
|
|
error_report("WARNING: trace event '%s' does not exist",
|
|
|
|
line_ptr);
|
2014-05-21 10:16:01 +02:00
|
|
|
} else if (!trace_event_get_state_static(ev)) {
|
2015-02-25 05:22:31 +01:00
|
|
|
error_report("WARNING: trace event '%s' is not traceable",
|
2014-06-02 08:34:10 +02:00
|
|
|
line_ptr);
|
2014-05-21 10:16:01 +02:00
|
|
|
} else {
|
|
|
|
trace_event_set_state_dynamic(ev, enable);
|
2013-03-05 14:47:38 +01:00
|
|
|
}
|
2011-08-31 20:31:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fclose(fp) != 0) {
|
2014-06-02 08:34:10 +02:00
|
|
|
loc_set_file(fname, 0);
|
|
|
|
error_report("%s", strerror(errno));
|
2011-08-31 20:31:31 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2014-06-02 08:34:10 +02:00
|
|
|
loc_pop(&loc);
|
2011-08-31 20:31:31 +02:00
|
|
|
}
|
2014-05-27 15:02:14 +02:00
|
|
|
|
2016-01-07 14:55:24 +01:00
|
|
|
void trace_init_file(const char *file)
|
2014-05-27 15:02:14 +02:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_TRACE_SIMPLE
|
2016-01-07 14:55:24 +01:00
|
|
|
st_set_trace_file(file);
|
2014-05-27 15:02:14 +02:00
|
|
|
#else
|
|
|
|
if (file) {
|
|
|
|
fprintf(stderr, "error: -trace file=...: "
|
|
|
|
"option not supported by the selected tracing backends\n");
|
2016-01-07 14:55:24 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool trace_init_backends(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_TRACE_SIMPLE
|
|
|
|
if (!st_init()) {
|
|
|
|
fprintf(stderr, "failed to initialize simple tracing backend.\n");
|
2014-05-27 15:02:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_TRACE_FTRACE
|
|
|
|
if (!ftrace_init()) {
|
|
|
|
fprintf(stderr, "failed to initialize ftrace backend.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|