diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-02-25 11:36:40 +0100 |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-02-25 11:36:40 +0100 |
commit | fca677a26aff3bce34b1b9b7662dd3a95cd285ba (patch) | |
tree | bb1029606f2410b0ee54231ff506bf3844f5ee11 /Lib/cProfile.py | |
parent | d7c59e101f99cc06f524f48063ce96403c7a6c30 (diff) | |
download | cpython-git-fca677a26aff3bce34b1b9b7662dd3a95cd285ba.tar.gz |
Fix #17197: profile/cProfile modules refactored so that code of run() and runctx() utility functions is not duplicated in both modules.
Diffstat (limited to 'Lib/cProfile.py')
-rwxr-xr-x | Lib/cProfile.py | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py index 81e722b1ec..1184385ae1 100755 --- a/Lib/cProfile.py +++ b/Lib/cProfile.py @@ -7,54 +7,20 @@ __all__ = ["run", "runctx", "Profile"] import _lsprof +import profile as _pyprofile # ____________________________________________________________ # Simple interface def run(statement, filename=None, sort=-1): - """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() - result = None - try: - try: - prof = prof.run(statement) - except SystemExit: - pass - finally: - if filename is not None: - prof.dump_stats(filename) - else: - result = prof.print_stats(sort) - return result + return _pyprofile._Utils(Profile).run(statement, filename, sort) def runctx(statement, globals, locals, filename=None, sort=-1): - """Run statement under profiler, supplying your own globals and locals, - optionally saving results in filename. + return _pyprofile._Utils(Profile).runctx(statement, globals, locals, + filename, sort) - statement and filename have the same semantics as profile.run - """ - prof = Profile() - result = None - try: - try: - prof = prof.runctx(statement, globals, locals) - except SystemExit: - pass - finally: - if filename is not None: - prof.dump_stats(filename) - else: - result = prof.print_stats(sort) - return result +run.__doc__ = _pyprofile.run.__doc__ +runctx.__doc__ = _pyprofile.runctx.__doc__ # ____________________________________________________________ |