gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

CPUPercent is Wrong,Percent is OK,but wait one second

Open greatdba opened this issue 3 years ago • 2 comments

Describe the bug proc, _ := process.NewProcess(int32(pid)) cpuPercent, err := proc.CPUPercent() //get wrong value

proc, _ := process.NewProcess(int32(pid)) cpuPercent, err := proc.Percent(time.Second) //right value, **but wait one second** , same like psutil(python)

### how to get cpuPercent faster ?

To Reproduce

// paste example code reproducing the bug you are reporting

Expected behavior [A clear and concise description of what you expected to happen.]

Environment (please complete the following information):

  • [ ] Windows: [paste the result of ver]
  • [x] Linux: [paste contents of /etc/os-release and the result of uname -a]
  • [ ] Mac OS: [paste the result of sw_vers and uname -a
  • [ ] FreeBSD: [paste the result of freebsd-version -k -r -u and uname -a]
  • [ ] OpenBSD: [paste the result of uname -a]

Additional context [Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]

greatdba avatar Sep 13 '22 13:09 greatdba

Could you tell us what is the 'wrong value' with some examples?

shirou avatar Sep 20 '22 09:09 shirou

I have same problem cpuPercent, err := proc.CPUPercent(), cpuPercentis wrong. 飞书20230112-105036

qingfengshuixu11 avatar Jan 12 '23 02:01 qingfengshuixu11