Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
vmprof-python/vmprof/show.py at remove-click · vmprof/vmprof-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
vmprof
/
vmprof-python
Public
Notifications
You must be signed in to change notification settings
Fork
55
Star
439
Code
Issues
53
Pull requests
6
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
remove-click
Breadcrumbs
vmprof-python
/
vmprof
/
show.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
152 lines (116 loc) · 4.83 KB
remove-click
Breadcrumbs
vmprof-python
/
vmprof
/
show.py
Copy path
Top
File metadata and controls
Code
Blame
152 lines (116 loc) · 4.83 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from
__future__
import
absolute_import
import
os
import
six
import
vmprof
import
argparse
class
color
(
six
.
text_type
):
RED
=
'
\033
[31m'
WHITE
=
'
\033
[37m'
BLUE
=
'
\033
[94m'
BOLD
=
'
\033
[1m'
END
=
'
\033
[0m'
def
__new__
(
cls
,
content
,
color
,
bold
=
False
):
return
six
.
text_type
.
__new__
(
cls
,
"%s%s%s%s"
%
(
color
,
cls
.
BOLD
if
bold
else
""
,
content
,
cls
.
END
))
class
PrettyPrinter
(
object
):
"""
A pretty print for vmprof profile files.
"""
def
__init__
(
self
,
prune_percent
=
None
,
prune_level
=
None
,
indent
=
None
):
"""
:param prune_percent: Prune output of a profile stats node when CPU consumed
is less than this value for the node and everything below.
:type prune_percent: None or float
:param prune_level: Prune output of a profile stats node when the node is deeper
than this level down the call graph from the very top.
:type prune_level: None or int
:param indent: The indention per level within the call graph.
:type indent: None or int
"""
assert
(
prune_percent
is
None
or
(
prune_percent
>=
0
and
prune_percent
<=
100
))
assert
(
prune_level
is
None
or
(
prune_level
>=
0
and
prune_level
<=
1000
))
assert
(
indent
is
None
or
(
indent
>=
0
and
indent
<=
4
))
self
.
_prune_percent
=
prune_percent
or
0.
self
.
_prune_level
=
prune_level
or
1000
self
.
_indent
=
indent
or
2
def
show
(
self
,
profile
):
"""
Read and display a vmprof profile file.
:param profile: The filename of the vmprof profile file to display.
:type profile: str
"""
try
:
stats
=
vmprof
.
read_profile
(
profile
)
except
Exception
as
e
:
print
(
"Fatal: could not read vmprof profile file '{}': {}"
.
format
(
profile
,
e
))
return
#vmprof.cli.show(stats)
tree
=
stats
.
get_tree
()
self
.
_print_tree
(
tree
)
def
_walk_tree
(
self
,
parent
,
node
,
level
,
callback
):
callback
(
parent
,
node
,
level
)
level
+=
1
if
level
>
self
.
_prune_level
:
return
for
c
in
six
.
itervalues
(
node
.
children
):
self
.
_walk_tree
(
node
,
c
,
level
,
callback
)
def
_print_tree
(
self
,
tree
):
total
=
float
(
tree
.
count
)
def
print_node
(
parent
,
node
,
level
):
parent_name
=
parent
.
name
if
parent
else
None
perc
=
round
(
100.
*
float
(
node
.
count
)
/
total
,
1
)
if
parent
and
parent
.
count
:
perc_of_parent
=
round
(
100.
*
float
(
node
.
count
)
/
float
(
parent
.
count
),
1
)
else
:
perc_of_parent
=
100.
if
perc
>=
self
.
_prune_percent
:
parts
=
node
.
name
.
count
(
':'
)
if
parts
==
3
:
block_type
,
funname
,
funline
,
filename
=
node
.
name
.
split
(
':'
)
p2
=
color
(
funname
,
color
.
BLUE
,
bold
=
True
)
p2b
=
color
((
'.'
*
level
*
self
.
_indent
),
color
.
BLUE
)
p3
=
[]
if
os
.
path
.
dirname
(
filename
):
p3
.
append
(
color
(
os
.
path
.
dirname
(
filename
)
+
'/'
,
color
.
WHITE
))
p3
.
append
(
color
(
os
.
path
.
basename
(
filename
),
color
.
WHITE
,
bold
=
True
)
+
":"
)
p3
.
append
(
color
(
"{}"
.
format
(
funline
),
color
.
WHITE
))
p3
=
''
.
join
(
p3
)
p5
=
color
(
"{:>2}"
.
format
(
level
),
color
.
BLUE
)
elif
parts
==
1
:
block_type
,
funname
=
node
.
name
.
split
(
':'
)
p2
=
color
(
"JIT code"
,
color
.
RED
,
bold
=
True
)
p2b
=
color
(
'.'
*
level
*
self
.
_indent
,
color
.
RED
,
bold
=
False
)
p3
=
color
(
funname
,
color
.
WHITE
,
bold
=
False
)
p5
=
color
(
"{:>2}"
.
format
(
level
),
color
.
RED
,
bold
=
False
)
else
:
raise
Exception
(
"fail!"
)
p1
=
color
(
"{:>5}%"
.
format
(
perc
),
color
.
WHITE
,
bold
=
True
)
p4
=
color
(
"{}%"
.
format
(
perc_of_parent
),
color
.
WHITE
,
bold
=
True
)
print
(
"{} {} {} {} {}"
.
format
(
p1
,
p2b
,
p2
,
p4
,
p3
))
self
.
_walk_tree
(
None
,
tree
,
0
,
print_node
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"profile"
)
parser
.
add_argument
(
'--prune_percent'
,
type
=
float
,
default
=
0
,
help
=
"The indention per level within the call graph."
)
parser
.
add_argument
(
'--prune_level'
,
type
=
int
,
default
=
None
,
help
=
'Prune output of a profile stats node when CPU.'
)
parser
.
add_argument
(
'--indent'
,
type
=
int
,
default
=
2
,
help
=
'The indention per level within the call graph.'
)
args
=
parser
.
parse_args
()
pp
=
PrettyPrinter
(
prune_percent
=
args
.
prune_percent
,
prune_level
=
args
.
prune_level
,
indent
=
args
.
indent
)
pp
.
show
(
args
.
profile
)
if
__name__
==
'__main__'
:
main
()
You can’t perform that action at this time.