diff --git a/Lib/cProfile.py b/Lib/cProfile.py --- a/Lib/cProfile.py +++ b/Lib/cProfile.py @@ -7,54 +7,7 @@ __all__ = ["run", "runctx", "Profile"] import _lsprof - -# ____________________________________________________________ -# 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 - -def runctx(statement, globals, locals, filename=None, sort=-1): - """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() - 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 +import profile as _pyprofile # ____________________________________________________________ @@ -154,6 +107,15 @@ # ____________________________________________________________ +run = _pyprofile.run +run._profiler = Profile +run.__doc__ = _pyprofile.__doc__ +runctx = _pyprofile.runctx +runctx._profiler = Profile +runctx.__doc__ = _pyprofile.__doc__ + +# ____________________________________________________________ + def main(): import os, sys from optparse import OptionParser diff --git a/Lib/profile.py b/Lib/profile.py --- a/Lib/profile.py +++ b/Lib/profile.py @@ -56,7 +56,7 @@ standard name string (file/line/function-name) that is presented in each line. """ - prof = Profile() + prof = run._profiler() try: prof = prof.run(statement) except SystemExit: @@ -72,7 +72,7 @@ statement and filename have the same semantics as profile.run """ - prof = Profile() + prof = runctx._profiler() try: prof = prof.runctx(statement, globals, locals) except SystemExit: @@ -531,6 +531,9 @@ print("mean stopwatch overhead per profile event =", mean) return mean +run._profiler = Profile +runctx._profiler = Profile + #**************************************************************************** def main():