Skip to content

Commit 1a07c4a

Browse files
committed
one less syskall
1 parent f5c7535 commit 1a07c4a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Modules/_remote_debugging/threads.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,14 @@ unwind_stack_for_thread(
450450
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to collect frames");
451451
goto error;
452452
}
453-
// Update last_profiled_frame for next sample
454-
uintptr_t lpf_addr =
455-
*current_tstate + (uintptr_t)unwinder->debug_offsets.thread_state.last_profiled_frame;
456-
if (_Py_RemoteDebug_WriteRemoteMemory(&unwinder->handle, lpf_addr,
457-
sizeof(uintptr_t), &frame_addr) < 0) {
458-
PyErr_Clear(); // Non-fatal
453+
// Update last_profiled_frame for next sample if it changed
454+
if (frame_addr != ctx.last_profiled_frame) {
455+
uintptr_t lpf_addr =
456+
*current_tstate + (uintptr_t)unwinder->debug_offsets.thread_state.last_profiled_frame;
457+
if (_Py_RemoteDebug_WriteRemoteMemory(&unwinder->handle, lpf_addr,
458+
sizeof(uintptr_t), &frame_addr) < 0) {
459+
PyErr_Clear(); // Non-fatal
460+
}
459461
}
460462
} else {
461463
// No caching - process entire frame chain with base_frame validation

0 commit comments

Comments
 (0)