Fix NaN percentage if process was created too soon
This commit is contained in:
parent
6e221c4826
commit
696e1e0123
|
@ -207,12 +207,13 @@ func (p *Process) CPUPercent() (float64, error) {
|
|||
}
|
||||
|
||||
|
||||
cpu, err := p.Times()
|
||||
cput, err := p.Times()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
created := time.Unix(0, crt_time * int64(time.Millisecond))
|
||||
totalTime := time.Since(created).Seconds()
|
||||
|
||||
return (100 * (cpu.Total()) / float64(time.Now().Unix()-(crt_time/1000))), nil
|
||||
return (100 * (cput.Total() / totalTime)), nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue