From 36678f902364d6df22d67680f8d11b1189ce7a96 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Thu, 25 Aug 2022 23:37:32 +0800 Subject: [PATCH] chore: refactor stat (#2299) --- core/stat/internal/cpu_linux.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/stat/internal/cpu_linux.go b/core/stat/internal/cpu_linux.go index 5965b096..5c8c6521 100644 --- a/core/stat/internal/cpu_linux.go +++ b/core/stat/internal/cpu_linux.go @@ -21,10 +21,9 @@ var ( preTotal uint64 quota float64 cores uint64 + initOnce sync.Once ) -var initonce sync.Once - // if /proc not present, ignore the cpu calculation, like wsl linux func initialize() { cpus, err := cpuSets() @@ -72,11 +71,13 @@ func initialize() { // RefreshCpu refreshes cpu usage and returns. func RefreshCpu() uint64 { - initonce.Do(initialize) + initOnce.Do(initialize) + total, err := totalCpuUsage() if err != nil { return 0 } + system, err := systemCpuUsage() if err != nil { return 0