Support class for utility functions which are shared by profile.py and cProfile.py modules. Not supposed to be used directly.
| 1 | class _Utils: |
| 2 | """Support class for utility functions which are shared by |
| 3 | profile.py and cProfile.py modules. |
| 4 | Not supposed to be used directly. |
| 5 | """ |
| 6 | |
| 7 | def __init__(self, profiler): |
| 8 | self.profiler = profiler |
| 9 | |
| 10 | def run(self, statement, filename, sort): |
| 11 | prof = self.profiler() |
| 12 | try: |
| 13 | prof.run(statement) |
| 14 | except SystemExit: |
| 15 | pass |
| 16 | finally: |
| 17 | self._show(prof, filename, sort) |
| 18 | |
| 19 | def runctx(self, statement, globals, locals, filename, sort): |
| 20 | prof = self.profiler() |
| 21 | try: |
| 22 | prof.runctx(statement, globals, locals) |
| 23 | except SystemExit: |
| 24 | pass |
| 25 | finally: |
| 26 | self._show(prof, filename, sort) |
| 27 | |
| 28 | def _show(self, prof, filename, sort): |
| 29 | if filename is not None: |
| 30 | prof.dump_stats(filename) |
| 31 | else: |
| 32 | prof.print_stats(sort) |