(self)
| 22 | |
| 23 | # --------------------------------------------------------------------------- |
| 24 | # Non-blocking CPU sampling |
| 25 | # --------------------------------------------------------------------------- |
| 26 | # psutil.cpu_percent(interval=N) SLEEPS the calling thread for N seconds to |
| 27 | # measure over that window. The status endpoints call it, and the dashboard |
| 28 | # polls those endpoints, so every tab switch / click paid a full ~1s stall |
| 29 | # (the "1-2 second delay when clicking on things" operators reported). |
| 30 | # |
| 31 | # Instead we sample in compute-since-last-call mode (interval=None), which |
| 32 | # returns instantly, and cache it — re-sampling at most once per |
| 33 | # _CPU_MIN_WINDOW seconds so each real sample still spans a meaningful window. |
| 34 | # Every caller shares this one cache, so the value stays consistent and no |
| 35 | # request ever blocks. The very first reading is 0.0 until the sampler primes. |
| 36 | _cpu_lock = threading.Lock() |
| 37 | _cpu_cached = 0.0 |
| 38 | _cpu_primed = False |
| 39 | _cpu_sampled_at = 0.0 |
nothing calls this directly
no outgoing calls
no test coverage detected