From: Lluís <xscript@gmx.net>
To: qemu-devel@nongnu.org
Cc: stefanha@gmail.com, chouteau@adacore.com
Subject: [Qemu-devel] [PATCH v5 06/10] trace-state: add "-trace events" argument to control initial state
Date: Tue, 28 Jun 2011 18:53:34 +0200 [thread overview]
Message-ID: <20110628165334.23482.6251.stgit@ginnungagap.bsc.es> (raw)
In-Reply-To: <20110628165254.23482.17825.stgit@ginnungagap.bsc.es>
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>
---
docs/tracing.txt | 3 +++
qemu-config.c | 3 +++
qemu-options.hx | 24 ++++++++++++++++++------
trace/control.c | 30 ++++++++++++++++++++++++++++++
trace/control.h | 2 ++
vl.c | 2 ++
6 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/docs/tracing.txt b/docs/tracing.txt
index 017ff59..8f6e5c9 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -129,6 +129,9 @@ 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.
+
== Trace backends ==
The "tracetool" script automates tedious trace event code generation and also
diff --git a/qemu-config.c b/qemu-config.c
index d187dc5..3fae102 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -302,6 +302,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 b691e13..7e7b1f7 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2394,17 +2394,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.
+
+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 not available when using the @var{nop} tracing backend.
+@item file=@var{file}
+Log output traces to @var{file}.
This option is available only 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
index 6138eab..0086f1f 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -34,3 +34,33 @@ bool trace_event_set_state (const char *name, bool state)
#endif
return false;
}
+
+void trace_config_event_set_state (const char *fname)
+{
+ if (fname == NULL) {
+ return;
+ }
+
+ FILE *fp = fopen(fname, "r");
+ if (!fp) {
+ fprintf(stderr, "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, "qemu: error: trace event '%s' does not exist\n", line_buf);
+ exit(1);
+ }
+ }
+ }
+ if (fclose(fp) != 0) {
+ fprintf(stderr, "qemu: error: closing file '%s': %s\n",
+ fname, strerror(errno));
+ exit(1);
+ }
+}
diff --git a/trace/control.h b/trace/control.h
index 37d3aa0..48f4b01 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -11,4 +11,6 @@
void trace_print_events (FILE *stream, fprintf_function stream_printf);
bool trace_event_set_state (const char *name, bool state);
+void trace_config_event_set_state (const char *fname);
+
#endif /* TRACE_CONTROL_H */
diff --git a/vl.c b/vl.c
index b766dc7..c95b186 100644
--- a/vl.c
+++ b/vl.c
@@ -156,6 +156,7 @@ int main(int argc, char **argv)
#include "slirp/libslirp.h"
#include "trace.h"
+#include "trace/control.h"
#include "trace/simple.h"
#include "qemu-queue.h"
#include "cpus.h"
@@ -2870,6 +2871,7 @@ int main(int argc, char **argv, char **envp)
fprintf(stderr, "qemu: option \"-%s\" is not supported by this tracing backend\n", popt->name);
exit(1);
#endif
+ trace_config_event_set_state(qemu_opt_get(opts, "events"));
trace_file = qemu_opt_get(opts, "file");
#if !defined(CONFIG_SIMPLE_TRACE)
if (trace_file) {
next prev parent reply other threads:[~2011-06-28 16:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-28 16:52 [Qemu-devel] [PATCH v5 00/10] trace-state: make the behaviour of "disable" consistent across all backends Lluís
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 01/10] trace: move backend-specific code into the trace/ directory Lluís
2011-07-15 9:40 ` Stefan Hajnoczi
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 02/10] trace: avoid conditional code compilation during option parsing Lluís
2011-07-15 9:41 ` Stefan Hajnoczi
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 03/10] trace: generalize the "property" concept in the trace-events file Lluís
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 04/10] trace-state: separate trace event control and query routines from the simple backend Lluís
2011-07-15 9:41 ` Stefan Hajnoczi
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 05/10] trace-state: always compile support for controlling and querying trace event states Lluís
2011-06-28 16:53 ` Lluís [this message]
2011-07-15 9:40 ` [Qemu-devel] [PATCH v5 06/10] trace-state: add "-trace events" argument to control initial state Stefan Hajnoczi
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 07/10] trace-state: always use the "nop" backend on events with the "disable" keyword Lluís
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 08/10] trace-state: [simple] disable all trace points by default Lluís
2011-06-28 16:53 ` [Qemu-devel] [PATCH v5 09/10] trace-state: [stderr] add support for dynamically enabling/disabling events Lluís
2011-06-28 16:54 ` [Qemu-devel] [PATCH v5 10/10] trace: enable all events Lluís
2011-07-12 18:04 ` [Qemu-devel] [PATCH v5 00/10] trace-state: make the behaviour of "disable" consistent across all backends Stefan Hajnoczi
2011-07-15 9:47 ` Stefan Hajnoczi
2011-07-20 19:19 ` Lluís
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=20110628165334.23482.6251.stgit@ginnungagap.bsc.es \
--to=xscript@gmx.net \
--cc=chouteau@adacore.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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).