From 200e5fbeab49ce5543ef0ddc314ba5b6b772a733 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Wed, 6 Mar 2019 19:41:26 +0100 Subject: [PATCH] [cpu][linux] Remove regexp in Counts Also remove some remaining debug print and unnecessary strings.Split --- cpu/cpu_linux.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index ee1dcd6..dc89c79 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "os/exec" - "regexp" "strconv" "strings" @@ -304,10 +303,8 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) { if err != nil { return 0, err } - re := regexp.MustCompile(`cpu\d`) for _, line := range lines { - line = strings.Split(line, " ")[0] - if re.MatchString(line) { + if len(line) >= 4 && strings.HasPrefix(line, "cpu") && '0' <= line[3] && line[3] <= '9' { // `^cpu\d` regexp matching ret++ } } @@ -342,7 +339,6 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) { if fields[0] == "physical id" || fields[0] == "cpu cores" { val, err := strconv.Atoi(strings.TrimSpace(fields[1])) if err != nil { - fmt.Println(err) continue } currentInfo[fields[0]] = val