Skip to content

Commit 24b63e1

Browse files
committed
Enable frame caching by default in the sampling profiler
Turn on cache_frames=True in the sampling profiler and the external inspection benchmark. This significantly reduces the cost of sampling deep stacks since unchanged parent frames don't need to be re-read from the target process.
1 parent 04db7b0 commit 24b63e1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Lib/profiling/sampling/sample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ def __init__(self, pid, sample_interval_usec, all_threads, *, mode=PROFILING_MOD
3535
if _FREE_THREADED_BUILD:
3636
self.unwinder = _remote_debugging.RemoteUnwinder(
3737
self.pid, all_threads=self.all_threads, mode=mode, native=native, gc=gc,
38-
skip_non_matching_threads=skip_non_matching_threads
38+
skip_non_matching_threads=skip_non_matching_threads, cache_frames=True
3939
)
4040
else:
4141
only_active_threads = bool(self.all_threads)
4242
self.unwinder = _remote_debugging.RemoteUnwinder(
4343
self.pid, only_active_thread=only_active_threads, mode=mode, native=native, gc=gc,
44-
skip_non_matching_threads=skip_non_matching_threads
44+
skip_non_matching_threads=skip_non_matching_threads, cache_frames=True
4545
)
4646
# Track sample intervals and total sample count
4747
self.sample_intervals = deque(maxlen=100)

Tools/inspection/benchmark_external_inspection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def main():
434434
elif args.threads == "only_active":
435435
kwargs["only_active_thread"] = True
436436
unwinder = _remote_debugging.RemoteUnwinder(
437-
process.pid, **kwargs
437+
process.pid, cache_frames=True, **kwargs
438438
)
439439
results = benchmark(unwinder, duration_seconds=args.duration)
440440
finally:

0 commit comments

Comments
 (0)