disable cpu stat in wsl linux

master
kevin 4 years ago
parent 1c24e71568
commit 5d8a3c07cd

@ -22,19 +22,30 @@ var (
cores uint64 cores uint64
) )
// if /proc not present, ignore the cpu calcuation, like wsl linux
func init() { func init() {
cpus, err := perCpuUsage() cpus, err := perCpuUsage()
logx.Must(err) if err != nil {
cores = uint64(len(cpus)) logx.Error(err)
return
}
cores = uint64(len(cpus))
sets, err := cpuSets() sets, err := cpuSets()
logx.Must(err) if err != nil {
logx.Error(err)
return
}
quota = float64(len(sets)) quota = float64(len(sets))
cq, err := cpuQuota() cq, err := cpuQuota()
if err == nil { if err == nil {
if cq != -1 { if cq != -1 {
period, err := cpuPeriod() period, err := cpuPeriod()
logx.Must(err) if err != nil {
logx.Error(err)
return
}
limit := float64(cq) / float64(period) limit := float64(cq) / float64(period)
if limit < quota { if limit < quota {
@ -44,10 +55,16 @@ func init() {
} }
preSystem, err = systemCpuUsage() preSystem, err = systemCpuUsage()
logx.Must(err) if err != nil {
logx.Error(err)
return
}
preTotal, err = totalCpuUsage() preTotal, err = totalCpuUsage()
logx.Must(err) if err != nil {
logx.Error(err)
return
}
} }
func RefreshCpu() uint64 { func RefreshCpu() uint64 {

Loading…
Cancel
Save