Merge pull request #650 from mznet/physical-cpu-darwin

[Darwin][CPU] retrieve a cpu count depends on an boolean argument
pull/659/head
shirou 6 years ago committed by GitHub
commit e1d4d987e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,7 +4,6 @@ package cpu
import (
"context"
"runtime"
"strconv"
"strings"
@ -88,5 +87,17 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
}
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
return runtime.NumCPU(), nil
var cpuArgument string
if logical {
cpuArgument = "hw.logicalcpu"
} else {
cpuArgument = "hw.physicalcpu"
}
count, err := unix.SysctlUint32(cpuArgument)
if err != nil {
return 0, err
}
return int(count), nil
}

Loading…
Cancel
Save