trace/simple: Enable tracing on startup only if the user specifies a trace option

Tracing can be enabled at the command line or via the
monitor. Command-line trace options are recorded during
trace_opt_parse(), but tracing is not enabled until the various
front-ends later call trace_init_file(). If the user passes a trace
option on the command-line, remember that and enable tracing during
trace_init_file().  Otherwise, trace_init_file() should record the
trace file specified by the frontend and avoid enabling traces
until the user requests them via the monitor.

This fixes 1b7157be3a and also
db25d56c01, by allowing the user
to enable traces on the command line and also avoiding
unwanted trace-<pid> files when the user has not asked for them.

Fixes: 1b7157be3a
Signed-off-by: Josh DuBois <josh@joshdubois.com>
Message-id: 20200816174610.20253-1-josh@joshdubois.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Josh DuBois 2020-08-16 12:46:10 -05:00 committed by Stefan Hajnoczi
parent a46e727105
commit 648b4823d9
1 changed files with 5 additions and 1 deletions

View File

@ -39,6 +39,7 @@ static TraceEventGroup *event_groups;
static size_t nevent_groups;
static uint32_t next_id;
static uint32_t next_vcpu_id;
static bool init_trace_on_startup;
QemuOptsList qemu_trace_opts = {
.name = "trace",
@ -225,7 +226,9 @@ void trace_init_file(const char *file)
{
#ifdef CONFIG_TRACE_SIMPLE
st_set_trace_file(file);
st_set_trace_file_enabled(true);
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"
@ -299,6 +302,7 @@ char *trace_opt_parse(const char *optarg)
}
trace_init_events(qemu_opt_get(opts, "events"));
trace_file = g_strdup(qemu_opt_get(opts, "file"));
init_trace_on_startup = true;
qemu_opts_del(opts);
return trace_file;