diff -r 886f48754f7e Lib/profile.py --- a/Lib/profile.py Thu Jan 31 16:11:28 2013 +0200 +++ b/Lib/profile.py Sat Feb 23 17:35:37 2013 +0100 @@ -83,6 +83,24 @@ else: return prof.print_stats(sort) +def runcall(func, *args, **kwargs): + """ Run function under profiler with arguments and keywords. + + Keyword arguments filename_ and sort_ work as in run.""" + prof = Profile() + try: + excludes = ['filename_', 'sort_'] + filtered_kwargs = { k: v for k,v in kwargs.items() if k not in excludes } + return prof.runcall(func, *args, **filtered_kwargs) + except SystemExit: + pass + finally: + if 'filename_' in kwargs: + prof.dump_stats(kwargs['filename_']) + else: + sort = kwargs['sort_'] if 'sort_' in kwargs else -1 + prof.print_stats(sort) + class Profile: """Profiler class.