From patchwork Tue Aug 3 05:37:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prerna Saxena X-Patchwork-Id: 60721 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 F0DC41007D1 for ; Tue, 3 Aug 2010 15:39:35 +1000 (EST) Received: from localhost ([127.0.0.1]:59174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgADs-00052v-0I for incoming@patchwork.ozlabs.org; Tue, 03 Aug 2010 01:39:32 -0400 Received: from [140.186.70.92] (port=45547 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgABd-0004Vq-0N for qemu-devel@nongnu.org; Tue, 03 Aug 2010 01:37:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgABb-00033K-Lv for qemu-devel@nongnu.org; Tue, 03 Aug 2010 01:37:12 -0400 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:53445) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgABa-00032x-UX for qemu-devel@nongnu.org; Tue, 03 Aug 2010 01:37:11 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp02.au.ibm.com (8.14.4/8.13.1) with ESMTP id o735X3tD000636 for ; Tue, 3 Aug 2010 15:33:03 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o735b5xQ1171602 for ; Tue, 3 Aug 2010 15:37:05 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o735b53x017074 for ; Tue, 3 Aug 2010 15:37:05 +1000 Received: from zephyr (K50wks273921wss.in.ibm.com [9.124.35.83]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o735b3XT017039; Tue, 3 Aug 2010 15:37:04 +1000 Date: Tue, 3 Aug 2010 11:07:00 +0530 From: Prerna Saxena To: qemu-devel Message-ID: <20100803110700.75d7c3b0@zephyr> Organization: IBM X-Mailer: Claws Mail 3.7.5 (GTK+ 2.16.6; i586-redhat-linux-gnu) Mime-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Ananth Narayan , Stefan Hajnoczi Subject: [Qemu-devel] [Tracing][PATCH] Add options to specify trace file name at startup and runtime. 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 This patch adds an optional command line switch '-trace' to specify the filename to write traces to, when qemu starts. Eg, If compiled with the 'simple' trace backend, [temp@system]$ qemu -trace FILENAME IMAGE Allows the binary traces to be written to FILENAME instead of the option set at config-time. Also, this adds monitor sub-command 'set' to trace-file commands to dynamically change trace log file at runtime. Eg, (qemu)trace-file set FILENAME This allows one to set trace outputs to FILENAME from the default specified at startup. Signed-off-by: Prerna Saxena --- monitor.c | 6 ++++++ qemu-monitor.hx | 6 +++--- qemu-options.hx | 11 +++++++++++ simpletrace.c | 41 ++++++++++++++++++++++++++++++++--------- tracetool | 1 + vl.c | 22 ++++++++++++++++++++++ 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/monitor.c b/monitor.c index 1e35a6b..8e2a3a6 100644 --- a/monitor.c +++ b/monitor.c @@ -544,6 +544,7 @@ static void do_change_trace_event_state(Monitor *mon, const QDict *qdict) static void do_trace_file(Monitor *mon, const QDict *qdict) { const char *op = qdict_get_try_str(qdict, "op"); + const char *arg = qdict_get_try_str(qdict, "arg"); if (!op) { st_print_trace_file_status((FILE *)mon, &monitor_fprintf); @@ -553,8 +554,13 @@ static void do_trace_file(Monitor *mon, const QDict *qdict) st_set_trace_file_enabled(false); } else if (!strcmp(op, "flush")) { st_flush_trace_buffer(); + } else if (!strcmp(op, "set")) { + if (arg) { + st_set_trace_file(arg); + } } else { monitor_printf(mon, "unexpected argument \"%s\"\n", op); + monitor_printf(mon, "Options are: [on | off| flush| set FILENAME]"); } } #endif diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 25887bd..adfaf2b 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -276,9 +276,9 @@ ETEXI { .name = "trace-file", - .args_type = "op:s?", - .params = "op [on|off|flush]", - .help = "open, close, or flush trace file", + .args_type = "op:s?,arg:F?", + .params = "on|off|flush|set [arg]", + .help = "open, close, or flush trace file, or set a new file name", .mhandler.cmd = do_trace_file, }, diff --git a/qemu-options.hx b/qemu-options.hx index d1d2272..aea9675 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2223,6 +2223,17 @@ Normally QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and @var{sysconfdir}/target-@var{ARCH}.conf on startup. The @code{-nodefconfig} 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", + QEMU_ARCH_ALL) +STEXI +@item -trace +@findex -trace +Specify a trace file to log output traces to. +ETEXI +#endif HXCOMM This is the last statement. Insert new options before this line! STEXI diff --git a/simpletrace.c b/simpletrace.c index 71110b3..5812fe9 100644 --- a/simpletrace.c +++ b/simpletrace.c @@ -20,25 +20,48 @@ enum { static TraceRecord trace_buf[TRACE_BUF_LEN]; static unsigned int trace_idx; static FILE *trace_fp; -static bool trace_file_enabled = true; +static char *trace_file_name = NULL; +static bool trace_file_enabled = false; void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) { - stream_printf(stream, "Trace file \"" CONFIG_TRACE_FILE "\" %s.\n", - getpid(), trace_file_enabled ? "on" : "off"); + stream_printf(stream, "Trace file \"%s\" %s.\n", + trace_file_name, trace_file_enabled ? "on" : "off"); } static bool open_trace_file(void) { - char *filename; + trace_fp = fopen(trace_file_name, "w"); + return trace_fp != NULL; +} - if (asprintf(&filename, CONFIG_TRACE_FILE, getpid()) < 0) { - return false; +/** + * set_trace_file : To set the name of a trace file. + * @file : pointer to the name to be set. + * If NULL, set to the default name- set at config time. + */ +bool st_set_trace_file(const char *file) +{ + if (trace_file_enabled) { + st_set_trace_file_enabled(false); } - trace_fp = fopen(filename, "w"); - free(filename); - return trace_fp != NULL; + if (trace_file_name) { + free(trace_file_name); + } + + if (!file) { + if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) { + return false; + } + } else { + if (asprintf(&trace_file_name, "%s", file) < 0) { + return false; + } + } + + st_set_trace_file_enabled(true); + return true; } static void flush_trace_file(void) diff --git a/tracetool b/tracetool index ac832af..5b979f5 100755 --- a/tracetool +++ b/tracetool @@ -158,6 +158,7 @@ void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)); void st_flush_trace_buffer(void); void st_set_trace_file_enabled(bool enable); +bool st_set_trace_file(const char *file); void change_trace_event_state(const char *tname, bool tstate); EOF diff --git a/vl.c b/vl.c index 920717a..6d68e38 100644 --- a/vl.c +++ b/vl.c @@ -47,6 +47,10 @@ #include #include #include +#ifdef CONFIG_SIMPLE_TRACE +#include "trace.h" +#endif + #ifdef CONFIG_BSD #include #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) @@ -1822,6 +1826,9 @@ int main(int argc, char **argv, char **envp) int show_vnc_port = 0; int defconfig = 1; +#ifdef CONFIG_SIMPLE_TRACE + char *trace_file = NULL; +#endif atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); @@ -2590,6 +2597,12 @@ int main(int argc, char **argv, char **envp) } xen_mode = XEN_ATTACH; break; +#ifdef CONFIG_SIMPLE_TRACE + case QEMU_OPTION_trace: + trace_file = (char *) qemu_malloc(strlen(optarg) + 1); + strcpy(trace_file, optarg); + break; +#endif case QEMU_OPTION_readconfig: { int ret = qemu_read_config_file(optarg); @@ -2633,6 +2646,15 @@ int main(int argc, char **argv, char **envp) data_dir = CONFIG_QEMU_DATADIR; } +#ifdef CONFIG_SIMPLE_TRACE + /* + * Set the trace file name, if specified. + */ + st_set_trace_file(trace_file); + if (trace_file) { + qemu_free(trace_file); + } +#endif /* * Default to max_cpus = smp_cpus, in case the user doesn't * specify a max_cpus value.