You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_remote_debugging: --mode cpu --blocking can return an empty profile #162427
maurycy@gimel cpython (main e0d0f2e?) % sudo ./python.exe -m profiling.sampling run --mode cpu --blocking -m timeit
100000000 loops, best of 5: 3.15 nsec per loop
Captured 2,185 samples in 2.19 seconds
Sample rate: 999.95 samples/sec
Error rate: 0.00
No samples were collected.
This can happen in CPU mode when all threads are idle.
Note the No samples were collected..
A bit more complex repro but the result is the asme:
2026-11-22T11:09:05.918638000+0100 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main e0d0f2e?) % echo'print(sum(i*i for i in range(10_000_000)))'> busy.py
2026-11-22T11:09:06.849092000+0100 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main e0d0f2e?) % sudo ./python.exe -m profiling.sampling run --mode cpu --blocking busy.py
333333283333335000000
Captured 343 samples in 0.34 seconds
Sample rate: 999.63 samples/sec
Error rate: 0.29
No samples were collected.
This can happen in CPU mode when all threads are idle.
The cause: we task_suspend() before doing get_thread_status() and we never get TH_STATE_RUNNING so cannot report ON_CPU. I suspect the same thing happens on Linux
I see this on Linux too. A busy thread goes from R to t when we pause it, so the CPU filter drops it.
I think your suggestion is right. We want the CPU state to tell us what the thread was doing when we sampled it. Once we stop the thread, that state reflects our own pause. I suggest we save the state by native thread ID just before the pause, then read the stacks once the threads stop. A thread can still go idle in between, but the pause itself will no longer make every busy thread disappear from the profile.
@pablogsal Yes, but... there's some backlog I want to go through first, especially all the great code reviews! Realistically I'd put this on hold for a week or two. Maybe we can pair, just like in #161956?
Activity
maurycy commentedon Nov 22, 2026
cc @pablogsal I did not explore the solution space here. The obvious intuition is to gather the state before pausing. It feels racy, though.
pablogsal commentedon Nov 22, 2026
I see this on Linux too. A busy thread goes from
Rtotwhen we pause it, so the CPU filter drops it.I think your suggestion is right. We want the CPU state to tell us what the thread was doing when we sampled it. Once we stop the thread, that state reflects our own pause. I suggest we save the state by native thread ID just before the pause, then read the stacks once the threads stop. A thread can still go idle in between, but the pause itself will no longer make every busy thread disappear from the profile.
pablogsal commentedon Nov 22, 2026
Do you want to work on a fix?
maurycy commentedon Nov 22, 2026
@pablogsal Yes, but... there's some backlog I want to go through first, especially all the great code reviews! Realistically I'd put this on hold for a week or two. Maybe we can pair, just like in #161956?