Skip to content

gh-159312: Resolve CPU attribution from collected stacks - #159328

Draft
pablogsal wants to merge 3 commits into
python:mainfrom
pablogsal:fix-159312-cpu-tstate
Draft

pablogsal wants to merge 3 commits into
python:mainfrom
pablogsal:fix-159312-cpu-tstate

Conversation

@pablogsal

@pablogsal pablogsal commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

CPU mode can attribute samples to a suspended stack when another thread state uses the same native thread. Use the binding status and stacks already collected to prefer a bound, nonempty stack. Preserve the existing attribution when no such stack is present, including native work after a callback deletes or empties its temporary state.

Only samples containing an unbound stack run the local filter. It uses a temporary set and two passes over the collected results, with no additional remote reads or OS thread-status queries. Ordinary bound-state samples add only local checks. The regression uses the existing test helper.

External-inspection and profiling tests pass on regular and free-threaded debug builds, with 547 tests on each; the regression also passes reference-leak checks. Linux syscall counts match the original code for ordinary, duplicate-state, and callback-return samples, with frame caching on and off. In cached ALL-mode debug measurements, median sample times were 6.14 to 6.09 microseconds for ordinary sampling, 19.85 to 20.31 for duplicate states, and 29.00 to 29.56 after a callback. The unusual cases still incur local filtering work.

@pablogsal pablogsal changed the title gh-159312: Prefer bound stacks for CPU sample attribution gh-159312: Avoid CPU attribution to suspended thread states Oct 13, 2026
@pablogsal pablogsal closed this Oct 14, 2026
@pablogsal pablogsal changed the title gh-159312: Avoid CPU attribution to suspended thread states gh-159312: Resolve CPU attribution from collected stacks Oct 15, 2026
@pablogsal pablogsal reopened this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant