summaryrefslogtreecommitdiffstats
path: root/Lib/profile.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-03-14 20:01:19 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-03-14 20:01:19 (GMT)
commitadcf8a05a44a9053cb40d0cbc21b7c9c2559cf5f (patch)
tree00664f62a7be422ddd61bb16ea37905a98a03c84 /Lib/profile.py
parent538453e1554166053786d35329edd0000d24f10d (diff)
downloadcpython-adcf8a05a44a9053cb40d0cbc21b7c9c2559cf5f.zip
cpython-adcf8a05a44a9053cb40d0cbc21b7c9c2559cf5f.tar.gz
cpython-adcf8a05a44a9053cb40d0cbc21b7c9c2559cf5f.tar.bz2
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?
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-xLib/profile.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/profile.py b/Lib/profile.py
index afc47eb..a32a1c1 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -55,16 +55,24 @@ __all__ = ["run","help","Profile"]
# Note that an instance of Profile() is *not* needed to call them.
#**************************************************************************
-
-# simplified user interface
-def run(statement, *args):
+def run(statement, filename=None):
+ """Run statement under profiler optionally saving results in filename
+
+ This function takes a single argument that can be passed to the
+ "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()
try:
prof = prof.run(statement)
except SystemExit:
pass
- if args:
- prof.dump_stats(args[0])
+ if filename is not None:
+ prof.dump_stats(filename)
else:
return prof.print_stats()