mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
This commit is contained in:
parent
caed610b41
commit
e05e22b6cb
@ -321,23 +321,12 @@ func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||
return p.createTime, err
|
||||
}
|
||||
|
||||
// https://github.com/giampaolo/psutil/blob/550c825c95b537e9c3fee8452e5e1cd4fe5c704a/psutil/__init__.py#L1664-L1677
|
||||
func calculateBusyTime(t *cpu.TimesStat) float64 {
|
||||
tot := t.Total()
|
||||
if runtime.GOOS == "linux" {
|
||||
tot -= t.Guest // Linux 2.6.24+
|
||||
tot -= t.GuestNice // Linux 3.2.0+
|
||||
}
|
||||
tot -= t.Idle
|
||||
tot -= t.Iowait
|
||||
return tot
|
||||
}
|
||||
|
||||
func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64 {
|
||||
if delta == 0 {
|
||||
return 0
|
||||
}
|
||||
delta_proc := calculateBusyTime(t2) - calculateBusyTime(t1)
|
||||
//https://github1s.com/giampaolo/psutil/blob/c034e6692cf736b5e87d14418a8153bb03f6cf42/psutil/__init__.py#L1064
|
||||
delta_proc := (t2.User - t1.User) + (t2.System - t1.System)
|
||||
if delta_proc <= 0 {
|
||||
return 0
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user