|
|
@ -21,10 +21,9 @@ var (
|
|
|
|
preTotal uint64
|
|
|
|
preTotal uint64
|
|
|
|
quota float64
|
|
|
|
quota float64
|
|
|
|
cores uint64
|
|
|
|
cores uint64
|
|
|
|
|
|
|
|
initOnce sync.Once
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var initonce sync.Once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if /proc not present, ignore the cpu calculation, like wsl linux
|
|
|
|
// if /proc not present, ignore the cpu calculation, like wsl linux
|
|
|
|
func initialize() {
|
|
|
|
func initialize() {
|
|
|
|
cpus, err := cpuSets()
|
|
|
|
cpus, err := cpuSets()
|
|
|
@ -72,11 +71,13 @@ func initialize() {
|
|
|
|
|
|
|
|
|
|
|
|
// RefreshCpu refreshes cpu usage and returns.
|
|
|
|
// RefreshCpu refreshes cpu usage and returns.
|
|
|
|
func RefreshCpu() uint64 {
|
|
|
|
func RefreshCpu() uint64 {
|
|
|
|
initonce.Do(initialize)
|
|
|
|
initOnce.Do(initialize)
|
|
|
|
|
|
|
|
|
|
|
|
total, err := totalCpuUsage()
|
|
|
|
total, err := totalCpuUsage()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
system, err := systemCpuUsage()
|
|
|
|
system, err := systemCpuUsage()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|