diff options
author | mwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net> | 2004-03-11 19:55:00 +0000 |
---|---|---|
committer | mwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net> | 2004-03-11 19:55:00 +0000 |
commit | 578734ab97aeef213ceabd85ac7984ce029706b3 (patch) | |
tree | 46d4d3e261321fbcc8d0128e5c3cece65d1e2aec /tools/xentrace/xentrace_format | |
parent | 76fff2563fe96d97805f9873334a69122a1406f2 (diff) | |
download | xen-578734ab97aeef213ceabd85ac7984ce029706b3.tar.gz xen-578734ab97aeef213ceabd85ac7984ce029706b3.tar.bz2 xen-578734ab97aeef213ceabd85ac7984ce029706b3.zip |
bitkeeper revision 1.784 (4050c414tIvxGfQ8IUNIXoAjpoXBVA)
Updated script names and added man pages for all the xentrace tools.
Diffstat (limited to 'tools/xentrace/xentrace_format')
-rw-r--r-- | tools/xentrace/xentrace_format | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tools/xentrace/xentrace_format b/tools/xentrace/xentrace_format new file mode 100644 index 0000000000..b8f8d018ce --- /dev/null +++ b/tools/xentrace/xentrace_format @@ -0,0 +1,96 @@ +#!/usr/bin/env python + +# by Mark Williamson, (C) 2004 Intel Research Cambridge + +# Program for reformatting trace buffer output according to user-supplied rules + +import re, sys, string, signal + +def usage(): + print >> sys.stderr, \ + "Usage: " + sys.argv[0] + """ defs-file + Parses trace data in ASCII format and reformats it according to the + rules in a file of definitions. The rules in this file should have + the format ({ and } show grouping and are not part of the syntax): + + {event_id}{whitespace}{text format string} + + The textual format string may include the format specifiers: + %(cpu)s, %(tsc), %(event)s, %(1)s, %(2)s, %(3)s, %(4)s, %(5)s + + Which correspond to the CPU number, event ID, timestamp counter and + the 5 data fields from the trace record. There should be one such + rule for each type of event. + + Depending on your system and the volume of trace buffer data, + this script may not be able to keep up with the output of xentrace + if it is piped directly. In these circumstances you should have + xentrace output to a file for processing off-line. + """ + sys.exit(1) + +def read_defs(defs_file): + defs = {} + + fd = open(defs_file) + + reg = re.compile('(\d+)\s+(\S.*)') + + while True: + line = fd.readline() + if not line: + break + + m = reg.match(line) + + if not m: print >> sys.stderr, "Bad format file" ; sys.exit(1) + + defs[m.group(1)] = m.group(2) + + return defs + +def sighand(x,y): + global interrupted + interrupted = 1 + +##### Main code + +if len(sys.argv) < 2: + usage() + +signal.signal(signal.SIGTERM, sighand) +signal.signal(signal.SIGHUP, sighand) +signal.signal(signal.SIGINT, sighand) + +interrupted = 0 + +defs = read_defs(sys.argv[1]) + +reg = re.compile('(\d+) (\d+) (\d+) (.*)') + +while not interrupted: + try: + line = sys.stdin.readline() + if not line: + break + + m = reg.match(line) + + if not m: print >> sys.stderr, "Invalid input line." + + s = string.split(m.group(4)) + + args = {'cpu' : m.group(1), + 'tsc' : m.group(2), + 'event' : m.group(3) } + + i = 0 + for item in s: + args[str(i)] = item + i += 1 + + if defs.has_key(m.group(3)): print defs[m.group(3)] % args + # silently skip lines we don't have a format for - a 'complain' option + # should be added if needed + + except IOError: sys.exit() |