From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz2IP-0002Q9-Dy for qemu-devel@nongnu.org; Thu, 01 Sep 2011 04:06:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qz2IE-0007al-6G for qemu-devel@nongnu.org; Thu, 01 Sep 2011 04:06:40 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:59694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz2ID-0007ZI-GK for qemu-devel@nongnu.org; Thu, 01 Sep 2011 04:06:34 -0400 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p8186WTi024861 for ; Thu, 1 Sep 2011 08:06:32 GMT Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p8186WwS2642008 for ; Thu, 1 Sep 2011 09:06:32 +0100 Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p8186Vxf020179 for ; Thu, 1 Sep 2011 02:06:31 -0600 From: Stefan Hajnoczi Date: Thu, 1 Sep 2011 09:06:21 +0100 Message-Id: <1314864386-14202-11-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1314864386-14202-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1314864386-14202-1-git-send-email-stefanha@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 10/15] trace: add "-trace events" argument to control initial state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , =?UTF-8?q?Llu=C3=ADs?= , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= From: Llu=C3=ADs 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 provid= ing early tracing. This saves the user from manually toggling event states through the monit= or interface or whichever backend-specific interface. Signed-off-by: Llu=C3=ADs Vilanova --- 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) +=3D default.o trace-nested-$(CONFIG_TRACE_SIMPLE) +=3D simple.o trace-obj-$(CONFIG_TRACE_SIMPLE) +=3D qemu-timer-common.o =20 +trace-nested-y +=3D control.o + trace-obj-y +=3D $(addprefix trace/, $(trace-nested-y)) =20 ###################################################################### 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. =20 +The "-trace events=3D" command line argument can be used to enable= the +events listed in from the very beginning of the program. This fil= e must +contain one event name per line. + =3D=3D Trace backends =3D=3D =20 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 =3D { .head =3D QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), .desc =3D { { + .name =3D "events", + .type =3D QEMU_OPT_STRING, + },{ .name =3D "file", .type =3D 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 @va= r{sysconfdir}/qemu.conf and option will prevent QEMU from loading these configuration files at start= up. ETEXI DEF("trace", HAS_ARG, QEMU_OPTION_trace, - "-trace\n" - " Specify a trace file to log traces to\n", + "-trace [events=3D][,file=3D]\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-specif= ic but +HXCOMM HX does not support conditional compilation of text. +@item -trace [events=3D@var{file}][,file=3D@var{file}] @findex -trace -Specify a trace file to log output traces to. =20 -This option is available only when using the @var{simple} tracing backen= d. +Specify tracing options. + +@table @option +@item events=3D@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 backen= d. +@item file=3D@var{file} +Log output traces to @var{file}. + +This option is only available when using the @var{simple} tracing backen= d. +@end table ETEXI =20 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=C3=ADs Vilanova + * + * 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 =3D=3D NULL) { + return; + } + + FILE *fp =3D 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 =3D strlen(line_buf); + if (len > 1) { /* skip empty lines */ + line_buf[len - 1] =3D '\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) !=3D 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 sta= te); =20 /** Initialize the tracing backend. * - * @file Name of trace output file; may be NULL. - * Corresponds to commandline option "-trace file=3D...". + * @events Name of file with events to be enabled at startup; may be NUL= L. + * Corresponds to commandline option "-trace events=3D...". + * @file Name of trace output file; may be NULL. + * Corresponds to commandline option "-trace file=3D...". * @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); =20 #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 stat= e) return false; } =20 -bool trace_backend_init(const char *file) +bool trace_backend_init(const char *events, const char *file) { + if (events) { + fprintf(stderr, "error: -trace events=3D...: " + "option not supported by the selected tracing backend\n"= ); + return false; + } if (file) { fprintf(stderr, "error: -trace file=3D...: " "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 sta= te) return false; } =20 -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 back= end\n"); } else { atexit(st_flush_trace_buffer); + trace_backend_init_events(events); st_set_trace_file(file); } =20 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 =3D realloc_and_trace, .free =3D free_and_trace, }; + const char *trace_events =3D NULL; const char *trace_file =3D NULL; =20 atexit(qemu_run_exit_notifiers); @@ -2934,6 +2935,7 @@ int main(int argc, char **argv, char **envp) if (!opts) { exit(1); } + trace_events =3D qemu_opt_get(opts, "events"); trace_file =3D qemu_opt_get(opts, "file"); break; } @@ -2994,7 +2996,7 @@ int main(int argc, char **argv, char **envp) set_cpu_log(log_mask); } =20 - if (!trace_backend_init(trace_file)) { + if (!trace_backend_init(trace_events, trace_file)) { exit(1); } =20 --=20 1.7.5.4