diff options
author | Nicholas Bastin <nick.bastin@gmail.com> | 2004-03-22 20:12:56 +0000 |
---|---|---|
committer | Nicholas Bastin <nick.bastin@gmail.com> | 2004-03-22 20:12:56 +0000 |
commit | 1eb4bfc6579133c2d7a495141b1f754dfecf0fc6 (patch) | |
tree | ebdd1801beda401932abd45966cc052e461d74fc /Lib/profile.py | |
parent | The fix in ceval.c 2.386 allows iteration-by-iteration line tracing even in (diff) | |
download | cpython-1eb4bfc6579133c2d7a495141b1f754dfecf0fc6.tar.gz cpython-1eb4bfc6579133c2d7a495141b1f754dfecf0fc6.tar.bz2 cpython-1eb4bfc6579133c2d7a495141b1f754dfecf0fc6.zip |
Added global runctx function to profile to fix SF Bug #716587
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-x | Lib/profile.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/profile.py b/Lib/profile.py index 2dc6e8734c4..1a4ff67370b 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: |