Skip to content
Prev Previous commit
Next Next commit
profiling(gecko): take last thread as main thread instead of first one
The ordering is actually newest -> oldest, since the _remote_debugging
code traverses the ThreadState linked list in the intepreter state, appending
to a list of threads in-order.

Signed-off-by: Sofia Donato Ferreira <flowlnlnln@gmail.com>
  • Loading branch information
flowln committed Mar 17, 2026
commit 8920f2f062bf3c93090c5ed2d1fab079baa6645f
8 changes: 3 additions & 5 deletions Lib/profiling/sampling/gecko_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,16 @@ def collect(self, stack_frames, timestamps_us=None):
self.last_sample_time = times[-1]

# Process threads
main_tid = None
for interpreter_info in stack_frames:
# Since 'threads' is in order from newest to oldest,
# we know the first thread must be the main thread.
main_tid = interpreter_info.threads[-1].thread_id
for thread_info in interpreter_info.threads:
frames = filter_internal_frames(thread_info.frame_info)
tid = thread_info.thread_id

# Initialize thread if needed
if tid not in self.threads:
# Since 'threads' is in order from oldest to newest,
# we know the first thread must be the main thread.
if len(self.threads) == 0:
main_tid = tid
self.threads[tid] = self._create_thread(tid, main_tid)

thread_data = self.threads[tid]
Expand Down
Loading