1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-01 13:48:52 +08:00

fix(process): 确保CPU使用率计算为非负值

This commit is contained in:
liang.che 2024-08-16 17:11:45 +08:00
parent 07303dfe82
commit caed610b41

View File

@ -338,6 +338,9 @@ func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64
return 0
}
delta_proc := calculateBusyTime(t2) - calculateBusyTime(t1)
if delta_proc <= 0 {
return 0
}
overall_percent := ((delta_proc / delta) * 100) * float64(numcpu)
return overall_percent
}