@@ -35,26 +35,29 @@ def __init__(self, pid, sample_interval_usec, all_threads, *, mode=PROFILING_MOD
3535 self .mode = mode # Store mode for later use
3636 self .collect_stats = collect_stats
3737 try :
38- if _FREE_THREADED_BUILD :
39- self .unwinder = _remote_debugging .RemoteUnwinder (
40- self .pid , all_threads = self .all_threads , mode = mode , native = native , gc = gc ,
41- opcodes = opcodes , skip_non_matching_threads = skip_non_matching_threads ,
42- cache_frames = True , stats = collect_stats
43- )
44- else :
45- only_active_threads = bool (self .all_threads )
46- self .unwinder = _remote_debugging .RemoteUnwinder (
47- self .pid , only_active_thread = only_active_threads , mode = mode , native = native , gc = gc ,
48- opcodes = opcodes , skip_non_matching_threads = skip_non_matching_threads ,
49- cache_frames = True , stats = collect_stats
50- )
38+ self .unwinder = self ._new_unwinder (native , gc , opcodes , skip_non_matching_threads )
5139 except RuntimeError as err :
5240 raise SystemExit (err )
5341 # Track sample intervals and total sample count
5442 self .sample_intervals = deque (maxlen = 100 )
5543 self .total_samples = 0
5644 self .realtime_stats = False
5745
46+ def _new_unwinder (self , native , gc , opcodes , skip_non_matching_threads ):
47+ if _FREE_THREADED_BUILD :
48+ unwinder = _remote_debugging .RemoteUnwinder (
49+ self .pid , all_threads = self .all_threads , mode = self .mode , native = native , gc = gc ,
50+ opcodes = opcodes , skip_non_matching_threads = skip_non_matching_threads ,
51+ cache_frames = True , stats = self .collect_stats
52+ )
53+ else :
54+ unwinder = _remote_debugging .RemoteUnwinder (
55+ self .pid , only_active_thread = bool (self .all_threads ), mode = self .mode , native = native , gc = gc ,
56+ opcodes = opcodes , skip_non_matching_threads = skip_non_matching_threads ,
57+ cache_frames = True , stats = self .collect_stats
58+ )
59+ return unwinder
60+
5861 def sample (self , collector , duration_sec = 10 , * , async_aware = False ):
5962 sample_interval_sec = self .sample_interval_usec / 1_000_000
6063 running_time = 0
0 commit comments