@@ -109,7 +109,7 @@ def sample(self, collector, duration_sec=None, *, async_aware=False):
109109 last_sample_time = start_time
110110 realtime_update_interval = 1.0 # Update every second
111111 last_realtime_update = start_time
112- aggregating = getattr (collector , 'aggregating' , False )
112+ aggregating = getattr (collector , 'aggregating' , False ) is True
113113 prev_stack = None
114114 pending_count = 0
115115 pending_timestamps = [] if aggregating else None
@@ -118,15 +118,10 @@ def flush_pending():
118118 nonlocal pending_count , pending_timestamps
119119 if pending_count == 0 :
120120 return
121- count = pending_count
122121 pending_count = 0
123- if aggregating :
124- ts = pending_timestamps
125- pending_timestamps = []
126- collector .collect (prev_stack , timestamps_us = ts )
127- else :
128- for _ in range (count ):
129- collector .collect (prev_stack )
122+ ts = pending_timestamps
123+ pending_timestamps = []
124+ collector .collect (prev_stack , timestamps_us = ts )
130125
131126 try :
132127 while duration_sec is None or running_time_sec < duration_sec :
@@ -145,12 +140,14 @@ def flush_pending():
145140 stack_frames = self ._get_stack_trace (
146141 async_aware = async_aware
147142 )
148- if stack_frames != prev_stack :
149- flush_pending ()
150- prev_stack = stack_frames
151- pending_count += 1
152143 if aggregating :
144+ if stack_frames != prev_stack :
145+ flush_pending ()
146+ prev_stack = stack_frames
147+ pending_count += 1
153148 pending_timestamps .append (current_time_us )
149+ else :
150+ collector .collect (stack_frames )
154151 except ProcessLookupError as e :
155152 running_time_sec = current_time - start_time
156153 break
0 commit comments