Skip to content

Commit 6e2c7ae

Browse files
committed
do not squish the memory
1 parent 2d26718 commit 6e2c7ae

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/profiling/sampling/sample.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def _pause_threads(unwinder, blocking):
4747
# If fewer samples are collected, we skip the TUI and just print a message
4848
MIN_SAMPLES_FOR_TUI = 200
4949

50+
# Maximum number of consecutive identical samples to keep before flushing.
51+
MAX_PENDING_SAMPLES = 8192
52+
5053
class SampleProfiler:
5154
def __init__(self, pid, sample_interval_usec, all_threads, *, mode=PROFILING_MODE_WALL, native=False, gc=True, opcodes=False, skip_non_matching_threads=True, collect_stats=False, blocking=False):
5255
self.pid = pid
@@ -146,6 +149,8 @@ def flush_pending():
146149
prev_stack = stack_frames
147150
pending_count += 1
148151
pending_timestamps.append(current_time_us)
152+
if pending_count >= MAX_PENDING_SAMPLES:
153+
flush_pending()
149154
else:
150155
collector.collect(stack_frames)
151156
except ProcessLookupError as e:

0 commit comments

Comments
 (0)