mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-138709: Implement CPU time profiling in profiling.sample (#138710)
This commit is contained in:
parent
d06113c7a7
commit
67636f72d2
13 changed files with 971 additions and 38 deletions
|
|
@ -11,8 +11,11 @@
|
|||
|
||||
|
||||
class StackTraceCollector(Collector):
|
||||
def collect(self, stack_frames):
|
||||
for frames in self._iter_all_frames(stack_frames):
|
||||
def __init__(self, *, skip_idle=False):
|
||||
self.skip_idle = skip_idle
|
||||
|
||||
def collect(self, stack_frames, skip_idle=False):
|
||||
for frames in self._iter_all_frames(stack_frames, skip_idle=skip_idle):
|
||||
if not frames:
|
||||
continue
|
||||
self.process_frames(frames)
|
||||
|
|
@ -22,7 +25,8 @@ def process_frames(self, frames):
|
|||
|
||||
|
||||
class CollapsedStackCollector(StackTraceCollector):
|
||||
def __init__(self):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.stack_counter = collections.Counter()
|
||||
|
||||
def process_frames(self, frames):
|
||||
|
|
@ -46,7 +50,8 @@ def export(self, filename):
|
|||
|
||||
|
||||
class FlamegraphCollector(StackTraceCollector):
|
||||
def __init__(self):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.stats = {}
|
||||
self._root = {"samples": 0, "children": {}}
|
||||
self._total_samples = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue