mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-05-15 14:15:55 -06:00
[GH-ISSUE #71] [Question] process.cpu_percent() got over 100% value #42
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#42
Loading…
Add table
Add a link
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?
Originally created by @qpc001 on GitHub (Apr 11, 2023).
Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/71
Originally assigned to: @XuehaiPan on GitHub.
Required prerequisites
Questions
I am using the script here:
5a0da9239b/README.md (L658)And I print a strange cpu_percent value:
But I print in top is:

@qpc001 commented on GitHub (Apr 11, 2023):
The full script I am using is:
@XuehaiPan commented on GitHub (Apr 11, 2023):
Hi @qpc001
From
htopmanual page (ref: Why is the CPU usage reported by top in Linux over 100%?):The CPU percent is calculated by:
when you are running a multi-threaded program on a multi-core machine. It can be over 100%. E.g.
3000%on a 32-core machine.Feel free to ask more questions.
@qpc001 commented on GitHub (Apr 12, 2023):
My point is that it is not possible for the CPU usage of this program to reach over 200%, rather than discussing why the program's CPU usage can exceed 100%.
@XuehaiPan commented on GitHub (Apr 12, 2023):
@qpc001 I'm sorry that I misunderstood your question. But the answer would be similar.
It can get CPU percent over 100%. As I mentioned:
It's really depending on your sample interval for
elapsed_time. It can get a large value if yourelapsed_timeis relatively small. If you want to get a more accurate result. You should average over a time interval.This would block your program for 1 second and gather the CPU time information during the sample interval.
nvitopuseprocess.cpu_percent()in non-blocking mode. That is, it will not block your program but use the CPU time information between two calls. You may get an inaccurate result in the first call because you don't have a previous call to compare with.Here is the code for how
psutil.Processcalculate the CPU percent:90b35e3ae8/psutil/init.py#L946-L1036The result also depends on how many CPUs are on your machine.
nvitopusespsutilto gather process information about CPU and virtual RAM usage. If you think this would be a bug, please report it to giampaolo/psutil.Here is the result from my side: