Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu.Percent is less then process.CPUPercent #1684

Open
soluchok opened this issue Aug 5, 2024 · 0 comments
Open

cpu.Percent is less then process.CPUPercent #1684

soluchok opened this issue Aug 5, 2024 · 0 comments

Comments

@soluchok
Copy link

soluchok commented Aug 5, 2024

As I understand, cpu.Percent shows the CPU usage of the entire system, while process.CPUPercent shows the CPU usage of a specific process. How is it possible that cpu.Percent returns 2% but process.CPUPercent returns 4%? Am I missing something here?

import "github.com/shirou/gopsutil/v4/cpu"
import "github.com/shirou/gopsutil/v4/process"

proc, _ := process.NewProcess(int32(os.Getpid()))
usage, _ := proc.CPUPercent() // usage is 4%

cpuPercent, err := cpu.Percent(0, false) // cpuPercent is 2%
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

No branches or pull requests

1 participant