@@ -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
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> --- simpletrace.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)