| class _Utils: | |
| """Support class for utility functions which are shared by | |
| profile.py and cProfile.py modules. | |
| Not supposed to be used directly. | |
| """ | |
| def __init__(self, profiler): | |
| self.profiler = profiler | |
| def run(self, statement, filename, sort): | |
| prof = self.profiler() | |
| try: | |
| prof.run(statement) | |
| except SystemExit: | |
| pass | |
| finally: | |
| self._show(prof, filename, sort) | |
| def runctx(self, statement, globals, locals, filename, sort): | |
| prof = self.profiler() | |
| try: | |
| prof.runctx(statement, globals, locals) | |
| except SystemExit: | |
| pass | |
| finally: | |
| self._show(prof, filename, sort) | |
| def _show(self, prof, filename, sort): | |
| if filename is not None: | |
| prof.dump_stats(filename) | |
| else: | |
| prof.print_stats(sort) |