aboutsummaryrefslogtreecommitdiff
path: root/simpletrace.py
diff options
context:
space:
mode:
authorBlue Swirl <blauwirbel@gmail.com>2011-01-20 20:54:21 +0000
committerBlue Swirl <blauwirbel@gmail.com>2011-01-20 20:54:21 +0000
commit4c3b5a4891c44ebbc23d80f95e5b66e2ec66b8b1 (patch)
tree6333f8e376ca8de657b8a5f4fdc76f937214bb65 /simpletrace.py
parent8e5977e5f588b2d4b74831d11860191f815b4c5b (diff)
Add scripts directory
Move build and user scripts into scripts directory. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'simpletrace.py')
-rwxr-xr-xsimpletrace.py93
1 files changed, 0 insertions, 93 deletions
diff --git a/simpletrace.py b/simpletrace.py
deleted file mode 100755
index 553a72709f..0000000000
--- a/simpletrace.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/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
-
-header_event_id = 0xffffffffffffffff
-header_magic = 0xf2b177cb0aa429b4
-header_version = 0
-
-trace_fmt = '=QQQQQQQQ'
-trace_len = struct.calcsize(trace_fmt)
-event_re = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*')
-
-def err(msg):
- sys.stderr.write(msg + '\n')
- sys.exit(1)
-
-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 = {}
- event_num = 0
- for line in fobj:
- m = event_re.match(line.strip())
- if m is None:
- continue
-
- disable, name, args = m.groups()
- events[event_num] = (name,) + get_argnames(args)
- event_num += 1
- 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)
-
-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):
- def __init__(self, events):
- self.events = events
- self.last_timestamp = None
-
- def format_record(self, rec):
- if self.last_timestamp is None:
- self.last_timestamp = rec[1]
- delta_ns = rec[1] - self.last_timestamp
- self.last_timestamp = rec[1]
-
- event = self.events[rec[0]]
- fields = [event[0], '%0.3f' % (delta_ns / 1000.0)]
- for i in xrange(1, len(event)):
- fields.append('%s=0x%x' % (event[i], rec[i + 1]))
- return ' '.join(fields)
-
-if len(sys.argv) != 3:
- err('usage: %s <trace-events> <trace-file>' % sys.argv[0])
-
-events = parse_events(open(sys.argv[1], 'r'))
-formatter = Formatter(events)
-for rec in read_trace_file(open(sys.argv[2], 'rb')):
- print formatter.format_record(rec)