#include "qemu/error-report.h"
#include "qemu/config-file.h"
#include "monitor/monitor.h"
-#include "trace-root.h"
+#include "trace/trace-root.h"
int trace_events_enabled_count;
static size_t nevent_groups;
static uint32_t next_id;
static uint32_t next_vcpu_id;
+static bool init_trace_on_startup;
+static char *trace_opts_file;
QemuOptsList qemu_trace_opts = {
.name = "trace",
return NULL;
}
-void trace_list_events(void)
+void trace_list_events(FILE *f)
{
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init(&iter, NULL);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
- fprintf(stderr, "%s\n", trace_event_get_name(ev));
+ fprintf(f, "%s\n", trace_event_get_name(ev));
}
#ifdef CONFIG_TRACE_DTRACE
- fprintf(stderr, "This list of names of trace points may be incomplete "
- "when using the DTrace/SystemTap backends.\n"
- "Run 'qemu-trace-stap list %s' to print the full list.\n",
+ fprintf(f, "This list of names of trace points may be incomplete "
+ "when using the DTrace/SystemTap backends.\n"
+ "Run 'qemu-trace-stap list %s' to print the full list.\n",
error_get_progname());
#endif
}
void trace_enable_events(const char *line_buf)
{
if (is_help_option(line_buf)) {
- trace_list_events();
- if (cur_mon == NULL) {
+ trace_list_events(stdout);
+ if (monitor_cur() == NULL) {
exit(0);
}
} else {
loc_pop(&loc);
}
-void trace_init_file(const char *file)
+void trace_init_file(void)
{
#ifdef CONFIG_TRACE_SIMPLE
- st_set_trace_file(file);
+ st_set_trace_file(trace_opts_file);
+ if (init_trace_on_startup) {
+ st_set_trace_file_enabled(true);
+ }
#elif defined CONFIG_TRACE_LOG
- /* If both the simple and the log backends are enabled, "--trace file"
- * only applies to the simple backend; use "-D" for the log backend.
+ /*
+ * If both the simple and the log backends are enabled, "--trace file"
+ * only applies to the simple backend; use "-D" for the log
+ * backend. However we should only override -D if we actually have
+ * something to override it with.
*/
- if (file) {
- qemu_set_log_filename(file, &error_fatal);
+ if (trace_opts_file) {
+ qemu_set_log_filename(trace_opts_file, &error_fatal);
}
#else
- if (file) {
+ if (trace_opts_file) {
fprintf(stderr, "error: --trace file=...: "
"option not supported by the selected tracing backends\n");
exit(1);
return true;
}
-char *trace_opt_parse(const char *optarg)
+void trace_opt_parse(const char *optarg)
{
- char *trace_file;
QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
optarg, true);
if (!opts) {
trace_enable_events(qemu_opt_get(opts, "enable"));
}
trace_init_events(qemu_opt_get(opts, "events"));
- trace_file = g_strdup(qemu_opt_get(opts, "file"));
+ init_trace_on_startup = true;
+ g_free(trace_opts_file);
+ trace_opts_file = g_strdup(qemu_opt_get(opts, "file"));
qemu_opts_del(opts);
-
- return trace_file;
}
uint32_t trace_get_vcpu_event_count(void)