From ff31c3cc450ace5599256a26a350f5525358b6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20W=20Baul=C3=A9?= Date: Mon, 28 Aug 2023 11:51:58 -0300 Subject: [PATCH] Implement Mhz to current, min and max. --- cpu/cpu.go | 8 ++++- cpu/cpu_aix_cgo.go | 8 +++-- cpu/cpu_aix_nocgo.go | 10 +++--- cpu/cpu_darwin.go | 8 +++-- cpu/cpu_darwin_test.go | 2 +- cpu/cpu_dragonfly.go | 5 +-- cpu/cpu_freebsd.go | 4 ++- cpu/cpu_linux.go | 47 ++++++++++++++++----------- cpu/cpu_openbsd.go | 4 ++- cpu/cpu_solaris.go | 12 +++++-- cpu/cpu_solaris_test.go | 86 ++++++++++++++++++++++++------------------------- cpu/cpu_windows.go | 9 ++++-- 12 files changed, 123 insertions(+), 80 deletions(-) diff --git a/cpu/cpu.go b/cpu/cpu.go index 83bc23d..dbce093 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -40,12 +40,18 @@ type InfoStat struct { CoreID string `json:"coreId"` Cores int32 `json:"cores"` ModelName string `json:"modelName"` - Mhz float64 `json:"mhz"` + Mhz Mhz `json:"mhz"` CacheSize int32 `json:"cacheSize"` Flags []string `json:"flags"` Microcode string `json:"microcode"` } +type Mhz struct { + current float64 `json:"current"` //from cpuinfo or cpufreq/cpuinfo_cur_freq + max float64 `json:"max"` //from cpufreq/cpuinfo_max_freq + min float64 `json:"min"` //from cpufreq/cpuinfo_min_freq +} + type lastPercent struct { sync.Mutex lastCPUTimes []TimesStat diff --git a/cpu/cpu_aix_cgo.go b/cpu/cpu_aix_cgo.go index 9c1e70b..3f13b55 100644 --- a/cpu/cpu_aix_cgo.go +++ b/cpu/cpu_aix_cgo.go @@ -49,8 +49,12 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { return nil, err } info := InfoStat{ - CPU: 0, - Mhz: float64(c.ProcessorHz / 1000000), + CPU: 0, + Mhz: Mhz{ + current: float64(c.ProcessorHz / 1000000), + max: 0, + min: 0, + }, Cores: int32(c.NCpusCfg), } result := []InfoStat{info} diff --git a/cpu/cpu_aix_nocgo.go b/cpu/cpu_aix_nocgo.go index 1a29153..46bb7db 100644 --- a/cpu/cpu_aix_nocgo.go +++ b/cpu/cpu_aix_nocgo.go @@ -70,14 +70,16 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { if t, err := strconv.ParseFloat(p[3], 64); err == nil { switch strings.ToUpper(p[4]) { case "MHZ": - ret.Mhz = t + ret.Mhz.current = t case "GHZ": - ret.Mhz = t * 1000.0 + ret.Mhz.current = t * 1000.0 case "KHZ": - ret.Mhz = t / 1000.0 + ret.Mhz.current = t / 1000.0 default: - ret.Mhz = t + ret.Mhz.current = t } + ret.Mhz.min = 0 + ret.Mhz.max = 0 } } break diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index 41f395e..6d597fd 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -87,13 +87,17 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { c.VendorID, _ = unix.Sysctl("machdep.cpu.vendor") if m1cpu.IsAppleSilicon() { - c.Mhz = float64(m1cpu.PCoreHz() / 1_000_000) + c.Mhz.current = float64(m1cpu.PCoreHz() / 1_000_000) + c.Mhz.max = 0 + c.Mhz.min = 0 } else { // Use the rated frequency of the CPU. This is a static value and does not // account for low power or Turbo Boost modes. cpuFrequency, err := unix.SysctlUint64("hw.cpufrequency") if err == nil { - c.Mhz = float64(cpuFrequency) / 1000000.0 + c.Mhz.current = float64(cpuFrequency) / 1000000.0 + c.Mhz.max = 0 + c.Mhz.min = 0 } } diff --git a/cpu/cpu_darwin_test.go b/cpu/cpu_darwin_test.go index 57b3d66..b21319d 100644 --- a/cpu/cpu_darwin_test.go +++ b/cpu/cpu_darwin_test.go @@ -23,7 +23,7 @@ func Test_CpuInfo_AppleSilicon(t *testing.T) { if vv.ModelName == "" { t.Errorf("could not get CPU info: %v", vv) } - if vv.Mhz <= 0 { + if vv.Mhz.current <= 0 { t.Errorf("could not get frequency of: %s", vv.ModelName) } if vv.Mhz > 6000 { diff --git a/cpu/cpu_dragonfly.go b/cpu/cpu_dragonfly.go index fef53e5..5fda78b 100644 --- a/cpu/cpu_dragonfly.go +++ b/cpu/cpu_dragonfly.go @@ -102,8 +102,9 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { if u32, err = unix.SysctlUint32("hw.clockrate"); err != nil { return nil, err } - c.Mhz = float64(u32) - + c.Mhz.current = float64(u32) + c.Mhz.min = 0 + c.Mhz.max = 0 var num int var buf string if buf, err = unix.Sysctl("hw.cpu_topology.tree"); err != nil { diff --git a/cpu/cpu_freebsd.go b/cpu/cpu_freebsd.go index d3f4735..0d31613 100644 --- a/cpu/cpu_freebsd.go +++ b/cpu/cpu_freebsd.go @@ -103,7 +103,9 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { if u32, err = unix.SysctlUint32("hw.clockrate"); err != nil { return nil, err } - c.Mhz = float64(u32) + c.Mhz.current = float64(u32) + c.Mhz.min = 0 + c.Mhz.max = 0 if u32, err = unix.SysctlUint32("hw.ncpu"); err != nil { return nil, err diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index b5a20e3..2b81505 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -133,7 +133,6 @@ func sysCPUPath(ctx context.Context, cpu int32, relPath string) string { func finishCPUInfo(ctx context.Context, c *InfoStat) { var lines []string var err error - var value float64 if len(c.CoreID) == 0 { lines, err = common.ReadLines(sysCPUPath(ctx, c.CPU, "topology/core_id")) @@ -142,23 +141,35 @@ func finishCPUInfo(ctx context.Context, c *InfoStat) { } } - // override the value of c.Mhz with cpufreq/cpuinfo_max_freq regardless - // of the value from /proc/cpuinfo because we want to report the maximum - // clock-speed of the CPU for c.Mhz, matching the behaviour of Windows - lines, err = common.ReadLines(sysCPUPath(ctx, c.CPU, "cpufreq/cpuinfo_max_freq")) - // if we encounter errors below such as there are no cpuinfo_max_freq file, - // we just ignore. so let Mhz is 0. - if err != nil || len(lines) == 0 { - return - } - value, err = strconv.ParseFloat(lines[0], 64) - if err != nil { - return - } - c.Mhz = value / 1000.0 // value is in kHz - if c.Mhz > 9999 { - c.Mhz = c.Mhz / 1000.0 // value in Hz + c.Mhz.current = fillMhz(ctx, "current", c) + c.Mhz.min = fillMhz(ctx, "min", c) + c.Mhz.max = fillMhz(ctx, "max", c) + +} + +func fillMhz(ctx context.Context, value string, c *InfoStat) float64 { + var lines []string + var err error + var line float64 + var mhz float64 = 0 + + if value == "min" || value == "max" || value == "current" { + lines, err = common.ReadLines(sysCPUPath(ctx, c.CPU, fmt.Sprintf("cpufreq/cpuinfo_%s_freq", value))) + // if we encounter errors below such as there are no cpuinfo_max_freq file, + // we just ignore. so let Mhz is 0. + if err != nil || len(lines) == 0 { + return mhz + } + line, err = strconv.ParseFloat(lines[0], 64) + if err != nil { + return mhz + } + mhz = line / 1000.0 // value is in kHz + if mhz > 9999 { + mhz = mhz / 1000.0 // value in Hz + } } + return 0 } // CPUInfo on linux will return 1 item per physical thread. @@ -279,7 +290,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { case "cpu MHz", "clock", "cpu MHz dynamic": // treat this as the fallback value, thus we ignore error if t, err := strconv.ParseFloat(strings.Replace(value, "MHz", "", 1), 64); err == nil { - c.Mhz = t + c.Mhz.current = t } case "cache size": t, err := strconv.ParseInt(strings.Replace(value, " KB", "", 1), 10, 64) diff --git a/cpu/cpu_openbsd.go b/cpu/cpu_openbsd.go index fe33290..2895d48 100644 --- a/cpu/cpu_openbsd.go +++ b/cpu/cpu_openbsd.go @@ -117,7 +117,9 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { if err != nil { return nil, err } - c.Mhz = float64(mhz) + c.Mhz.current = float64(mhz) + c.Mhz.min = 0 + c.Mhz.max = 0 ncpu, err := unix.SysctlUint32("hw.ncpuonline") if err != nil { diff --git a/cpu/cpu_solaris.go b/cpu/cpu_solaris.go index f828c84..518e94d 100644 --- a/cpu/cpu_solaris.go +++ b/cpu/cpu_solaris.go @@ -226,7 +226,11 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) { Family: physicalCPU[psrFamilyOffset], Model: physicalCPU[psrModelOffset], Stepping: step, - Mhz: clock, + Mhz: Mhz{ + current: clock, + max: 0, + min: 0, + }, }) infoStatCount++ } @@ -252,7 +256,11 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) { Family: physicalCPU[psrFamilyOffset], Model: physicalCPU[psrModelOffset], Stepping: step, - Mhz: clock, + Mhz: Mhz{ + current: clock, + max: 0, + min: 0, + }, }) infoStatCount++ } diff --git a/cpu/cpu_solaris_test.go b/cpu/cpu_solaris_test.go index 508aad5..c6951ac 100644 --- a/cpu/cpu_solaris_test.go +++ b/cpu/cpu_solaris_test.go @@ -75,64 +75,64 @@ func TestParseProcessorInfo(t *testing.T) { { "1cpu_1core_psrinfo.txt", []InfoStat{ - {CPU: 0, VendorID: "GenuineIntel", Family: "6", Model: "78", Stepping: 3, PhysicalID: "0", CoreID: "0", Cores: 1, ModelName: "Intel(r) Core(tm) i7-6567U CPU @ 3.30GHz", Mhz: 3312}, + {CPU: 0, VendorID: "GenuineIntel", Family: "6", Model: "78", Stepping: 3, PhysicalID: "0", CoreID: "0", Cores: 1, ModelName: "Intel(r) Core(tm) i7-6567U CPU @ 3.30GHz", Mhz.current: 3312}, }, }, { "2cpu_1core_psrinfo.txt", []InfoStat{ - {CPU: 0, VendorID: "GenuineIntel", Family: "6", Model: "78", Stepping: 3, PhysicalID: "0", CoreID: "0", Cores: 1, ModelName: "Intel(r) Core(tm) i7-6567U CPU @ 3.30GHz", Mhz: 3312}, - {CPU: 1, VendorID: "GenuineIntel", Family: "6", Model: "78", Stepping: 3, PhysicalID: "1", CoreID: "0", Cores: 1, ModelName: "Intel(r) Core(tm) i7-6567U CPU @ 3.30GHz", Mhz: 3312}, + {CPU: 0, VendorID: "GenuineIntel", Family: "6", Model: "78", Stepping: 3, PhysicalID: "0", CoreID: "0", Cores: 1, ModelName: "Intel(r) Core(tm) i7-6567U CPU @ 3.30GHz", Mhz.current: 3312}, + {CPU: 1, VendorID: "GenuineIntel", Family: "6", Model: "78", Stepping: 3, PhysicalID: "1", CoreID: "0", Cores: 1, ModelName: "Intel(r) Core(tm) i7-6567U CPU @ 3.30GHz", Mhz.current: 3312}, }, }, { "2cpu_8core_psrinfo.txt", []InfoStat{ - {CPU: 0, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "0", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 1, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "1", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 2, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "2", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 3, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "3", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 4, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "4", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 5, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "5", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 6, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "6", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 7, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "7", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 8, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "0", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 9, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "1", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 10, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "2", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 11, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "3", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 12, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "4", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 13, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "5", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 14, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "6", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, - {CPU: 15, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "7", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz: 2600}, + {CPU: 0, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "0", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 1, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "1", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 2, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "2", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 3, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "3", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 4, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "4", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 5, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "5", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 6, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "6", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 7, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "0", CoreID: "7", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 8, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "0", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 9, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "1", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 10, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "2", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 11, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "3", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 12, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "4", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 13, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "5", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 14, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "6", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, + {CPU: 15, VendorID: "GenuineIntel", Family: "6", Model: "45", Stepping: 7, PhysicalID: "1", CoreID: "7", Cores: 2, ModelName: "Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz", Mhz.current: 2600}, }, }, { "2cpu_12core_psrinfo.txt", []InfoStat{ - {CPU: 0, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "0", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 1, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "1", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 2, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "2", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 3, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "3", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 4, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "4", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 5, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "5", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 6, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "6", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 7, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "7", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 8, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "8", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 9, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "9", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 10, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "10", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 11, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "11", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 12, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "0", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 13, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "1", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 14, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "2", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 15, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "3", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 16, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "4", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 17, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "5", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 18, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "6", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 19, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "7", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 20, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "8", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 21, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "9", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 22, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "10", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, - {CPU: 23, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "11", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz: 2300}, + {CPU: 0, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "0", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 1, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "1", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 2, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "2", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 3, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "3", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 4, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "4", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 5, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "5", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 6, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "6", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 7, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "7", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 8, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "8", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 9, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "9", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 10, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "10", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 11, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "0", CoreID: "11", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 12, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "0", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 13, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "1", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 14, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "2", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 15, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "3", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 16, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "4", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 17, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "5", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 18, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "6", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 19, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "7", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 20, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "8", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 21, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "9", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 22, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "10", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, + {CPU: 23, VendorID: "AuthenticAMD", Family: "16", Model: "9", Stepping: 1, PhysicalID: "1", CoreID: "11", Cores: 1, ModelName: "AMD Opteron(tm) Processor 6176\t[ Socket: G34 ]", Mhz.current: 2300}, }, }, } diff --git a/cpu/cpu_windows.go b/cpu/cpu_windows.go index e10612f..6e48be8 100644 --- a/cpu/cpu_windows.go +++ b/cpu/cpu_windows.go @@ -9,7 +9,6 @@ import ( "unsafe" "github.com/shirou/gopsutil/v3/internal/common" - "github.com/yusufpapurcu/wmi" "golang.org/x/sys/windows" ) @@ -117,8 +116,12 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { ModelName: l.Name, Cores: int32(l.NumberOfLogicalProcessors), PhysicalID: procID, - Mhz: float64(l.MaxClockSpeed), - Flags: []string{}, + Mhz: Mhz{ + current: float64(l.MaxClockSpeed), + max: float64(l.MaxClockSpeed), + min: 0, + }, + Flags: []string{}, } ret = append(ret, cpu) }