1
#! /usr/bin/env python2.3
3
"""Transform gprof(1) output into useful HTML."""
5
import re, os, sys, cgi, webbrowser
10
<title>gprof output (%s)</title>
22
def add_escapes(input):
24
yield cgi.escape(line)
27
filename = "gprof.out"
29
filename = sys.argv[1]
30
outputfilename = filename + ".html"
31
input = add_escapes(file(filename))
32
output = file(outputfilename, "w")
33
output.write(header % filename)
36
if line.startswith(" time"):
40
m = re.match(r"(.* )(\w+)\n", line)
44
stuff, fname = m.group(1, 2)
46
output.write('%s<a name="flat:%s" href="#call:%s">%s</a>\n' %
47
(stuff, fname, fname, fname))
50
if line.startswith("index % time"):
53
m = re.match(r"(.* )(\w+)(( <cycle.*>)? \[\d+\])\n", line)
56
if line.startswith("Index by function name"):
59
prefix, fname, suffix = m.group(1, 2, 3)
60
if fname not in labels:
63
if line.startswith("["):
64
output.write('%s<a name="call:%s" href="#flat:%s">%s</a>%s\n' %
65
(prefix, fname, fname, fname, suffix))
67
output.write('%s<a href="#call:%s">%s</a>%s\n' %
68
(prefix, fname, fname, suffix))
70
for part in re.findall(r"(\w+(?:\.c)?|\W+)", line):
72
part = '<a href="#call:%s">%s</a>' % (part, part)
76
webbrowser.open("file:" + os.path.abspath(outputfilename))
78
if __name__ == '__main__':