|
|
|
@ -199,24 +199,24 @@ func (p *Process) MemoryPercent() (float32, error) {
|
|
|
|
|
|
|
|
|
|
return (100 * float32(used) / float32(total)), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CPU_Percent returns how many percent of the CPU time this process uses
|
|
|
|
|
func (p *Process) CPUPercent() (float64, error) {
|
|
|
|
|
crt_time, err := p.CreateTime()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
crt_time, err := p.CreateTime()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cput, err := p.Times()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
cput, err := p.Times()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
created := time.Unix(0, crt_time * int64(time.Millisecond))
|
|
|
|
|
totalTime := time.Since(created).Seconds()
|
|
|
|
|
if totalTime <= 0 {
|
|
|
|
|
return 0, nil
|
|
|
|
|
}
|
|
|
|
|
created := time.Unix(0, crt_time*int64(time.Millisecond))
|
|
|
|
|
totalTime := time.Since(created).Seconds()
|
|
|
|
|
if totalTime <= 0 {
|
|
|
|
|
return 0, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 100 * cput.Total() / totalTime, nil
|
|
|
|
|
return 100 * cput.Total() / totalTime, nil
|
|
|
|
|
}
|
|
|
|
|