Revision 23d15e86
b/Makefile.objs | ||
---|---|---|
384 | 384 |
trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o |
385 | 385 |
trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o |
386 | 386 |
|
387 |
trace-nested-y += control.o |
|
388 |
|
|
387 | 389 |
trace-obj-y += $(addprefix trace/, $(trace-nested-y)) |
388 | 390 |
|
389 | 391 |
###################################################################### |
b/docs/tracing.txt | ||
---|---|---|
138 | 138 |
* trace-event NAME on|off |
139 | 139 |
Enable/disable a given trace event. |
140 | 140 |
|
141 |
The "-trace events=<file>" command line argument can be used to enable the |
|
142 |
events listed in <file> from the very beginning of the program. This file must |
|
143 |
contain one event name per line. |
|
144 |
|
|
141 | 145 |
== Trace backends == |
142 | 146 |
|
143 | 147 |
The "tracetool" script automates tedious trace event code generation and also |
b/qemu-config.c | ||
---|---|---|
309 | 309 |
.head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), |
310 | 310 |
.desc = { |
311 | 311 |
{ |
312 |
.name = "events", |
|
313 |
.type = QEMU_OPT_STRING, |
|
314 |
},{ |
|
312 | 315 |
.name = "file", |
313 | 316 |
.type = QEMU_OPT_STRING, |
314 | 317 |
}, |
b/qemu-options.hx | ||
---|---|---|
2437 | 2437 |
option will prevent QEMU from loading these configuration files at startup. |
2438 | 2438 |
ETEXI |
2439 | 2439 |
DEF("trace", HAS_ARG, QEMU_OPTION_trace, |
2440 |
"-trace\n" |
|
2441 |
" Specify a trace file to log traces to\n",
|
|
2440 |
"-trace [events=<file>][,file=<file>]\n"
|
|
2441 |
" specify tracing options\n",
|
|
2442 | 2442 |
QEMU_ARCH_ALL) |
2443 | 2443 |
STEXI |
2444 |
HXCOMM This line is not accurate, as the option is backend-specific but HX does
|
|
2445 |
HXCOMM not support conditional compilation of text. |
|
2446 |
@item -trace |
|
2444 |
HXCOMM This line is not accurate, as some sub-options are backend-specific but
|
|
2445 |
HXCOMM HX does not support conditional compilation of text.
|
|
2446 |
@item -trace [events=@var{file}][,file=@var{file}]
|
|
2447 | 2447 |
@findex -trace |
2448 |
Specify a trace file to log output traces to. |
|
2449 | 2448 |
|
2450 |
This option is available only when using the @var{simple} tracing backend. |
|
2449 |
Specify tracing options. |
|
2450 |
|
|
2451 |
@table @option |
|
2452 |
@item events=@var{file} |
|
2453 |
Immediately enable events listed in @var{file}. |
|
2454 |
The file must contain one event name (as listed in the @var{trace-events} file) |
|
2455 |
per line. |
|
2456 |
|
|
2457 |
This option is only available when using the @var{simple} tracing backend. |
|
2458 |
@item file=@var{file} |
|
2459 |
Log output traces to @var{file}. |
|
2460 |
|
|
2461 |
This option is only available when using the @var{simple} tracing backend. |
|
2462 |
@end table |
|
2451 | 2463 |
ETEXI |
2452 | 2464 |
|
2453 | 2465 |
HXCOMM This is the last statement. Insert new options before this line! |
b/trace/control.c | ||
---|---|---|
1 |
/* |
|
2 |
* Interface for configuring and controlling the state of tracing events. |
|
3 |
* |
|
4 |
* Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu> |
|
5 |
* |
|
6 |
* This work is licensed under the terms of the GNU GPL, version 2. See |
|
7 |
* the COPYING file in the top-level directory. |
|
8 |
*/ |
|
9 |
|
|
10 |
#include "trace/control.h" |
|
11 |
|
|
12 |
|
|
13 |
void trace_backend_init_events(const char *fname) |
|
14 |
{ |
|
15 |
if (fname == NULL) { |
|
16 |
return; |
|
17 |
} |
|
18 |
|
|
19 |
FILE *fp = fopen(fname, "r"); |
|
20 |
if (!fp) { |
|
21 |
fprintf(stderr, "error: could not open trace events file '%s': %s\n", |
|
22 |
fname, strerror(errno)); |
|
23 |
exit(1); |
|
24 |
} |
|
25 |
char line_buf[1024]; |
|
26 |
while (fgets(line_buf, sizeof(line_buf), fp)) { |
|
27 |
size_t len = strlen(line_buf); |
|
28 |
if (len > 1) { /* skip empty lines */ |
|
29 |
line_buf[len - 1] = '\0'; |
|
30 |
if (!trace_event_set_state(line_buf, true)) { |
|
31 |
fprintf(stderr, |
|
32 |
"error: trace event '%s' does not exist\n", line_buf); |
|
33 |
exit(1); |
|
34 |
} |
|
35 |
} |
|
36 |
} |
|
37 |
if (fclose(fp) != 0) { |
|
38 |
fprintf(stderr, "error: closing file '%s': %s\n", |
|
39 |
fname, strerror(errno)); |
|
40 |
exit(1); |
|
41 |
} |
|
42 |
} |
b/trace/control.h | ||
---|---|---|
24 | 24 |
|
25 | 25 |
/** Initialize the tracing backend. |
26 | 26 |
* |
27 |
* @file Name of trace output file; may be NULL. |
|
28 |
* Corresponds to commandline option "-trace file=...". |
|
27 |
* @events Name of file with events to be enabled at startup; may be NULL. |
|
28 |
* Corresponds to commandline option "-trace events=...". |
|
29 |
* @file Name of trace output file; may be NULL. |
|
30 |
* Corresponds to commandline option "-trace file=...". |
|
29 | 31 |
* @return Whether the backend could be successfully initialized. |
30 | 32 |
*/ |
31 |
bool trace_backend_init(const char *file); |
|
33 |
bool trace_backend_init(const char *events, const char *file); |
|
34 |
|
|
35 |
/** Generic function to initialize the state of events. |
|
36 |
* |
|
37 |
* @fname Name of file with events to enable; may be NULL. |
|
38 |
*/ |
|
39 |
void trace_backend_init_events(const char *fname); |
|
32 | 40 |
|
33 | 41 |
#endif /* TRACE_CONTROL_H */ |
b/trace/default.c | ||
---|---|---|
25 | 25 |
return false; |
26 | 26 |
} |
27 | 27 |
|
28 |
bool trace_backend_init(const char *file) |
|
28 |
bool trace_backend_init(const char *events, const char *file)
|
|
29 | 29 |
{ |
30 |
if (events) { |
|
31 |
fprintf(stderr, "error: -trace events=...: " |
|
32 |
"option not supported by the selected tracing backend\n"); |
|
33 |
return false; |
|
34 |
} |
|
30 | 35 |
if (file) { |
31 | 36 |
fprintf(stderr, "error: -trace file=...: " |
32 | 37 |
"option not supported by the selected tracing backend\n"); |
b/trace/simple.c | ||
---|---|---|
331 | 331 |
return false; |
332 | 332 |
} |
333 | 333 |
|
334 |
bool trace_backend_init(const char *file) |
|
334 |
bool trace_backend_init(const char *events, const char *file)
|
|
335 | 335 |
{ |
336 | 336 |
pthread_t thread; |
337 | 337 |
pthread_attr_t attr; |
... | ... | |
350 | 350 |
fprintf(stderr, "warning: unable to initialize simple trace backend\n"); |
351 | 351 |
} else { |
352 | 352 |
atexit(st_flush_trace_buffer); |
353 |
trace_backend_init_events(events); |
|
353 | 354 |
st_set_trace_file(file); |
354 | 355 |
} |
355 | 356 |
|
b/vl.c | ||
---|---|---|
2137 | 2137 |
.realloc = realloc_and_trace, |
2138 | 2138 |
.free = free_and_trace, |
2139 | 2139 |
}; |
2140 |
const char *trace_events = NULL; |
|
2140 | 2141 |
const char *trace_file = NULL; |
2141 | 2142 |
|
2142 | 2143 |
atexit(qemu_run_exit_notifiers); |
... | ... | |
2934 | 2935 |
if (!opts) { |
2935 | 2936 |
exit(1); |
2936 | 2937 |
} |
2938 |
trace_events = qemu_opt_get(opts, "events"); |
|
2937 | 2939 |
trace_file = qemu_opt_get(opts, "file"); |
2938 | 2940 |
break; |
2939 | 2941 |
} |
... | ... | |
2994 | 2996 |
set_cpu_log(log_mask); |
2995 | 2997 |
} |
2996 | 2998 |
|
2997 |
if (!trace_backend_init(trace_file)) { |
|
2999 |
if (!trace_backend_init(trace_events, trace_file)) {
|
|
2998 | 3000 |
exit(1); |
2999 | 3001 |
} |
3000 | 3002 |
|
Also available in: Unified diff