From 123a6c9b0db86670bb8781f588341c9d9c7cecbb Mon Sep 17 00:00:00 2001 From: "K.C. Wong" Date: Tue, 23 Aug 2016 16:48:25 -0700 Subject: [PATCH] Addressing frequency unit discrepancies * for Darwin, it is a minor tweak for readability: the value returned is in Hz, so using a variable named 'hz' makes more sense than 'mhz' * for Linux, the unit is in kHz so we need to divide the value from `cpuinfo_max_freq` by 10^3 to get MHz (see cpu-freq/user-guide.txt of the kernel documentation) --- cpu/cpu_darwin.go | 4 ++-- cpu/cpu_linux.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index 4cb1d8c..af27e62 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -96,11 +96,11 @@ func Info() ([]InfoStat, error) { } values := strings.Fields(string(out)) - mhz, err := strconv.ParseFloat(values[1], 64) + hz, err := strconv.ParseFloat(values[1], 64) if err != nil { return ret, err } - c.Mhz = mhz / 1000000.0 + c.Mhz = hz / 1000000.0 return append(ret, c), nil } diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 6df542b..0f095f1 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -72,7 +72,7 @@ func finishCPUInfo(c *InfoStat) error { if err != nil { return err } - c.Mhz = value + c.Mhz = value/1000.0 // value is in kHz } } if len(c.CoreID) == 0 {