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

@ -5,7 +5,7 @@
class PstatsCollector(Collector):
def __init__(self, sample_interval_usec):
def __init__(self, sample_interval_usec, *, skip_idle=False):
self.result = collections.defaultdict(
lambda: dict(total_rec_calls=0, direct_calls=0, cumulative_calls=0)
)
@ -14,6 +14,7 @@ def __init__(self, sample_interval_usec):
self.callers = collections.defaultdict(
lambda: collections.defaultdict(int)
)
self.skip_idle = skip_idle
def _process_frames(self, frames):
"""Process a single thread's frame stack."""
@ -40,7 +41,7 @@ def _process_frames(self, frames):
self.callers[callee][caller] += 1
def collect(self, stack_frames):
for frames in self._iter_all_frames(stack_frames):
for frames in self._iter_all_frames(stack_frames, skip_idle=self.skip_idle):
self._process_frames(frames)
def export(self, filename):