gh-138385: Sample all interpreters in the tachyon profiler (#138398)

This commit is contained in:
Pablo Galindo Salgado 2025-09-09 00:41:08 +01:00 committed by GitHub
parent 01895d233b
commit 03ee060ec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 884 additions and 320 deletions

View file

@ -15,43 +15,33 @@ def __init__(self, sample_interval_usec):
lambda: collections.defaultdict(int)
)
def _process_frames(self, frames):
"""Process a single thread's frame stack."""
if not frames:
return
# Process each frame in the stack to track cumulative calls
for frame in frames:
location = (frame.filename, frame.lineno, frame.funcname)
self.result[location]["cumulative_calls"] += 1
# The top frame gets counted as an inline call (directly executing)
top_location = (frames[0].filename, frames[0].lineno, frames[0].funcname)
self.result[top_location]["direct_calls"] += 1
# Track caller-callee relationships for call graph
for i in range(1, len(frames)):
callee_frame = frames[i - 1]
caller_frame = frames[i]
callee = (callee_frame.filename, callee_frame.lineno, callee_frame.funcname)
caller = (caller_frame.filename, caller_frame.lineno, caller_frame.funcname)
self.callers[callee][caller] += 1
def collect(self, stack_frames):
for thread_id, frames in stack_frames:
if not frames:
continue
# Process each frame in the stack to track cumulative calls
for frame in frames:
location = (frame.filename, frame.lineno, frame.funcname)
self.result[location]["cumulative_calls"] += 1
# The top frame gets counted as an inline call (directly executing)
top_frame = frames[0]
top_location = (
top_frame.filename,
top_frame.lineno,
top_frame.funcname,
)
self.result[top_location]["direct_calls"] += 1
# Track caller-callee relationships for call graph
for i in range(1, len(frames)):
callee_frame = frames[i - 1]
caller_frame = frames[i]
callee = (
callee_frame.filename,
callee_frame.lineno,
callee_frame.funcname,
)
caller = (
caller_frame.filename,
caller_frame.lineno,
caller_frame.funcname,
)
self.callers[callee][caller] += 1
for frames in self._iter_all_frames(stack_frames):
self._process_frames(frames)
def export(self, filename):
self.create_stats()