From patchwork Mon Sep 6 15:14:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 63931 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 C81F0B7116 for ; Tue, 7 Sep 2010 01:16:47 +1000 (EST) Received: from localhost ([127.0.0.1]:50112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsdR0-00058i-MA for incoming@patchwork.ozlabs.org; Mon, 06 Sep 2010 11:16:38 -0400 Received: from [140.186.70.92] (port=47933 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsdPR-00055L-Oe for qemu-devel@nongnu.org; Mon, 06 Sep 2010 11:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OsdPN-0003yX-Sz for qemu-devel@nongnu.org; Mon, 06 Sep 2010 11:15:01 -0400 Received: from mtagate4.de.ibm.com ([195.212.17.164]:57481) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OsdPN-0003xr-G9 for qemu-devel@nongnu.org; Mon, 06 Sep 2010 11:14:57 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate4.de.ibm.com (8.13.1/8.13.1) with ESMTP id o86FEtkZ031200 for ; Mon, 6 Sep 2010 15:14:55 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o86FEqSc3403830 for ; Mon, 6 Sep 2010 17:14:55 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o86FEpIB018028 for ; Mon, 6 Sep 2010 17:14:51 +0200 Received: from stefan-thinkpad.manchester-maybrook.uk.ibm.com (dyn-9-174-219-60.manchester-maybrook.uk.ibm.com [9.174.219.60]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o86FEmNb017891; Mon, 6 Sep 2010 17:14:50 +0200 From: Stefan Hajnoczi To: Date: Mon, 6 Sep 2010 16:14:02 +0100 Message-Id: <1283786051-29530-6-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1283786051-29530-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1283786051-29530-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Blue Swirl , Anthony Liguori , "Michael S. Tsirkin" , Stefan Hajnoczi , Prerna Saxena Subject: [Qemu-devel] [PATCH 05/14] trace: 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 From: Prerna Saxena 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: 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 : 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. Edited-by: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi --- configure | 12 ++++++++++++ simpletrace.c | 21 +++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 5afb3b5..234e75b 100755 --- a/configure +++ b/configure @@ -318,6 +318,7 @@ check_utests="no" user_pie="no" zero_malloc="" trace_backend="nop" +trace_file="trace" # OS specific if check_define __linux__ ; then @@ -522,6 +523,8 @@ for opt do ;; --trace-backend=*) trace_backend="$optarg" ;; + --trace-file=*) trace_file="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static) @@ -901,6 +904,8 @@ 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" +echo " --trace-file=NAME Full PATH,NAME of file to store traces" +echo " Default:trace-" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1 @@ -2206,6 +2211,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" @@ -2471,6 +2477,12 @@ echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak if test "$trace_backend" = "simple"; then echo "CONFIG_SIMPLE_TRACE=y" >> $config_host_mak fi +# Set the appropriate trace file. +if test "$trace_backend" = "simple"; then + trace_file="\"$trace_file-%u\"" +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 688959a..97045a6 100644 --- a/simpletrace.c +++ b/simpletrace.c @@ -54,13 +54,26 @@ static bool write_header(FILE *fp) return fwrite(&header, sizeof header, 1, fp) == 1; } +static bool open_trace_file(void) +{ + char *filename; + + if (asprintf(&filename, CONFIG_TRACE_FILE, getpid()) < 0) { + return false; + } + + trace_fp = fopen(filename, "w"); + free(filename); + if (!trace_fp) { + return false; + } + return write_header(trace_fp); +} + static void flush_trace_buffer(void) { if (!trace_fp) { - trace_fp = fopen("trace.log", "w"); - if (trace_fp) { - write_header(trace_fp); - } + open_trace_file(); } if (trace_fp) { size_t unused; /* for when fwrite(3) is declared warn_unused_result */