Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
824b1b2d
Kaydet (Commit)
824b1b2d
authored
Mar 23, 2004
tarafından
Nicholas Bastin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added command line options for profile.py - one for stats output file
and one for sort order when using stdout. Uses optparse.
üst
6fca7cc7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
13 deletions
+39
-13
libprofile.tex
Doc/lib/libprofile.tex
+9
-0
profile.py
Lib/profile.py
+27
-13
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libprofile.tex
Dosyayı görüntüle @
824b1b2d
...
@@ -131,6 +131,15 @@ a script to profile another script. For example:
...
@@ -131,6 +131,15 @@ a script to profile another script. For example:
python /usr/local/lib/python1.5/profile.py myscript.py
python /usr/local/lib/python1.5/profile.py myscript.py
\end{verbatim}
\end{verbatim}
\file
{
profile.py
}
accepts two optional arguments on the command line:
\begin{verbatim}
profile.py [-o output
_
file] [-s sort
_
order]
\end{verbatim}
\samp
{
-s
}
only applies to stdout (i.e.
\samp
{
-o
}
is not supplied.
Look in the
\class
{
Stats
}
documentation for valid sort values.
When you wish to review the profile, you should use the methods in the
When you wish to review the profile, you should use the methods in the
\module
{
pstats
}
module. Typically you would load the statistics data as
\module
{
pstats
}
module. Typically you would load the statistics data as
follows:
follows:
...
...
Lib/profile.py
Dosyayı görüntüle @
824b1b2d
...
@@ -39,6 +39,7 @@ import sys
...
@@ -39,6 +39,7 @@ import sys
import
os
import
os
import
time
import
time
import
marshal
import
marshal
from
optparse
import
OptionParser
__all__
=
[
"run"
,
"help"
,
"Profile"
]
__all__
=
[
"run"
,
"help"
,
"Profile"
]
...
@@ -55,7 +56,7 @@ __all__ = ["run","help","Profile"]
...
@@ -55,7 +56,7 @@ __all__ = ["run","help","Profile"]
# Note that an instance of Profile() is *not* needed to call them.
# Note that an instance of Profile() is *not* needed to call them.
#**************************************************************************
#**************************************************************************
def
run
(
statement
,
filename
=
None
):
def
run
(
statement
,
filename
=
None
,
sort
=-
1
):
"""Run statement under profiler optionally saving results in filename
"""Run statement under profiler optionally saving results in filename
This function takes a single argument that can be passed to the
This function takes a single argument that can be passed to the
...
@@ -74,7 +75,7 @@ def run(statement, filename=None):
...
@@ -74,7 +75,7 @@ def run(statement, filename=None):
if
filename
is
not
None
:
if
filename
is
not
None
:
prof
.
dump_stats
(
filename
)
prof
.
dump_stats
(
filename
)
else
:
else
:
return
prof
.
print_stats
()
return
prof
.
print_stats
(
sort
)
def
runctx
(
statement
,
globals
,
locals
,
filename
=
None
):
def
runctx
(
statement
,
globals
,
locals
,
filename
=
None
):
"""Run statement under profiler, supplying your own globals and locals,
"""Run statement under profiler, supplying your own globals and locals,
...
@@ -384,9 +385,9 @@ class Profile:
...
@@ -384,9 +385,9 @@ class Profile:
self
.
t
=
get_time
()
-
t
self
.
t
=
get_time
()
-
t
def
print_stats
(
self
):
def
print_stats
(
self
,
sort
=-
1
):
import
pstats
import
pstats
pstats
.
Stats
(
self
)
.
strip_dirs
()
.
sort_stats
(
-
1
)
.
\
pstats
.
Stats
(
self
)
.
strip_dirs
()
.
sort_stats
(
sort
)
.
\
print_stats
()
print_stats
()
def
dump_stats
(
self
,
file
):
def
dump_stats
(
self
,
file
):
...
@@ -556,15 +557,28 @@ def Stats(*args):
...
@@ -556,15 +557,28 @@ def Stats(*args):
# When invoked as main program, invoke the profiler on a script
# When invoked as main program, invoke the profiler on a script
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
usage
=
"profile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
if
not
sys
.
argv
[
1
:]:
if
not
sys
.
argv
[
1
:]:
print
"
usage: profile.py scriptfile [arg] ..."
print
"
Usage: "
,
usage
sys
.
exit
(
2
)
sys
.
exit
(
2
)
filename
=
sys
.
argv
[
1
]
# Get script filename
class
ProfileParser
(
OptionParser
):
def
__init__
(
self
,
usage
):
del
sys
.
argv
[
0
]
# Hide "profile.py" from argument list
OptionParser
.
__init__
(
self
)
self
.
usage
=
usage
# Insert script directory in front of module search path
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
filename
))
parser
=
ProfileParser
(
usage
)
parser
.
allow_interspersed_args
=
False
run
(
'execfile(
%
r)'
%
(
filename
,))
parser
.
add_option
(
'-o'
,
'--outfile'
,
dest
=
"outfile"
,
help
=
"Save stats to <outfile>"
,
default
=
None
)
parser
.
add_option
(
'-s'
,
'--sort'
,
dest
=
"sort"
,
help
=
"Sort order when printing to stdout, based on pstats.Stats class"
,
default
=-
1
)
(
options
,
args
)
=
parser
.
parse_args
()
sys
.
argv
[:]
=
args
if
(
len
(
sys
.
argv
)
>
0
):
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
run
(
'execfile(
%
r)'
%
(
sys
.
argv
[
0
],),
options
.
outfile
,
options
.
sort
)
else
:
print
"Usage: "
,
usage
Misc/NEWS
Dosyayı görüntüle @
824b1b2d
...
@@ -290,6 +290,9 @@ Extension modules
...
@@ -290,6 +290,9 @@ Extension modules
Library
Library
-------
-------
- Added two new command-line arguments for profile (output file and
default sort).
- Added global runctx function to profile module
- Added global runctx function to profile module
- Add hlist missing entryconfigure and entrycget methods.
- Add hlist missing entryconfigure and entrycget methods.
...
...
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