Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1eb4bfc6
Commit
1eb4bfc6
authored
Mar 22, 2004
by
Nicholas Bastin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added global runctx function to profile to fix SF Bug #716587
parent
70693382
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
7 deletions
+46
-7
Doc/lib/libprofile.tex
Doc/lib/libprofile.tex
+7
-1
Lib/profile.py
Lib/profile.py
+17
-0
Lib/test/output/test_profile
Lib/test/output/test_profile
+6
-6
Lib/test/test_profile.py
Lib/test/test_profile.py
+14
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/lib/libprofile.tex
View file @
1eb4bfc6
...
...
@@ -275,7 +275,7 @@ Profiler Extensions, which includes discussion of how to derive
``better'' profilers from the classes presented, or reading the source
code for these modules.
\begin{funcdesc}
{
run
}{
string
\optional
{
, filename
\optional
{
, ...
}
}}
\begin{funcdesc}
{
run
}{
command
\optional
{
, filename
}}
This function takes a single argument that has can be passed to the
\keyword
{
exec
}
statement, and an optional file name. In all cases this
...
...
@@ -339,6 +339,12 @@ figure is printed.
\end{funcdesc}
\begin{funcdesc}
{
runctx
}{
command, globals, locals
\optional
{
, filename
}}
This function is similar to
\function
{
profile.run()
}
, with added
arguments to supply the globals and locals dictionaries for the
\var
{
command
}
string.
\end{funcdesc}
Analysis of the profiler data is done using this class from the
\module
{
pstats
}
module:
...
...
Lib/profile.py
View file @
1eb4bfc6
...
...
@@ -76,6 +76,23 @@ def run(statement, filename=None):
else
:
return
prof
.
print_stats
()
def
runctx
(
statement
,
globals
,
locals
,
filename
=
None
):
"""Run statement under profiler, supplying your own globals and locals,
optionally saving results in filename.
statement and filename have the same semantics as profile.run
"""
prof
=
Profile
()
try
:
prof
=
prof
.
runctx
(
statement
,
globals
,
locals
)
except
SystemExit
:
pass
if
filename
is
not
None
:
prof
.
dump_stats
(
filename
)
else
:
return
prof
.
print_stats
()
# print help
def
help
():
for
dirname
in
sys
.
path
:
...
...
Lib/test/output/test_profile
View file @
1eb4bfc6
...
...
@@ -7,11 +7,11 @@ test_profile
1 0.000 0.000 1.000 1.000 <string>:1(?)
0 0.000 0.000 profile:0(profiler)
1 0.000 0.000 1.000 1.000 profile:0(testfunc())
1 0.400 0.400 1.000 1.000 test_profile.py:2
1
(testfunc)
2 0.080 0.040 0.600 0.300 test_profile.py:3
0
(helper)
4 0.116 0.029 0.120 0.030 test_profile.py:
48
(helper1)
8 0.312 0.039 0.400 0.050 test_profile.py:5
6
(helper2)
8 0.064 0.008 0.080 0.010 test_profile.py:6
6
(subhelper)
28 0.028 0.001 0.028 0.001 test_profile.py:
78
(__getattr__)
1 0.400 0.400 1.000 1.000 test_profile.py:2
3
(testfunc)
2 0.080 0.040 0.600 0.300 test_profile.py:3
2
(helper)
4 0.116 0.029 0.120 0.030 test_profile.py:
50
(helper1)
8 0.312 0.039 0.400 0.050 test_profile.py:5
8
(helper2)
8 0.064 0.008 0.080 0.010 test_profile.py:6
8
(subhelper)
28 0.028 0.001 0.028 0.001 test_profile.py:
80
(__getattr__)
Lib/test/test_profile.py
View file @
1eb4bfc6
"""Test suite for the profile module."""
import
profile
import
os
from
test.test_support
import
TESTFN
,
vereq
# In order to have reproducible time, we simulate a timer in the global
# variable 'ticks', which represents simulated time in milliseconds.
...
...
@@ -82,5 +84,17 @@ class C:
ticks
+=
1
raise
AttributeError
def
test_2
():
d
=
globals
().
copy
()
def
testfunc
():
global
x
x
=
1
d
[
'testfunc'
]
=
testfunc
profile
.
runctx
(
"testfunc()"
,
d
,
d
,
TESTFN
)
vereq
(
x
,
1
)
os
.
unlink
(
TESTFN
)
if
__name__
==
"__main__"
:
test_main
()
test_2
()
Misc/NEWS
View file @
1eb4bfc6
...
...
@@ -290,6 +290,8 @@ Extension modules
Library
-------
- Added global runctx function to profile module
- Add hlist missing entryconfigure and entrycget methods.
- The ptcp154 codec was added for Kazakh character set support.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment