FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Tools/scripts/gprof2html.py at pythoncapi · pythoncapi/cpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pythoncapi
/
cpython
Public
forked from
python/cpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Tools
/
scripts
/
gprof2html.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
85 lines (77 loc) · 2.18 KB
Breadcrumbs
cpython
/
Tools
/
scripts
/
gprof2html.py
Copy path
File metadata and controls
executable file
·
85 lines (77 loc) · 2.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /usr/bin/env python3
"""Transform gprof(1) output into useful HTML."""
import
html
import
os
import
re
import
sys
import
webbrowser
header
=
"""
\
<html>
<head>
<title>gprof output (%s)</title>
</head>
<body>
<pre>
"""
trailer
=
"""
\
</pre>
</body>
</html>
"""
def
add_escapes
(
filename
):
with
open
(
filename
)
as
fp
:
for
line
in
fp
:
yield
html
.
escape
(
line
)
def
main
():
filename
=
"gprof.out"
if
sys
.
argv
[
1
:]:
filename
=
sys
.
argv
[
1
]
outputfilename
=
filename
+
".html"
input
=
add_escapes
(
filename
)
output
=
open
(
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+)(( <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<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
))
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL