mirror of
https://github.com/python/cpython.git
synced 2025-11-07 00:51:49 +00:00
gh-138122: Implement PEP 799 (#138142)
This commit is contained in:
parent
f733e428f8
commit
56eb6b64a0
23 changed files with 497 additions and 386 deletions
32
Lib/profiling/tracing/_utils.py
Normal file
32
Lib/profiling/tracing/_utils.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue