chore: refactor stat (#2299)

master
Kevin Wan 2 years ago committed by GitHub
parent 90cdd61efc
commit 36678f9023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save