summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-09 20:07:34 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-09 20:07:34 (GMT)
commit7ec34b556c08f3cc47afaea16989b117ad9f0d91 (patch)
tree307dab02c57cabeee6b19720f45dc356cb1925cc
parented2f725f7d61c0fd99a2386352058ae045021ffd (diff)
downloadcpython-7ec34b556c08f3cc47afaea16989b117ad9f0d91.zip
cpython-7ec34b556c08f3cc47afaea16989b117ad9f0d91.tar.gz
cpython-7ec34b556c08f3cc47afaea16989b117ad9f0d91.tar.bz2
A tool to transform gprof(1) output into HTML, so you can click on a
function name and go to the corresponding entry.
-rwxr-xr-xTools/scripts/gprof2html.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/Tools/scripts/gprof2html.py b/Tools/scripts/gprof2html.py
new file mode 100755
index 0000000..aa13d52
--- /dev/null
+++ b/Tools/scripts/gprof2html.py
@@ -0,0 +1,78 @@
+#! /usr/bin/env python2.3
+
+"""Transform gprof(1) output into useful HTML."""
+
+import re, os, sys, cgi, webbrowser
+
+header = """\
+<html>
+<head>
+ <title>gprof output (%s)</title>
+</head>
+<body>
+<pre>
+"""
+
+trailer = """\
+</pre>
+</body>
+</html>
+"""
+
+def add_escapes(input):
+ for line in input:
+ yield cgi.escape(line)
+
+def main():
+ filename = "gprof.out"
+ if sys.argv[1:]:
+ filename = sys.argv[1]
+ outputfilename = filename + ".html"
+ input = add_escapes(file(filename))
+ output = file(outputfilename, "w")
+ output.write(header % filename)
+ for line in input:
+ output.write(line)
+ if line.startswith(" time"):
+ break
+ labels = {}
+ for line in input:
+ m = re.match(r"(.* )(\w+)\n", line)
+ if not m:
+ output.write(line)
+ break
+ stuff, fname = m.group(1, 2)
+ labels[fname] = fname
+ output.write('%s<a name="flat:%s" href="#call:%s">%s</a>\n' %
+ (stuff, fname, fname, fname))
+ for line in input:
+ output.write(line)
+ if line.startswith("index % time"):
+ break
+ for line in input:
+ m = re.match(r"(.* )(\w+)(( &lt;cycle.*&gt;)? \[\d+\])\n", line)
+ if not m:
+ output.write(line)
+ if line.startswith("Index by function name"):
+ break
+ continue
+ prefix, fname, suffix = m.group(1, 2, 3)
+ if fname not in labels:
+ output.write(line)
+ continue
+ if line.startswith("["):
+ output.write('%s<a name="call:%s" href="#flat:%s">%s</a>%s\n' %
+ (prefix, fname, fname, fname, suffix))
+ else:
+ output.write('%s<a href="#call:%s">%s</a>%s\n' %
+ (prefix, fname, fname, suffix))
+ for line in input:
+ for part in re.findall(r"(\w+(?:\.c)?|\W+)", line):
+ if part in labels:
+ part = '<a href="#call:%s">%s</a>' % (part, part)
+ output.write(part)
+ output.write(trailer)
+ output.close()
+ webbrowser.open("file:" + os.path.abspath(outputfilename))
+
+main()