mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-02 22:17:08 +08:00
fix(process): 确保CPU使用率计算为非负值
This commit is contained in:
parent
07303dfe82
commit
caed610b41
@ -338,6 +338,9 @@ func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
delta_proc := calculateBusyTime(t2) - calculateBusyTime(t1)
|
delta_proc := calculateBusyTime(t2) - calculateBusyTime(t1)
|
||||||
|
if delta_proc <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
overall_percent := ((delta_proc / delta) * 100) * float64(numcpu)
|
overall_percent := ((delta_proc / delta) * 100) * float64(numcpu)
|
||||||
return overall_percent
|
return overall_percent
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user