From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>, Lluís <xscript@gmx.net>,
"Lluís Vilanova" <vilanova@ac.upc.edu>
Subject: [Qemu-devel] [PATCH 10/15] trace: add "-trace events" argument to control initial state
Date: Thu, 1 Sep 2011 09:06:21 +0100 [thread overview]
Message-ID: <1314864386-14202-11-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1314864386-14202-1-git-send-email-stefanha@linux.vnet.ibm.com>
From: Lluís <xscript@gmx.net>
The "-trace events" argument can be used to provide a file with a list of trace
event names that will be enabled prior to starting execution, thus providing
early tracing.
This saves the user from manually toggling event states through the monitor
interface or whichever backend-specific interface.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
Makefile.objs | 2 ++
docs/tracing.txt | 4 ++++
qemu-config.c | 3 +++
qemu-options.hx | 26 +++++++++++++++++++-------
trace/control.c | 42 ++++++++++++++++++++++++++++++++++++++++++
trace/control.h | 14 +++++++++++---
trace/default.c | 7 ++++++-
trace/simple.c | 3 ++-
vl.c | 4 +++-
9 files changed, 92 insertions(+), 13 deletions(-)
create mode 100644 trace/control.c
diff --git a/Makefile.objs b/Makefile.objs
index 57a80e6..036a4eb 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -384,6 +384,8 @@ trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o
trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o
trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
+trace-nested-y += control.o
+
trace-obj-y += $(addprefix trace/, $(trace-nested-y))
######################################################################
diff --git a/docs/tracing.txt b/docs/tracing.txt
index 41eb8e6..455da37 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -138,6 +138,10 @@ This functionality is also provided through monitor commands:
* trace-event NAME on|off
Enable/disable a given trace event.
+The "-trace events=<file>" command line argument can be used to enable the
+events listed in <file> from the very beginning of the program. This file must
+contain one event name per line.
+
== Trace backends ==
The "tracetool" script automates tedious trace event code generation and also
diff --git a/qemu-config.c b/qemu-config.c
index 4f3465d..7a7854f 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -309,6 +309,9 @@ static QemuOptsList qemu_trace_opts = {
.head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
.desc = {
{
+ .name = "events",
+ .type = QEMU_OPT_STRING,
+ },{
.name = "file",
.type = QEMU_OPT_STRING,
},
diff --git a/qemu-options.hx b/qemu-options.hx
index 2d29933..edd181b 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2437,17 +2437,29 @@ Normally QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and
option will prevent QEMU from loading these configuration files at startup.
ETEXI
DEF("trace", HAS_ARG, QEMU_OPTION_trace,
- "-trace\n"
- " Specify a trace file to log traces to\n",
+ "-trace [events=<file>][,file=<file>]\n"
+ " specify tracing options\n",
QEMU_ARCH_ALL)
STEXI
-HXCOMM This line is not accurate, as the option is backend-specific but HX does
-HXCOMM not support conditional compilation of text.
-@item -trace
+HXCOMM This line is not accurate, as some sub-options are backend-specific but
+HXCOMM HX does not support conditional compilation of text.
+@item -trace [events=@var{file}][,file=@var{file}]
@findex -trace
-Specify a trace file to log output traces to.
-This option is available only when using the @var{simple} tracing backend.
+Specify tracing options.
+
+@table @option
+@item events=@var{file}
+Immediately enable events listed in @var{file}.
+The file must contain one event name (as listed in the @var{trace-events} file)
+per line.
+
+This option is only available when using the @var{simple} tracing backend.
+@item file=@var{file}
+Log output traces to @var{file}.
+
+This option is only available when using the @var{simple} tracing backend.
+@end table
ETEXI
HXCOMM This is the last statement. Insert new options before this line!
diff --git a/trace/control.c b/trace/control.c
new file mode 100644
index 0000000..4c5527d
--- /dev/null
+++ b/trace/control.c
@@ -0,0 +1,42 @@
+/*
+ * Interface for configuring and controlling the state of tracing events.
+ *
+ * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "trace/control.h"
+
+
+void trace_backend_init_events(const char *fname)
+{
+ if (fname == NULL) {
+ return;
+ }
+
+ FILE *fp = fopen(fname, "r");
+ if (!fp) {
+ fprintf(stderr, "error: could not open trace events file '%s': %s\n",
+ fname, strerror(errno));
+ exit(1);
+ }
+ char line_buf[1024];
+ while (fgets(line_buf, sizeof(line_buf), fp)) {
+ size_t len = strlen(line_buf);
+ if (len > 1) { /* skip empty lines */
+ line_buf[len - 1] = '\0';
+ if (!trace_event_set_state(line_buf, true)) {
+ fprintf(stderr,
+ "error: trace event '%s' does not exist\n", line_buf);
+ exit(1);
+ }
+ }
+ }
+ if (fclose(fp) != 0) {
+ fprintf(stderr, "error: closing file '%s': %s\n",
+ fname, strerror(errno));
+ exit(1);
+ }
+}
diff --git a/trace/control.h b/trace/control.h
index c99b4d5..2acaa42 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -24,10 +24,18 @@ bool trace_event_set_state(const char *name, bool state);
/** Initialize the tracing backend.
*
- * @file Name of trace output file; may be NULL.
- * Corresponds to commandline option "-trace file=...".
+ * @events Name of file with events to be enabled at startup; may be NULL.
+ * Corresponds to commandline option "-trace events=...".
+ * @file Name of trace output file; may be NULL.
+ * Corresponds to commandline option "-trace file=...".
* @return Whether the backend could be successfully initialized.
*/
-bool trace_backend_init(const char *file);
+bool trace_backend_init(const char *events, const char *file);
+
+/** Generic function to initialize the state of events.
+ *
+ * @fname Name of file with events to enable; may be NULL.
+ */
+void trace_backend_init_events(const char *fname);
#endif /* TRACE_CONTROL_H */
diff --git a/trace/default.c b/trace/default.c
index 3573d5b..c9b27a2 100644
--- a/trace/default.c
+++ b/trace/default.c
@@ -25,8 +25,13 @@ bool trace_event_set_state(const char *name, bool state)
return false;
}
-bool trace_backend_init(const char *file)
+bool trace_backend_init(const char *events, const char *file)
{
+ if (events) {
+ fprintf(stderr, "error: -trace events=...: "
+ "option not supported by the selected tracing backend\n");
+ return false;
+ }
if (file) {
fprintf(stderr, "error: -trace file=...: "
"option not supported by the selected tracing backend\n");
diff --git a/trace/simple.c b/trace/simple.c
index 70689e9..a609368 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -331,7 +331,7 @@ bool trace_event_set_state(const char *name, bool state)
return false;
}
-bool trace_backend_init(const char *file)
+bool trace_backend_init(const char *events, const char *file)
{
pthread_t thread;
pthread_attr_t attr;
@@ -350,6 +350,7 @@ bool trace_backend_init(const char *file)
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
} else {
atexit(st_flush_trace_buffer);
+ trace_backend_init_events(events);
st_set_trace_file(file);
}
diff --git a/vl.c b/vl.c
index 60322b6..c6dc689 100644
--- a/vl.c
+++ b/vl.c
@@ -2137,6 +2137,7 @@ int main(int argc, char **argv, char **envp)
.realloc = realloc_and_trace,
.free = free_and_trace,
};
+ const char *trace_events = NULL;
const char *trace_file = NULL;
atexit(qemu_run_exit_notifiers);
@@ -2934,6 +2935,7 @@ int main(int argc, char **argv, char **envp)
if (!opts) {
exit(1);
}
+ trace_events = qemu_opt_get(opts, "events");
trace_file = qemu_opt_get(opts, "file");
break;
}
@@ -2994,7 +2996,7 @@ int main(int argc, char **argv, char **envp)
set_cpu_log(log_mask);
}
- if (!trace_backend_init(trace_file)) {
+ if (!trace_backend_init(trace_events, trace_file)) {
exit(1);
}
--
1.7.5.4
next prev parent reply other threads:[~2011-09-01 8:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-01 8:06 [Qemu-devel] [PULL 00/15] Tracing patches Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 01/15] build: Fix linkage of QEMU_PROG Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 02/15] build: [simple] Include qemu-timer-common.o in trace-obj-y Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 03/15] trace: [configure] rename CONFIG_*_TRACE into CONFIG_TRACE_* Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 04/15] trace: [make] replace 'ifeq' with values in CONFIG_TRACE_* Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 05/15] trace: move backend-specific code into the trace/ directory Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 06/15] trace: avoid conditional code compilation during option parsing Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 07/15] trace: generalize the "property" concept in the trace-events file Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 08/15] trace: separate trace event control and query routines from the simple backend Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 09/15] trace: always compile support for controlling and querying trace event states Stefan Hajnoczi
2011-09-01 8:06 ` Stefan Hajnoczi [this message]
2011-09-01 8:06 ` [Qemu-devel] [PATCH 11/15] trace: always use the "nop" backend on events with the "disable" keyword Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 12/15] trace: [simple] disable all trace points by default Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 13/15] trace: [stderr] add support for dynamically enabling/disabling events Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 14/15] trace: enable all events Stefan Hajnoczi
2011-09-01 8:06 ` [Qemu-devel] [PATCH 15/15] simpletrace: fix process() argument count Stefan Hajnoczi
2011-09-01 19:08 ` [Qemu-devel] [PULL 00/15] Tracing patches Anthony Liguori
2011-09-02 9:39 ` Stefan Hajnoczi
2011-09-02 14:54 ` Anthony Liguori
2011-09-02 15:00 ` Anthony Liguori
2011-09-02 15:30 ` Lluís Vilanova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1314864386-14202-11-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=vilanova@ac.upc.edu \
--cc=xscript@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).