gh-138709: Implement CPU time profiling in profiling.sample (#138710)

This commit is contained in:
Pablo Galindo Salgado 2025-09-19 19:17:28 +01:00 committed by GitHub
parent d06113c7a7
commit 67636f72d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 971 additions and 38 deletions

View file

@ -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