mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Add doc string for run from profile.doc. (pydoc motivates me to write
good doc strings.) Fix silly argument handling; was using *args but really wanted 1 optional arg. XXX Should profile.doc be merged into the documentation and removed from the Lib directory?
This commit is contained in:
parent
538453e155
commit
adcf8a05a4
1 changed files with 12 additions and 4 deletions
|
@ -55,16 +55,24 @@ __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):
|
||||||
|
"""Run statement under profiler optionally saving results in filename
|
||||||
|
|
||||||
# simplified user interface
|
This function takes a single argument that can be passed to the
|
||||||
def run(statement, *args):
|
"exec" statement, and an optional file name. In all cases this
|
||||||
|
routine attempts to "exec" its first argument and gather profiling
|
||||||
|
statistics from the execution. If no file name is present, then this
|
||||||
|
function automatically prints a simple profiling report, sorted by the
|
||||||
|
standard name string (file/line/function-name) that is presented in
|
||||||
|
each line.
|
||||||
|
"""
|
||||||
prof = Profile()
|
prof = Profile()
|
||||||
try:
|
try:
|
||||||
prof = prof.run(statement)
|
prof = prof.run(statement)
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
if args:
|
if filename is not None:
|
||||||
prof.dump_stats(args[0])
|
prof.dump_stats(filename)
|
||||||
else:
|
else:
|
||||||
return prof.print_stats()
|
return prof.print_stats()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue