diff --git a/Lib/profiling/sampling/collector.py b/Lib/profiling/sampling/collector.py index 7dc095c6c279bd..20748849425262 100644 --- a/Lib/profiling/sampling/collector.py +++ b/Lib/profiling/sampling/collector.py @@ -182,8 +182,7 @@ def _build_linear_stacks(self, leaf_task_ids, task_map, child_to_parent): # Add all frames from all coroutines in this task if task_info.coroutine_stack: for coro_info in task_info.coroutine_stack: - for frame in coro_info.call_stack: - frames.append(frame) + frames.extend(coro_info.call_stack) # Get pre-computed parent info (no sorting needed!) parent_info = child_to_parent.get(current_id) diff --git a/Lib/profiling/sampling/sample.py b/Lib/profiling/sampling/sample.py index c6abfb1c8ee885..8df9dd8aca5bdb 100644 --- a/Lib/profiling/sampling/sample.py +++ b/Lib/profiling/sampling/sample.py @@ -104,7 +104,7 @@ def sample(self, collector, duration_sec=None, *, async_aware=False): sleep_time = (next_time - current_time) * 0.9 if sleep_time > 0.0001: time.sleep(sleep_time) - elif next_time < current_time: + else: try: with _pause_threads(self.unwinder, self.blocking): if async_aware == "all": @@ -126,7 +126,7 @@ def sample(self, collector, duration_sec=None, *, async_aware=False): raise e from None # Track actual sampling intervals for real-time stats - if num_samples > 0: + if self.realtime_stats and num_samples > 0: actual_interval = current_time - last_sample_time self.sample_intervals.append( 1.0 / actual_interval @@ -146,7 +146,7 @@ def sample(self, collector, duration_sec=None, *, async_aware=False): num_samples += 1 next_time += sample_interval_sec - running_time_sec = time.perf_counter() - start_time + running_time_sec = current_time - start_time except KeyboardInterrupt: interrupted = True running_time_sec = time.perf_counter() - start_time