Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 46 lines (33 sloc) 1.071 kB
ac10c55 @nelhage Add a mode to record total time spent in functions.
authored
1 #!/usr/bin/env python
2 import struct
3 import sys
4 import subprocess
5
6 prof_entry = struct.Struct("@LLLL")
7
8 def usage():
9 print >>sys.stdout, "Usage: %s langer.prof prog" % (sys.argv[0],)
10
11 def main(args):
12 if len(args) < 2:
13 usage()
14 sys.exit(1)
15
16 trace_file = args[0]
17 exe = args[1]
18 f = open(trace_file, 'r')
19 spc = ''
20
21 p = subprocess.Popen(['addr2line', '-f', '-e', exe],
22 stdin=subprocess.PIPE,
23 stdout=subprocess.PIPE)
24
25 fns = []
26
27 while True:
28 buf = f.read(prof_entry.size)
29 if len(buf) < prof_entry.size:
30 break
31 (ip, calls, s, us) = prof_entry.unpack(buf)
32
33 p.stdin.write("0x%x\n" % (ip,))
34 fn = p.stdout.readline().strip()
35 line = p.stdout.readline().strip()
36
37 fns.append((fn, line, ip, calls, s + 1e-6*us))
38
39 fns.sort(key=lambda e:e[4], reverse=True)
40
41 for (fn,line,ip,calls,t) in fns:
42 print "[%s] %s (%d calls)" % (fn, t, calls)
43
44 if __name__ == '__main__':
45 sys.exit(main(sys.argv[1:]))
Something went wrong with that request. Please try again.