|
|
@ -7,7 +7,6 @@ import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"os/exec"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
@ -304,10 +303,8 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
re := regexp.MustCompile(`cpu\d`)
|
|
|
|
|
|
|
|
for _, line := range lines {
|
|
|
|
for _, line := range lines {
|
|
|
|
line = strings.Split(line, " ")[0]
|
|
|
|
if len(line) >= 4 && strings.HasPrefix(line, "cpu") && '0' <= line[3] && line[3] <= '9' { // `^cpu\d` regexp matching
|
|
|
|
if re.MatchString(line) {
|
|
|
|
|
|
|
|
ret++
|
|
|
|
ret++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -342,7 +339,6 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
|
|
|
|
if fields[0] == "physical id" || fields[0] == "cpu cores" {
|
|
|
|
if fields[0] == "physical id" || fields[0] == "cpu cores" {
|
|
|
|
val, err := strconv.Atoi(strings.TrimSpace(fields[1]))
|
|
|
|
val, err := strconv.Atoi(strings.TrimSpace(fields[1]))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentInfo[fields[0]] = val
|
|
|
|
currentInfo[fields[0]] = val
|
|
|
|