* [Qemu-devel] [Tracing] [PATCH 1/4] Move simple trace prototypes to header file
@ 2010-07-22 15:58 Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 2/4] Add copyright and doc comments to simpletrace.py Stefan Hajnoczi
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2010-07-22 15:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Hajnoczi, Prerna Saxena
Simple trace prototypes should not be in the tracetool code generator.
It is easier to modify and debug the code if they are in a regular C
header file.
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
simpletrace.h | 37 +++++++++++++++++++++++++++++++++++++
tracetool | 22 +---------------------
2 files changed, 38 insertions(+), 21 deletions(-)
create mode 100644 simpletrace.h
diff --git a/simpletrace.h b/simpletrace.h
new file mode 100644
index 0000000..bec8d62
--- /dev/null
+++ b/simpletrace.h
@@ -0,0 +1,37 @@
+/*
+ * Simple trace backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef SIMPLETRACE_H
+#define SIMPLETRACE_H
+
+#include <stdbool.h>
+#include <stdio.h>
+
+typedef unsigned int TraceEventID;
+
+typedef struct {
+ const char *tp_name;
+ bool state;
+} TraceEvent;
+
+void trace0(TraceEventID event);
+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);
+void trace4(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4);
+void trace5(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4, unsigned long x5);
+void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...));
+void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...));
+void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...));
+void st_flush_trace_buffer(void);
+void st_set_trace_file_enabled(bool enable);
+void change_trace_event_state(const char *tname, bool tstate);
+
+#endif /* SIMPLETRACE_H */
diff --git a/tracetool b/tracetool
index ac832af..4890e66 100755
--- a/tracetool
+++ b/tracetool
@@ -138,27 +138,7 @@ linetoc_end_nop()
linetoh_begin_simple()
{
cat <<EOF
-#include <stdbool.h>
-
-typedef unsigned int TraceEventID;
-
-typedef struct {
- const char *tp_name;
- bool state;
-} TraceEvent;
-
-void trace0(TraceEventID event);
-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);
-void trace4(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4);
-void trace5(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4, unsigned long x5);
-void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...));
-void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...));
-void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...));
-void st_flush_trace_buffer(void);
-void st_set_trace_file_enabled(bool enable);
-void change_trace_event_state(const char *tname, bool tstate);
+#include "simpletrace.h"
EOF
simple_event_num=0
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [Tracing] [PATCH 2/4] Add copyright and doc comments to simpletrace.py
2010-07-22 15:58 [Qemu-devel] [Tracing] [PATCH 1/4] Move simple trace prototypes to header file Stefan Hajnoczi
@ 2010-07-22 15:58 ` Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 3/4] Add a header to the trace file format Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 4/4] Disable posix_aio_process_queue by default Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2010-07-22 15:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Hajnoczi, Prerna Saxena
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
simpletrace.py | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/simpletrace.py b/simpletrace.py
index 2271860..c951023 100755
--- a/simpletrace.py
+++ b/simpletrace.py
@@ -1,4 +1,14 @@
#!/usr/bin/env python
+#
+# Pretty-printer for simple trace backend binary trace files
+#
+# Copyright IBM, Corp. 2010
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+# For help see docs/tracing.txt
+
import sys
import struct
import re
@@ -8,7 +18,10 @@ trace_len = struct.calcsize(trace_fmt)
event_re = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\)\s+"([^"]*)"')
def parse_events(fobj):
+ """Parse a trace-events file."""
+
def get_argnames(args):
+ """Extract argument names from a parameter list."""
return tuple(arg.split()[-1].lstrip('*') for arg in args.split(','))
events = {}
@@ -27,17 +40,21 @@ def parse_events(fobj):
return events
def read_record(fobj):
+ """Deserialize a trace record from a file."""
s = fobj.read(trace_len)
if len(s) != trace_len:
return None
return struct.unpack(trace_fmt, s)
class Formatter(object):
+ """Trace record pretty-printer"""
+
def __init__(self, events):
self.events = events
self.last_timestamp = None
def format_record(self, rec):
+ """Return a string describing a given trace record."""
if self.last_timestamp is None:
self.last_timestamp = rec[1]
delta_ns = rec[1] - self.last_timestamp
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [Tracing] [PATCH 3/4] Add a header to the trace file format
2010-07-22 15:58 [Qemu-devel] [Tracing] [PATCH 1/4] Move simple trace prototypes to header file Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 2/4] Add copyright and doc comments to simpletrace.py Stefan Hajnoczi
@ 2010-07-22 15:58 ` Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 4/4] Disable posix_aio_process_queue by default Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2010-07-22 15:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Hajnoczi, Prerna Saxena
The trace file format needs a header so that future extension is
possible. There is a version number that can be bumped when file format
changes are made.
There is still the issue of endianness and sizeof(long). This patch
does not address those.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
simpletrace.c | 17 ++++++++++++++++-
simpletrace.py | 33 ++++++++++++++++++++++++++-------
2 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/simpletrace.c b/simpletrace.c
index 71110b3..df21609 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -28,6 +28,17 @@ void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream,
getpid(), trace_file_enabled ? "on" : "off");
}
+static bool write_header(FILE *fp)
+{
+ TraceRecord header = {
+ .event = -1UL, /* max avoids conflicting with TraceEventIDs */
+ .timestamp_ns = 0xf2b177cb0aa429b4, /* magic number */
+ .x1 = 0, /* bump this version number if file format changes */
+ };
+
+ return fwrite(&header, sizeof header, 1, fp) == 1;
+}
+
static bool open_trace_file(void)
{
char *filename;
@@ -38,7 +49,11 @@ static bool open_trace_file(void)
trace_fp = fopen(filename, "w");
free(filename);
- return trace_fp != NULL;
+ if (!trace_fp) {
+ return false;
+ }
+
+ return write_header(trace_fp);
}
static void flush_trace_file(void)
diff --git a/simpletrace.py b/simpletrace.py
index c951023..16ab2e7 100755
--- a/simpletrace.py
+++ b/simpletrace.py
@@ -13,10 +13,18 @@ import sys
import struct
import re
+header_event_id = 0xffffffffffffffff
+header_magic = 0xf2b177cb0aa429b4
+header_version = 0
+
trace_fmt = 'LLLLLLL'
trace_len = struct.calcsize(trace_fmt)
event_re = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\)\s+"([^"]*)"')
+def err(msg):
+ sys.stderr.write(msg + '\n')
+ sys.exit(1)
+
def parse_events(fobj):
"""Parse a trace-events file."""
@@ -46,6 +54,22 @@ def read_record(fobj):
return None
return struct.unpack(trace_fmt, s)
+def read_trace_file(fobj):
+ """Deserialize trace records from a file."""
+ header = read_record(fobj)
+ if header is None or \
+ header[0] != header_event_id or \
+ header[1] != header_magic or \
+ header[2] != header_version:
+ err('not a trace file or incompatible version')
+
+ while True:
+ rec = read_record(fobj)
+ if rec is None:
+ break
+
+ yield rec
+
class Formatter(object):
"""Trace record pretty-printer"""
@@ -67,15 +91,10 @@ class Formatter(object):
return ' '.join(fields)
if len(sys.argv) != 3:
- sys.stderr.write('usage: %s <trace-events> <trace-file>\n' % sys.argv[0])
- sys.exit(1)
+ err('usage: %s <trace-events> <trace-file>' % sys.argv[0])
events = parse_events(open(sys.argv[1], 'r'))
f = open(sys.argv[2], 'rb')
formatter = Formatter(events)
-while True:
- rec = read_record(f)
- if rec is None:
- break
-
+for rec in read_trace_file(f):
print formatter.format_record(rec)
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [Tracing] [PATCH 4/4] Disable posix_aio_process_queue by default
2010-07-22 15:58 [Qemu-devel] [Tracing] [PATCH 1/4] Move simple trace prototypes to header file Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 2/4] Add copyright and doc comments to simpletrace.py Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 3/4] Add a header to the trace file format Stefan Hajnoczi
@ 2010-07-22 15:58 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2010-07-22 15:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Hajnoczi, Prerna Saxena
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
trace-events | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/trace-events b/trace-events
index 5304826..a50215f 100644
--- a/trace-events
+++ b/trace-events
@@ -63,4 +63,4 @@ disable virtio_blk_handle_write(void *req, unsigned long sector, unsigned long n
# posix-aio-compat.c
disable paio_submit(void *acb, void *opaque, unsigned long sector_num, unsigned long nb_sectors, unsigned long type) "acb %p opaque %p sector_num %lu nb_sectors %lu type %lu"
-posix_aio_process_queue(void *acb, void *opaque, int type, int ret, uint64_t blocking_duration) "acb %p opaque %p type %d ret %d blocking_duration %lx"
+disable posix_aio_process_queue(void *acb, void *opaque, int type, int ret, uint64_t blocking_duration) "acb %p opaque %p type %d ret %d blocking_duration %lx"
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-07-22 15:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-22 15:58 [Qemu-devel] [Tracing] [PATCH 1/4] Move simple trace prototypes to header file Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 2/4] Add copyright and doc comments to simpletrace.py Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 3/4] Add a header to the trace file format Stefan Hajnoczi
2010-07-22 15:58 ` [Qemu-devel] [Tracing] [PATCH 4/4] Disable posix_aio_process_queue by default 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).