From 458120dd40db6b4df55a4e96b650e16798ef06a0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 3 May 2011 11:25:13 +0000 Subject: add hg and python --- sys/src/cmd/python/Tools/scripts/gprof2html.py | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 sys/src/cmd/python/Tools/scripts/gprof2html.py (limited to 'sys/src/cmd/python/Tools/scripts/gprof2html.py') diff --git a/sys/src/cmd/python/Tools/scripts/gprof2html.py b/sys/src/cmd/python/Tools/scripts/gprof2html.py new file mode 100755 index 000000000..cb01c2ce6 --- /dev/null +++ b/sys/src/cmd/python/Tools/scripts/gprof2html.py @@ -0,0 +1,79 @@ +#! /usr/bin/env python2.3 + +"""Transform gprof(1) output into useful HTML.""" + +import re, os, sys, cgi, webbrowser + +header = """\ + + + gprof output (%s) + + +
+"""
+
+trailer = """\
+
+ + +""" + +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%s\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+)(( <cycle.*>)? \[\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%s%s\n' % + (prefix, fname, fname, fname, suffix)) + else: + output.write('%s%s%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 = '%s' % (part, part) + output.write(part) + output.write(trailer) + output.close() + webbrowser.open("file:" + os.path.abspath(outputfilename)) + +if __name__ == '__main__': + main() -- cgit v1.2.3