mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +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
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue