Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 46 lines (33 sloc) 1.05 KB
#!/usr/bin/env python
import struct
import sys
import subprocess
prof_entry = struct.Struct("@LLLL")
def usage():
print >>sys.stdout, "Usage: %s langer.prof prog" % (sys.argv[0],)
def main(args):
if len(args) < 2:
usage()
sys.exit(1)
trace_file = args[0]
exe = args[1]
f = open(trace_file, 'r')
spc = ''
p = subprocess.Popen(['addr2line', '-f', '-e', exe],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
fns = []
while True:
buf = f.read(prof_entry.size)
if len(buf) < prof_entry.size:
break
(ip, calls, s, us) = prof_entry.unpack(buf)
p.stdin.write("0x%x\n" % (ip,))
fn = p.stdout.readline().strip()
line = p.stdout.readline().strip()
fns.append((fn, line, ip, calls, s + 1e-6*us))
fns.sort(key=lambda e:e[4], reverse=True)
for (fn,line,ip,calls,t) in fns:
print "[%s] %s (%d calls)" % (fn, t, calls)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))