From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: sripathik@in.ibm.com,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
Prerna Saxena <prerna@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 3/3] trace: Flush trace buffer on exit
Date: Tue, 6 Jul 2010 21:14:01 +0100 [thread overview]
Message-ID: <1278447241-2709-3-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1278447241-2709-1-git-send-email-stefanha@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
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);
+ }
+}
+
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;
- }
}
}
--
1.7.1
next prev parent reply other threads:[~2010-07-06 20:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-06 20:13 [Qemu-devel] [PATCH 1/3] trace: Document programmatically enabling/disabling trace events Stefan Hajnoczi
2010-07-06 20:14 ` [Qemu-devel] [PATCH 2/3] trace: Conform to QEMU coding style Stefan Hajnoczi
2010-07-06 20:14 ` Stefan Hajnoczi [this message]
2010-07-08 6:42 ` [Qemu-devel] [PATCH 3/3] trace: Flush trace buffer on exit Prerna Saxena
2010-07-08 8:28 ` Stefan Hajnoczi
2010-07-08 8:34 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1278447241-2709-3-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=prerna@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=sripathik@in.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).