open-nomad/helper/stats/cpu.go

31 lines
534 B
Go
Raw Normal View History

2016-06-10 21:46:33 +00:00
package stats
import (
"github.com/shirou/gopsutil/cpu"
2016-06-11 15:31:49 +00:00
"sync"
)
var (
clkSpeed float64
ticksLock sync.Mutex
2016-06-10 21:46:33 +00:00
)
// TotalTicksAvailable calculates the total frequency available across all cores
2016-06-11 15:31:49 +00:00
func TotalTicksAvailable() float64 {
ticksLock.Lock()
defer ticksLock.Unlock()
if clkSpeed == 0.0 {
var cpuInfo []cpu.InfoStat
var err error
2016-06-10 21:46:33 +00:00
2016-06-11 15:31:49 +00:00
var totalTicks float64
if cpuInfo, err = cpu.Info(); err == nil {
for _, cpu := range cpuInfo {
totalTicks += cpu.Mhz
}
clkSpeed = totalTicks
}
2016-06-10 21:46:33 +00:00
}
2016-06-11 15:31:49 +00:00
return clkSpeed
2016-06-10 21:46:33 +00:00
}