From 5d8a3c07cd18dcc8881799e954797ae23e03d254 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 27 Aug 2020 13:22:44 +0800 Subject: [PATCH] disable cpu stat in wsl linux --- core/stat/internal/cpu_linux.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/core/stat/internal/cpu_linux.go b/core/stat/internal/cpu_linux.go index 460d3b99..057ed47e 100644 --- a/core/stat/internal/cpu_linux.go +++ b/core/stat/internal/cpu_linux.go @@ -22,19 +22,30 @@ var ( cores uint64 ) +// if /proc not present, ignore the cpu calcuation, like wsl linux func init() { cpus, err := perCpuUsage() - logx.Must(err) - cores = uint64(len(cpus)) + if err != nil { + logx.Error(err) + return + } + cores = uint64(len(cpus)) sets, err := cpuSets() - logx.Must(err) + if err != nil { + logx.Error(err) + return + } + quota = float64(len(sets)) cq, err := cpuQuota() if err == nil { if cq != -1 { period, err := cpuPeriod() - logx.Must(err) + if err != nil { + logx.Error(err) + return + } limit := float64(cq) / float64(period) if limit < quota { @@ -44,10 +55,16 @@ func init() { } preSystem, err = systemCpuUsage() - logx.Must(err) + if err != nil { + logx.Error(err) + return + } preTotal, err = totalCpuUsage() - logx.Must(err) + if err != nil { + logx.Error(err) + return + } } func RefreshCpu() uint64 {