mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-08 19:29:25 +08:00
Merge pull request #1325 from shirou/feature/fix_cpu_total
fix(cpu): fix cpu total and busy calc
This commit is contained in:
commit
46f7642940
21
cpu/cpu.go
21
cpu/cpu.go
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -86,10 +87,12 @@ func (c TimesStat) String() string {
|
|||||||
return `{` + strings.Join(v, ",") + `}`
|
return `{` + strings.Join(v, ",") + `}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Total returns the total number of seconds in a CPUTimesStat
|
// Deprecated: Total returns the total number of seconds in a CPUTimesStat
|
||||||
|
// Please do not use this internal function.
|
||||||
func (c TimesStat) Total() float64 {
|
func (c TimesStat) Total() float64 {
|
||||||
total := c.User + c.System + c.Nice + c.Iowait + c.Irq + c.Softirq +
|
total := c.User + c.System + c.Idle + c.Nice + c.Iowait + c.Irq +
|
||||||
c.Steal + c.Idle
|
c.Softirq + c.Steal + c.Guest + c.GuestNice
|
||||||
|
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +102,15 @@ func (c InfoStat) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAllBusy(t TimesStat) (float64, float64) {
|
func getAllBusy(t TimesStat) (float64, float64) {
|
||||||
busy := t.User + t.System + t.Nice + t.Iowait + t.Irq +
|
tot := t.Total()
|
||||||
t.Softirq + t.Steal
|
if runtime.GOOS == "linux" {
|
||||||
return busy + t.Idle, busy
|
tot -= t.Guest // Linux 2.6.24+
|
||||||
|
tot -= t.GuestNice // Linux 3.2.0+
|
||||||
|
}
|
||||||
|
|
||||||
|
busy := tot - t.Idle - t.Iowait
|
||||||
|
|
||||||
|
return tot, busy
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateBusy(t1, t2 TimesStat) float64 {
|
func calculateBusy(t1, t2 TimesStat) float64 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user