From d551997afb1a5b4fdd2a4697423690f3d3453588 Mon Sep 17 00:00:00 2001 From: Dylan Myers Date: Wed, 15 May 2024 22:07:56 -0400 Subject: [PATCH] Fix typos and code misplacement in AIX CPU handling --- cpu/cpu_aix_nocgo.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpu/cpu_aix_nocgo.go b/cpu/cpu_aix_nocgo.go index 5f4bc49..9796cf5 100644 --- a/cpu/cpu_aix_nocgo.go +++ b/cpu/cpu_aix_nocgo.go @@ -25,6 +25,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { hp := strings.Fields(lines[5]) // headers for l := 6; l < len(lines)-1; l++ { + ct := &TimesStat{} v := strings.Fields(lines[l]) // values for i, header := range hp { // We're done in any of these use cases @@ -43,8 +44,8 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { if pos < 0 { continue } - ct := &TimesStat{} - if t, err := strconv.ParseFloat(v[i], 64); err == nil { + + if t, err := strconv.ParseFloat(v[pos], 64); err == nil { switch header { case `cpu`: ct.CPU = t @@ -58,10 +59,9 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { ct.Idle = t } } - - // Valid CPU data, so append it - ret = append(ret, *ct) } + // Valid CPU data, so append it + ret = append(ret, *ct) } } else { out, err := invoke.CommandWithContext(ctx, "sar", "-u", "10", "1")