From c0de2a8aff610c161331eb653601edf0c3c7d4e7 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:17:54 +0800 Subject: [PATCH] fix(cpu): detect number of cores correctly on all platform (#97) --- pkg/monitor/cpu/cpu.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pkg/monitor/cpu/cpu.go b/pkg/monitor/cpu/cpu.go index 8435538..accb6ea 100644 --- a/pkg/monitor/cpu/cpu.go +++ b/pkg/monitor/cpu/cpu.go @@ -19,7 +19,7 @@ func GetHost(ctx context.Context) ([]string, error) { cpuModelCount := make(map[string]int) for _, c := range ci { - cpuModelCount[c.ModelName]++ + cpuModelCount[c.ModelName] += int(c.Cores) } var cpuType string @@ -27,14 +27,9 @@ func GetHost(ctx context.Context) ([]string, error) { cpuType = t } - var ch []string - u := len(ci) > 1 + ch := make([]string, 0, len(cpuModelCount)) for model, count := range cpuModelCount { - if u { - ch = append(ch, fmt.Sprintf("%s %d %s Core", model, count, cpuType)) - } else { - ch = append(ch, fmt.Sprintf("%s %d %s Core", model, ci[0].Cores, cpuType)) - } + ch = append(ch, fmt.Sprintf("%s %d %s Core", model, count, cpuType)) } return ch, nil