ia64/xen-unstable

view tools/xentrace/xentrace_format @ 1372:5a6113c65ead

bitkeeper revision 1.891.1.12 (40a248b0WTGoOa9206iWkyGN0mTPNw)

Allow forcing of IRQ trigger-type to edge or level
(NB. DANGEROUS!).
author kaf24@scramble.cl.cam.ac.uk
date Wed May 12 15:54:24 2004 +0000 (2004-05-12)
parents cab392bd2c32
children 6cf25fb7eebd
line source
1 #!/usr/bin/env python
3 # by Mark Williamson, (C) 2004 Intel Research Cambridge
5 # Program for reformatting trace buffer output according to user-supplied rules
7 import re, sys, string, signal, struct
9 def usage():
10 print >> sys.stderr, \
11 "Usage: " + sys.argv[0] + """ defs-file
12 Parses trace data in binary format, as output by Xentrace and
13 reformats it according to the rules in a file of definitions. The
14 rules in this file should have the format ({ and } show grouping
15 and are not part of the syntax):
17 {event_id}{whitespace}{text format string}
19 The textual format string may include format specifiers, such as:
20 %(cpu)d, %(tsc)d, %(event)d, %(1)d, %(2)d, %(3)d, %(4)d, %(5)d
21 [ the 'd' format specifier outputs in decimal, alternatively 'x'
22 will output in hexadecimal and 'o' will output in octal ]
24 Which correspond to the CPU number, event ID, timestamp counter and
25 the 5 data fields from the trace record. There should be one such
26 rule for each type of event.
28 Depending on your system and the volume of trace buffer data,
29 this script may not be able to keep up with the output of xentrace
30 if it is piped directly. In these circumstances you should have
31 xentrace output to a file for processing off-line.
32 """
33 sys.exit(1)
35 def read_defs(defs_file):
36 defs = {}
38 fd = open(defs_file)
40 reg = re.compile('(\S+)\s+(\S.*)')
42 while True:
43 line = fd.readline()
44 if not line:
45 break
47 m = reg.match(line)
49 if not m: print >> sys.stderr, "Bad format file" ; sys.exit(1)
51 defs[str(eval(m.group(1)))] = m.group(2)
53 return defs
55 def sighand(x,y):
56 global interrupted
57 interrupted = 1
59 ##### Main code
61 if len(sys.argv) < 2:
62 usage()
64 signal.signal(signal.SIGTERM, sighand)
65 signal.signal(signal.SIGHUP, sighand)
66 signal.signal(signal.SIGINT, sighand)
68 interrupted = 0
70 defs = read_defs(sys.argv[1])
72 # structure of trace record + prepended CPU id (as output by xentrace):
73 # CPU(I) TSC(Q) EVENT(L) D1(L) D2(L) D3(L) D4(L) D5(L)
74 TRCREC = "IQLLLLLL"
76 while not interrupted:
77 try:
78 line = sys.stdin.read(struct.calcsize(TRCREC))
79 if not line:
80 break
82 (cpu, tsc, event, d1, d2, d3, d4, d5) = struct.unpack(TRCREC, line)
84 args = {'cpu' : cpu,
85 'tsc' : tsc,
86 'event' : event,
87 '1' : d1,
88 '2' : d2,
89 '3' : d3,
90 '4' : d4,
91 '5' : d5 }
93 if defs.has_key(str(event)): print defs[str(event)] % args
94 # silently skip lines we don't have a format for - a 'complain' option
95 # should be added if needed
97 except IOError, struct.error: sys.exit()