From e05e22b6cbfa87f3ab22a6867cfef8e44cf33dfd Mon Sep 17 00:00:00 2001 From: "liang.che" Date: Mon, 19 Aug 2024 11:22:57 +0800 Subject: [PATCH] https://github1s.com/giampaolo/psutil/blob/c034e6692cf736b5e87d14418a8153bb03f6cf42/psutil/__init__.py#L1064 --- process/process.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/process/process.go b/process/process.go index 03c62cf8..3c9e3f45 100644 --- a/process/process.go +++ b/process/process.go @@ -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 }