* [Qemu-devel] [PATCH v2] trace: Flush trace buffer on exit
@ 2010-07-09 11:23 Stefan Hajnoczi
0 siblings, 0 replies; only message in thread
From: Stefan Hajnoczi @ 2010-07-09 11:23 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Hajnoczi, Prerna Saxena
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
This patch is against the tracing branch:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing
v2:
* Reset trace_idx in flush_trace_buffer().
simpletrace.c | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/simpletrace.c b/simpletrace.c
index ace009f..4a4203e 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -22,6 +22,23 @@ 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);
+ }
+
+ /* Discard written trace records */
+ trace_idx = 0;
+}
+
static void trace(TraceEventID event, unsigned long x1,
unsigned long x2, unsigned long x3,
unsigned long x4, unsigned long x5)
@@ -44,15 +61,7 @@ static void trace(TraceEventID event, unsigned long x1,
rec->x5 = x5;
if (++trace_idx == TRACE_BUF_LEN) {
- 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;
- }
+ flush_trace_buffer();
}
}
--
1.7.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-07-09 11:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-09 11:23 [Qemu-devel] [PATCH v2] trace: Flush trace buffer on exit Stefan Hajnoczi
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).