From patchwork Wed Apr 6 18:34:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?Q?Llu=C3=ADs?= X-Patchwork-Id: 90062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9D5F2B6F73 for ; Thu, 7 Apr 2011 05:13:13 +1000 (EST) Received: from localhost ([127.0.0.1]:38880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7Xib-0008D5-CJ for incoming@patchwork.ozlabs.org; Wed, 06 Apr 2011 14:44:41 -0400 Received: from [140.186.70.92] (port=36047 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7XaG-0004U4-QW for qemu-devel@nongnu.org; Wed, 06 Apr 2011 14:36:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q7XaE-0001su-0R for qemu-devel@nongnu.org; Wed, 06 Apr 2011 14:36:04 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:33549) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Q7XaD-0001sq-Lf for qemu-devel@nongnu.org; Wed, 06 Apr 2011 14:36:01 -0400 Received: (qmail invoked by alias); 06 Apr 2011 18:36:00 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp030) with SMTP; 06 Apr 2011 20:36:00 +0200 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX19Arg5YrydAyg+qAQOyNjI9/iash6g7jCJqT+nU6o XvI6fYi3/I8+9t To: qemu-devel@nongnu.org From: =?utf-8?b?TGx1w61z?= Date: Wed, 06 Apr 2011 20:34:56 +0200 Message-ID: <20110406183456.22854.99191.stgit@ginnungagap.bsc.es> In-Reply-To: <20110406183341.22854.93929.stgit@ginnungagap.bsc.es> References: <20110406183341.22854.93929.stgit@ginnungagap.bsc.es> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 213.165.64.22 Cc: stefanha@gmail.com, chouteau@adacore.com Subject: [Qemu-devel] [PATCH v2 09/11] trace-state: [simple] add "-trace events" argument to control initial state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When using the "simple" tracing backend, all events are in disabled state by default. 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. This saves the user from manually toggling event states through the monitor interface, as well as enables early tracing for the selected points, much like other more-sophisticated backends like "ust" or "dtrace". Signed-off-by: LluĂ­s Vilanova --- docs/tracing.txt | 5 +++++ qemu-config.c | 3 +++ qemu-options.hx | 18 ++++++++++++++---- vl.c | 26 ++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/docs/tracing.txt b/docs/tracing.txt index 9138dca..26b221f 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -146,6 +146,11 @@ source tree. It may not be as powerful as platform-specific or third-party trace backends but it is portable. This is the recommended trace backend unless you have specific needs for more advanced backends. +==== Enabling trace events from the command line ==== + +The "-trace events=" command line argument can be used to enable the +events listed in from the very beginning of the program. + ==== Monitor commands ==== * info trace diff --git a/qemu-config.c b/qemu-config.c index 8ba0804..7c7357f 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -306,6 +306,9 @@ static QemuOptsList qemu_trace_opts = { { .name = "file", .type = QEMU_OPT_STRING, + },{ + .name = "events", + .type = QEMU_OPT_STRING, }, { /* end if list */ } }, diff --git a/qemu-options.hx b/qemu-options.hx index ef60730..ff8e75d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2358,13 +2358,23 @@ option will prevent QEMU from loading these configuration files at startup. ETEXI #ifdef CONFIG_SIMPLE_TRACE DEF("trace", HAS_ARG, QEMU_OPTION_trace, - "-trace\n" - " Specify a trace file to log traces to\n", + "-trace [file=][,events=]\n" + " specify tracing options\n", QEMU_ARCH_ALL) STEXI -@item -trace +@item -trace [file=@var{file}][,events=@var{file}] @findex -trace -Specify a trace file to log output traces to. + +Specify tracing options. + +@table @option +@item file=@var{file} +Log output traces to @var{file}. +@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. +@end table ETEXI #endif diff --git a/vl.c b/vl.c index 5a9ea51..35d440d 100644 --- a/vl.c +++ b/vl.c @@ -1968,6 +1968,7 @@ int main(int argc, char **argv, char **envp) int defconfig = 1; #if defined(CONFIG_SIMPLE_TRACE) const char *trace_file = NULL; + const char *trace_events_file = NULL; #endif atexit(qemu_run_exit_notifiers); @@ -2766,6 +2767,7 @@ int main(int argc, char **argv, char **envp) opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); if (opts) { trace_file = qemu_opt_get(opts, "file"); + trace_events_file = qemu_opt_get(opts, "events"); } break; #endif @@ -2818,6 +2820,30 @@ int main(int argc, char **argv, char **envp) if (!st_init(trace_file)) { fprintf(stderr, "warning: unable to initialize simple trace backend\n"); } + if (trace_events_file) { + FILE *trace_events_fp = fopen(trace_events_file, "r"); + if (!trace_events_fp) { + fprintf(stderr, "could not open trace events file '%s': %s\n", + trace_events_file, strerror(errno)); + exit(1); + } + char line_buf[1024]; + while (fgets(line_buf, sizeof(line_buf), trace_events_fp)) { + size_t len = strlen(line_buf); + if (len > 1) { /* skip empty lines */ + line_buf[len - 1] = '\0'; + if (!st_change_trace_event_state(line_buf, true)) { + fprintf(stderr, "trace event '%s' does not exist\n", line_buf); + exit(1); + } + } + } + if (fclose(trace_events_fp) != 0) { + fprintf(stderr, "error closing file '%s': %s\n", + trace_events_file, strerror(errno)); + exit(1); + } + } #endif /* If no data_dir is specified then try to find it relative to the