From patchwork Fri Jul 9 11:00:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prerna Saxena X-Patchwork-Id: 58384 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 884BFB6F10 for ; Fri, 9 Jul 2010 21:03:13 +1000 (EST) Received: from localhost ([127.0.0.1]:49581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OXBML-0000hy-KV for incoming@patchwork.ozlabs.org; Fri, 09 Jul 2010 07:03:09 -0400 Received: from [140.186.70.92] (port=35153 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OXBJn-0008HR-5n for qemu-devel@nongnu.org; Fri, 09 Jul 2010 07:00:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OXBJl-0000Bu-6A for qemu-devel@nongnu.org; Fri, 09 Jul 2010 07:00:30 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:50004) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OXBJk-0000BK-Ln for qemu-devel@nongnu.org; Fri, 09 Jul 2010 07:00:29 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp01.au.ibm.com (8.14.4/8.13.1) with ESMTP id o69AvkO8008804 for ; Fri, 9 Jul 2010 20:57:46 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o69B0OhS1769544 for ; Fri, 9 Jul 2010 21:00:24 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o69B0OO3001938 for ; Fri, 9 Jul 2010 21:00:24 +1000 Received: from zephyr ([9.124.35.83]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o69B0MHV001884; Fri, 9 Jul 2010 21:00:23 +1000 Date: Fri, 9 Jul 2010 16:30:19 +0530 From: Prerna Saxena To: qemu-devel Message-ID: <20100709163019.2dc123bc@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: Maneesh Soni , Ananth Narayan , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH][Tracing] Specify trace file name 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 [PATCH] Allow users to specify a file for trace-outputs at configuration. Also, allow trace files to be annotated by so each qemu instance has unique traces. The trace file name can be passed as a config option: --trace-file=/path/to/file (Default : /tmp/trace ) At runtime, the pid of the qemu process is appended to the filename so that mutiple qemu instances do not have overlapping logs. Eg : /tmp/trace-1234 for qemu launched with pid 1234. I have yet to test this on windows. getpid() is used at many places in code(including vnc.c), so I'm hoping this would be okay too. Signed-off-by: Prerna Saxena --- configure | 20 ++++++++++++++++++++ simpletrace.c | 13 ++++++++++++- tracetool | 1 + vl.c | 8 ++++++++ 4 files changed, 41 insertions(+), 1 deletions(-) diff --git a/configure b/configure index 02bf602..18cb6ab 100755 --- a/configure +++ b/configure @@ -313,6 +313,7 @@ check_utests="no" user_pie="no" zero_malloc="" trace_backend="nop" +trace_file="" # OS specific if check_define __linux__ ; then @@ -517,6 +518,8 @@ for opt do ;; --trace-backend=*) trace_backend="$optarg" ;; + --trace-file=*) trace_file="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static) @@ -876,6 +879,9 @@ echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" echo " --trace-backend=B Trace backend nop simple ust" +echo " --trace-file=NAME Full PATH,NAME of file to store traces" +echo " Default:/tmp/trace-" +echo " Default:trace- on Windows" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1 @@ -2132,6 +2138,7 @@ echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" echo "Trace backend $trace_backend" +echo "Trace Output File $trace_file-" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -2387,6 +2394,19 @@ fi if test "$trace_backend" = "ust"; then LIBS="-lust $LIBS" fi +# Set the appropriate trace file. +if test "$trace_backend" = "simple"; then + if test "$trace_file" = ""; then + if test "$mingw32" = "yes" ; then + trace_file="\"trace-%u\"" + else + trace_file="\"/tmp/trace-%u\"" + fi + else + trace_file="\"$trace_file-%u\"" + fi +fi +echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak diff --git a/simpletrace.c b/simpletrace.c index 57c41fc..4f3228f 100644 --- a/simpletrace.c +++ b/simpletrace.c @@ -20,6 +20,16 @@ static TraceRecord trace_buf[TRACE_BUF_LEN]; static unsigned int trace_idx; static FILE *trace_fp; +char* trace_file_name; + +/** + * Initialize trace file name. + */ +int init_trace_file(void) +{ + return asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()); +} + static void trace(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4, unsigned long x5) { @@ -40,7 +50,7 @@ static void trace(TraceEventID event, unsigned long x1, trace_idx = 0; if (!trace_fp) { - trace_fp = fopen("/tmp/trace.log", "w"); + trace_fp = fopen(trace_file_name, "w"); } if (trace_fp) { size_t result = fwrite(trace_buf, sizeof trace_buf, 1, trace_fp); @@ -78,6 +88,7 @@ void do_info_trace(Monitor *mon) trace_buf[i].event, trace_buf[i].x1, trace_buf[i].x2, trace_buf[i].x3, trace_buf[i].x4, trace_buf[i].x5); } + monitor_printf(mon, "Trace output logged at %s", trace_file_name); } void do_info_all_trace_events(Monitor *mon) diff --git a/tracetool b/tracetool index c77280d..05ece45 100755 --- a/tracetool +++ b/tracetool @@ -125,6 +125,7 @@ typedef struct { bool state; } TraceEvent; +int init_trace_file(void); void trace1(TraceEventID event, unsigned long x1); void trace2(TraceEventID event, unsigned long x1, unsigned long x2); void trace3(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3); diff --git a/vl.c b/vl.c index 920717a..adc28ef 100644 --- a/vl.c +++ b/vl.c @@ -95,6 +95,10 @@ extern int madvise(caddr_t, size_t, int); #include #endif +#ifdef CONFIG_SIMPLE_TRACE +#include "trace.h" +#endif + #ifdef CONFIG_SDL #if defined(__APPLE__) || defined(main) #include @@ -2758,6 +2762,10 @@ int main(int argc, char **argv, char **envp) exit(1); } + /* Init tracing, if configured */ +#ifdef CONFIG_SIMPLE_TRACE + init_trace_file(); +#endif /* init the bluetooth world */ if (foreach_device_config(DEV_BT, bt_parse)) exit(1);