From patchwork Thu Jul 22 15:58:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Tracing,2/4] Add copyright and doc comments to simpletrace.py From: Stefan Hajnoczi X-Patchwork-Id: 59608 Message-Id: <1279814326-9422-2-git-send-email-stefanha@linux.vnet.ibm.com> To: Cc: Stefan Hajnoczi , Prerna Saxena Date: Thu, 22 Jul 2010 16:58:44 +0100 Signed-off-by: Stefan Hajnoczi --- 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