diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index cd0475d..3d3455e 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -4,6 +4,7 @@ package cpu import ( "context" + "os/exec" "strconv" "strings" @@ -23,6 +24,21 @@ const ( // default value. from time.h var ClocksPerSec = float64(128) +func init() { + getconf, err := exec.LookPath("getconf") + if err != nil { + return + } + out, err := invoke.Command(getconf, "CLK_TCK") + // ignore errors + if err == nil { + i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64) + if err == nil { + ClocksPerSec = float64(i) + } + } +} + func Times(percpu bool) ([]TimesStat, error) { return TimesWithContext(context.Background(), percpu) }