From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=48129 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWkoO-0000Cw-VG for qemu-devel@nongnu.org; Thu, 08 Jul 2010 02:42:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OWkoN-0007d4-DO for qemu-devel@nongnu.org; Thu, 08 Jul 2010 02:42:20 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:60359) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OWkoM-0007cV-Lq for qemu-devel@nongnu.org; Thu, 08 Jul 2010 02:42:19 -0400 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by e28smtp02.in.ibm.com (8.14.4/8.13.1) with ESMTP id o686gCSU022560 for ; Thu, 8 Jul 2010 12:12:12 +0530 Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o686gB8o3522644 for ; Thu, 8 Jul 2010 12:12:11 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o686gBqb001310 for ; Thu, 8 Jul 2010 16:42:11 +1000 Message-ID: <4C357342.3080708@linux.vnet.ibm.com> Date: Thu, 08 Jul 2010 12:12:10 +0530 From: Prerna Saxena MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 3/3] trace: Flush trace buffer on exit References: <1278447241-2709-1-git-send-email-stefanha@linux.vnet.ibm.com> <1278447241-2709-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1278447241-2709-3-git-send-email-stefanha@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Maneesh Soni , sripathik@in.ibm.com, qemu-devel@nongnu.org, Ananth Hi Stefan, On 07/07/2010 01:44 AM, Stefan Hajnoczi wrote: > Signed-off-by: Stefan Hajnoczi > --- > This applies to the tracing branch at: > > http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing-dev > > simpletrace.c | 23 +++++++++++++++-------- > 1 files changed, 15 insertions(+), 8 deletions(-) > > diff --git a/simpletrace.c b/simpletrace.c > index ace009f..9604ea6 100644 > --- a/simpletrace.c > +++ b/simpletrace.c > @@ -22,6 +22,20 @@ static TraceRecord trace_buf[TRACE_BUF_LEN]; > static unsigned int trace_idx; > static FILE *trace_fp; > > +static void flush_trace_buffer(void) > +{ > + if (!trace_fp) { > + trace_fp = fopen("/tmp/trace.log", "w"); > + if (trace_fp) { > + atexit(flush_trace_buffer); > + } > + } > + if (trace_fp) { > + size_t unused; /* for when fwrite(3) is declared warn_unused_result */ > + unused = fwrite(trace_buf, trace_idx * sizeof(trace_buf[0]), 1, trace_fp); I think this would be better denoted as : unused = fwrite(trace_buf, trace_idx * sizeof(TraceRecord), 1, trace_fp); > + } > +} > + > static void trace(TraceEventID event, unsigned long x1, > unsigned long x2, unsigned long x3, > unsigned long x4, unsigned long x5) > @@ -44,15 +58,8 @@ static void trace(TraceEventID event, unsigned long x1, > rec->x5 = x5; > > if (++trace_idx == TRACE_BUF_LEN) { > + flush_trace_buffer(); > trace_idx = 0; > - > - if (!trace_fp) { > - trace_fp = fopen("/tmp/trace.log", "w"); > - } > - if (trace_fp) { > - size_t result = fwrite(trace_buf, sizeof trace_buf, 1, trace_fp); > - result = result; > - } > } > } > I was wondering if we can extend this. One can have a monitor command such as "dump-trace" which would write a partly-filled buffer to file using a call to flush_trace_buffer(). But this has a few caveats. flush_trace_buffer() must reset trace_idx to 0 to prevent duplicate traces to be written once the buffer is filled up. Also, I'm wondering what happens in case qemu is started with -smp 2 or more. We might need to enforce some kind of synchronisation so that threads on other cpus do not log traces while the buffer is being sync'ed. ( For now, I have not been able to get upstream qemu run with -smp. Going forward, this is something that might need to be looked into.) Regards, -- Prerna Saxena Linux Technology Centre, IBM Systems and Technology Lab, Bangalore, India