History

add hg and python

cinap_lenrek committed 15 years ago

Commit 4bb9e221 parent 987265c3706 files · +1228772 −-233Browse files

Showing the changes to sys/src/cmd/python/Tools/scripts/gprof2html.py (1 of 3706 files). Show all

Unified · Split

sys/src/cmd/python/Tools/scripts/gprof2html.py+79−0
@@ -0,0 +1,79 @@
1#! /usr/bin/env python2.3
2
3"""Transform gprof(1) output into useful HTML."""
4
5import re, os, sys, cgi, webbrowser
6
7header = """\
8<html>
9<head>
10 <title>gprof output (%s)</title>
11</head>
12<body>
13<pre>
14"""
15
16trailer = """\
17</pre>
18</body>
19</html>
20"""
21
22def add_escapes(input):
23 for line in input:
24 yield cgi.escape(line)
25
26def main():
27 filename = "gprof.out"
28 if sys.argv[1:]:
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)
34 for line in input:
35 output.write(line)
36 if line.startswith(" time"):
37 break
38 labels = {}
39 for line in input:
40 m = re.match(r"(.* )(\w+)\n", line)
41 if not m:
42 output.write(line)
43 break
44 stuff, fname = m.group(1, 2)
45 labels[fname] = fname
46 output.write('%s<a name="flat:%s" href="#call:%s">%s</a>\n' %
47 (stuff, fname, fname, fname))
48 for line in input:
49 output.write(line)
50 if line.startswith("index % time"):
51 break
52 for line in input:
53 m = re.match(r"(.* )(\w+)(( &lt;cycle.*&gt;)? \[\d+\])\n", line)
54 if not m:
55 output.write(line)
56 if line.startswith("Index by function name"):
57 break
58 continue
59 prefix, fname, suffix = m.group(1, 2, 3)
60 if fname not in labels:
61 output.write(line)
62 continue
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))
66 else:
67 output.write('%s<a href="#call:%s">%s</a>%s\n' %
68 (prefix, fname, fname, suffix))
69 for line in input:
70 for part in re.findall(r"(\w+(?:\.c)?|\W+)", line):
71 if part in labels:
72 part = '<a href="#call:%s">%s</a>' % (part, part)
73 output.write(part)
74 output.write(trailer)
75 output.close()
76 webbrowser.open("file:" + os.path.abspath(outputfilename))
77
78if __name__ == '__main__':
79 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t