]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-149521: Do not update `last_profiled_frame` if it's not changed (GH-149522...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 4 Jun 2026 08:31:47 +0000 (10:31 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Jun 2026 08:31:47 +0000 (11:31 +0300)
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Modules/_remote_debugging/threads.c

index 5176c4cf0671bb18ffa589bad87b1fb099589c4e..81735e85395ac9e18c6627105303bc7e0d580c11 100644 (file)
@@ -534,12 +534,14 @@ unwind_stack_for_thread(
             set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to collect frames");
             goto error;
         }
-        // Update last_profiled_frame for next sample
-        uintptr_t lpf_addr =
-            *current_tstate + (uintptr_t)unwinder->debug_offsets.thread_state.last_profiled_frame;
-        if (_Py_RemoteDebug_WriteRemoteMemory(&unwinder->handle, lpf_addr,
-                                              sizeof(uintptr_t), &frame_addr) < 0) {
-            PyErr_Clear();  // Non-fatal
+        // Update last_profiled_frame for next sample if it changed
+        if (frame_addr != ctx.last_profiled_frame) {
+            uintptr_t lpf_addr =
+                *current_tstate + (uintptr_t)unwinder->debug_offsets.thread_state.last_profiled_frame;
+            if (_Py_RemoteDebug_WriteRemoteMemory(&unwinder->handle, lpf_addr,
+                                                  sizeof(uintptr_t), &frame_addr) < 0) {
+                PyErr_Clear();  // Non-fatal
+            }
         }
     } else {
         // No caching - process entire frame chain with base_frame validation