Skip to content

Commit 0b54df2

Browse files
committed
Don't detect native frames at the top of the stack
1 parent abf1337 commit 0b54df2

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,7 @@ def main_loop():
31283128
operator.call(inner)
31293129
31303130
def inner():
3131-
# A mixture of native and Python code at the top of the stack:
3131+
# Python code at the top of the stack:
31323132
for _ in range(1_000_0000):
31333133
pass
31343134
@@ -3179,11 +3179,8 @@ def test_native_frames_enabled(self):
31793179
# Most samples should have native code in the middle of the stack:
31803180
self.assertTrue(any(";<native>;" in stack for stack in stacks))
31813181

3182-
# Some samples should have native code at the top of the stack:
3183-
self.assertTrue(any(stack.endswith(";<native>") for stack in stacks))
3184-
3185-
# Some samples should have Python code at the top of the stack:
3186-
self.assertTrue(any(not stack.endswith(";<native>") for stack in stacks))
3182+
# No samples should have native code at the top of the stack:
3183+
self.assertFalse(any(stack.endswith(";<native>") for stack in stacks))
31873184

31883185
def test_native_frames_disabled(self):
31893186
"""Test that native frames do not appear when native tracking is disabled."""

Modules/_remote_debugging_module.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,29 +2495,24 @@ process_frame_chain(
24952495
PyErr_SetString(PyExc_RuntimeError, e);
24962496
return -1;
24972497
}
2498-
_Py_DECLARE_STR(native, "<native>");
2499-
_Py_DECLARE_STR(gc, "<GC>");
25002498
PyObject *extra_frame = NULL;
25012499
// This frame kicked off the current GC collection:
25022500
if (unwinder->gc && frame_addr == gc_frame) {
2501+
_Py_DECLARE_STR(gc, "<GC>");
25032502
extra_frame = &_Py_STR(gc);
25042503
}
25052504
// Otherwise, check for native frames to insert:
2506-
else if (unwinder->native) {
2507-
// Topmost frame spilled its stack pointer for a native call:
2508-
if (PyList_GET_SIZE(frame_info) == 0 && stackpointer) {
2509-
extra_frame = &_Py_STR(native);
2510-
}
2511-
// Or, we've reached an interpreter trampoline frame:
2512-
else if (frame == NULL &&
2513-
// Bottommost frame is always native, so skip that one:
2514-
next_frame_addr &&
2515-
// If the next frame will be reported as a GC frame, then
2516-
// don't add an extra native frame below it:
2517-
!(unwinder->gc && next_frame_addr == gc_frame))
2518-
{
2519-
extra_frame = &_Py_STR(native);
2520-
}
2505+
else if (unwinder->native &&
2506+
// We've reached an interpreter trampoline frame:
2507+
frame == NULL &&
2508+
// Bottommost frame is always native, so skip that one:
2509+
next_frame_addr &&
2510+
// If the next frame will be reported as a GC frame, then
2511+
// don't add an extra native frame below it:
2512+
!(unwinder->gc && next_frame_addr == gc_frame))
2513+
{
2514+
_Py_DECLARE_STR(native, "<native>");
2515+
extra_frame = &_Py_STR(native);
25212516
}
25222517
if (extra_frame) {
25232518
// Use "~" as file and 0 as line, since that's what pstats uses:

0 commit comments

Comments
 (0)