summaryrefslogtreecommitdiffstats
path: root/Lib/profile.py
diff options
context:
space:
mode:
authorNicholas Bastin <nick.bastin@gmail.com>2004-03-22 20:12:56 (GMT)
committerNicholas Bastin <nick.bastin@gmail.com>2004-03-22 20:12:56 (GMT)
commit1eb4bfc6579133c2d7a495141b1f754dfecf0fc6 (patch)
treeebdd1801beda401932abd45966cc052e461d74fc /Lib/profile.py
parent706933821c88508299a292e8bb20bf22a9f6364b (diff)
downloadcpython-1eb4bfc6579133c2d7a495141b1f754dfecf0fc6.zip
cpython-1eb4bfc6579133c2d7a495141b1f754dfecf0fc6.tar.gz
cpython-1eb4bfc6579133c2d7a495141b1f754dfecf0fc6.tar.bz2
Added global runctx function to profile to fix SF Bug #716587
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-xLib/profile.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/profile.py b/Lib/profile.py
index 2dc6e87..1a4ff67 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -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: