@@ -245,10 +245,9 @@ def collect(self, stack_frames, timestamps_us=None):
245245
246246 first_time = times [0 ]
247247
248- # Update interval calculation
249- if self .sample_count > 0 and self .last_sample_time > 0 :
250- self .interval = (times [- 1 ] - self .last_sample_time ) / self .sample_count
251- self .last_sample_time = times [- 1 ]
248+ # Binary replay can deliver batches from different threads out of
249+ # order, so keep the latest time seen rather than the last one.
250+ self .last_sample_time = max (self .last_sample_time , times [- 1 ])
252251
253252 # Process async tasks
254253 if stack_frames and hasattr (stack_frames [0 ], "awaited_by" ):
@@ -727,9 +726,6 @@ def _finalize_markers(self):
727726
728727 def export (self , filename ):
729728 """Export the profile to a Gecko JSON file."""
730- if self .sample_count > 0 and self .last_sample_time > 0 :
731- self .interval = self .last_sample_time / self .sample_count
732-
733729 # Spinner for progress indication
734730 spinner = itertools .cycle (['⠋' , '⠙' , '⠹' , '⠸' , '⠼' , '⠴' , '⠦' , '⠧' , '⠇' , '⠏' ])
735731 stop_spinner = threading .Event ()
@@ -859,6 +855,8 @@ def _profile_tail(self):
859855 def _prepare_for_serialization (self ):
860856 if self .exported :
861857 raise RuntimeError ("GeckoCollector has already been exported" )
858+ if self .sample_count > 0 and self .last_sample_time > 0 :
859+ self .interval = self .last_sample_time / self .sample_count
862860 self ._finalize_markers ()
863861 for thread_data in self .threads .values ():
864862 thread_data ["_spill" ].prepare_read ()
0 commit comments