Debian Codegraph @

rpython/jit/tool/loopcounter.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """
3 Parse and display the traces produced by pypy-c-jit when PYPYLOG is set.
4 """
5 from __future__ import print_function
6
7 import sys
8 import optparse
9 import re
10
11 def get_timestamp(line):
12 match = re.match(r'\[([0-9a-f]*)\] .*', line)
13 return int(match.group(1), 16)
14
15 def count_loops_and_bridges(log):
16 loops = 0
17 bridges = 0
18 time0 = None
19 lines = iter(log)
20 for line in lines:
21 if time0 is None and line.startswith('['):
22 time0 = get_timestamp(line)
23 if '{jit-mem-looptoken-' in line:
24 time_now = get_timestamp(line) - time0
25 text = lines.next()
26 if text.startswith('allocating Loop #'):
27 loops += 1
28 elif text.startswith('allocating Bridge #'):
29 bridges += 1
30 elif text.startswith('freeing Loop #'):
31 match = re.match('freeing Loop # .* with ([0-9]*) attached bridges\n', text)
32 loops -=1
33 bridges -= int(match.group(1))
34 else:
35 assert False, 'unknown line' % line
36 total = loops+bridges
37 yield (time_now, total, loops, bridges)
38
39 def main(logfile, options):
40 print('timestamp,total,loops,bridges')
41 log = open(logfile)
42 for timestamp, total, loops, bridges in count_loops_and_bridges(log):
43 print('%d,%d,%d,%d' % (timestamp, total, loops, bridges))
44
45 if __name__ == '__main__':
46 parser = optparse.OptionParser(usage="%prog loopfile [options]")
47 options, args = parser.parse_args()
48 if len(args) != 1:
49 parser.print_help()
50 sys.exit(2)
51 main(args[0], options)