mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-10-29 22:03:15 -06:00
[PR #238] fix(api/host): avoid garbage interrupt/dpc times in host CPU percent #237
Labels
No labels
api
bug
bug
cli / tui
dependencies
documentation
documentation
documentation
duplicate
enhancement
exporter
invalid
pull-request
pynvml
question
question
upstream
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github-starred/nvitop#237
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/XuehaiPan/nvitop/pull/238
Author: @arinawang11
Created: 10/31/2026
Status: 🔄 Open
Base:
main← Head:fix/host-cpu-percent-windows📝 Commits (1)
b757a3afix(api/host): avoid garbageinterrupt/dpctimes in host CPU percent📊 Changes
2 files changed (+39 additions, -0 deletions)
View changed files
📝
docs/source/spelling_wordlist.txt(+2 -0)📝
nvitop/api/host.py(+37 -0)📄 Description
Problem
On Windows machines with more than 64 logical CPUs the host CPU percentage occasionally jumps to 100% while the machine is nearly idle, making the TUI graph oscillate between 100% and 0%.
Root cause
psutil.cpu_percent()computes the busy time asuser + system + interrupt + dpc. On Windows:user/system/idlecome fromGetSystemTimes()(one aggregate call).interrupt/dpcare summed fromcext.per_cpu_times(), which fills a buffer throughNtQuerySystemInformation(SystemProcessorPerformanceInformation). That API only fills the entries of the calling thread's processor group (at most 64 CPUs); on larger machines the remaining entries are never written and are read uninitialized.Measured on a 96-logical-CPU Windows Server 2025 host with psutil 7.2.2:
Whenever those values change between two samples, the busy delta dwarfs the real one and
cpu_percent()returns100.0. A 15 s run of the TUI produced four such samples.Upstream: psutil#2972 (uninitialized memory, fixed on
masterby3ea90fd9, not part of a release yet) and psutil#3061 (per-CPU APIs only cover one processor group, still open).Fix
On Windows, compute the host utilization from
user + systemoveruser + system + idle.psutil.cpu_times().systemis the kernel time minus idle and already includes interrupt/DPC time, so the result is complete and independent of the broken fields. It also removes the existing double counting of interrupt/DPC on healthy Windows machines and matches the\Processor Information(_Total)\% Processor Timecounter (Task Manager's default% Processor Utilityis additionally frequency-weighted, so small differences remain expected).The baseline is kept per thread like
psutil.cpu_percent(), the first call in each thread returns0.0, andpercpu=True/ blockingintervalcalls are still delegated to psutil.Placing the workaround in
nvitop.api.hostfixes every consumer at once (TUI host panel,nvitop --metricscollector, nvitop-exporter); other platforms are untouched.Affected scope
interrupt/dpconly exist there)Verification
On the 96-logical-CPU machine:
100.0samples in 15 s (logged fromhost-snapshot-daemon).>= 99.9in 20 s; values 0.4%–5.6%, consistent with the% Processor Timecounter.ruff checkandruff format --checkpass.dpcanduninitializedwere added to the pylint spelling wordlist.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.