mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
chore: refactor stat (#2299)
This commit is contained in:
parent
90cdd61efc
commit
36678f9023
@ -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…
Reference in New Issue
Block a user