Support class for utility functions which are shared by profile.py and cProfile.py modules. Not supposed to be used directly.
| 49 | #itimes = integer_timer # replace with C coded timer returning integers |
| 50 | |
| 51 | class _Utils: |
| 52 | """Support class for utility functions which are shared by |
| 53 | profile.py and cProfile.py modules. |
| 54 | Not supposed to be used directly. |
| 55 | """ |
| 56 | |
| 57 | def __init__(self, profiler): |
| 58 | self.profiler = profiler |
| 59 | |
| 60 | def run(self, statement, filename, sort): |
| 61 | prof = self.profiler() |
| 62 | try: |
| 63 | prof.run(statement) |
| 64 | except SystemExit: |
| 65 | pass |
| 66 | finally: |
| 67 | self._show(prof, filename, sort) |
| 68 | |
| 69 | def runctx(self, statement, globals, locals, filename, sort): |
| 70 | prof = self.profiler() |
| 71 | try: |
| 72 | prof.runctx(statement, globals, locals) |
| 73 | except SystemExit: |
| 74 | pass |
| 75 | finally: |
| 76 | self._show(prof, filename, sort) |
| 77 | |
| 78 | def _show(self, prof, filename, sort): |
| 79 | if filename is not None: |
| 80 | prof.dump_stats(filename) |
| 81 | else: |
| 82 | prof.print_stats(sort) |
| 83 | |
| 84 | |
| 85 | #************************************************************************** |