Commit c15dcd3
committed
gh-138122: Add incomplete sample detection and fix generator frame unwinding
This commit adds two related improvements to stack profiling:
1. Skip suspended generator frames during unwinding
Generator frames at yield points have NULL previous pointers and don't
link to callers via normal frame chains. These frames are now correctly
skipped during stack unwinding to prevent broken chains.
2. Detect and reject incomplete samples
Add PyThreadState.entry_frame to track the bottommost frame in each
thread's call stack. The profiler validates that unwinding reaches
this expected bottom frame. Samples that fail to unwind completely
(due to race conditions, memory corruption, or other errors) are now
rejected rather than being included as spurious single-frame stacks.
The entry_frame field is:
- Set when entering the first frame (when previous == NULL)
- Cleared when returning to no frames
- Exposed via debug offsets for remote profiling
- Compared against the last frame address reached during unwinding
This prevents corrupted profiling data from incomplete samples while
maintaining correct handling of suspended generator frames.1 parent 6462322 commit c15dcd3
File tree
6 files changed
+61
-7
lines changed- Include
- cpython
- internal
- Misc/NEWS.d/next/Core_and_Builtins
- Modules
- Python
6 files changed
+61
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
272 | 273 | | |
273 | 274 | | |
274 | 275 | | |
| 276 | + | |
275 | 277 | | |
276 | 278 | | |
277 | 279 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2254 | 2254 | | |
2255 | 2255 | | |
2256 | 2256 | | |
| 2257 | + | |
2257 | 2258 | | |
2258 | | - | |
| 2259 | + | |
2259 | 2260 | | |
2260 | 2261 | | |
2261 | 2262 | | |
2262 | | - | |
2263 | | - | |
2264 | | - | |
2265 | | - | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
2266 | 2273 | | |
2267 | 2274 | | |
2268 | 2275 | | |
| |||
2475 | 2482 | | |
2476 | 2483 | | |
2477 | 2484 | | |
2478 | | - | |
| 2485 | + | |
| 2486 | + | |
2479 | 2487 | | |
2480 | 2488 | | |
2481 | 2489 | | |
| 2490 | + | |
2482 | 2491 | | |
2483 | 2492 | | |
2484 | 2493 | | |
2485 | 2494 | | |
| 2495 | + | |
2486 | 2496 | | |
2487 | 2497 | | |
2488 | 2498 | | |
| |||
2564 | 2574 | | |
2565 | 2575 | | |
2566 | 2576 | | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
2567 | 2588 | | |
2568 | 2589 | | |
2569 | 2590 | | |
| |||
2806 | 2827 | | |
2807 | 2828 | | |
2808 | 2829 | | |
2809 | | - | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
2810 | 2837 | | |
2811 | 2838 | | |
2812 | 2839 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1234 | 1234 | | |
1235 | 1235 | | |
1236 | 1236 | | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
1237 | 1241 | | |
1238 | 1242 | | |
1239 | 1243 | | |
| |||
1300 | 1304 | | |
1301 | 1305 | | |
1302 | 1306 | | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1303 | 1311 | | |
1304 | 1312 | | |
1305 | 1313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1483 | 1483 | | |
1484 | 1484 | | |
1485 | 1485 | | |
| 1486 | + | |
1486 | 1487 | | |
1487 | 1488 | | |
1488 | 1489 | | |
| |||
0 commit comments