2022-02-15 06:44:27 +08:00
|
|
|
//go:build linux
|
2020-06-27 00:50:15 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package devices
|
|
|
|
|
2024-09-13 15:08:35 +08:00
|
|
|
import "github.com/shirou/gopsutil/v3/cpu"
|
2020-06-27 00:50:15 +08:00
|
|
|
|
|
|
|
func CpuCount() (int, error) {
|
|
|
|
cpuCount, err := cpu.Counts(false)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if cpuCount == 0 {
|
|
|
|
is, err := cpu.Info()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if is[0].Cores > 0 {
|
|
|
|
return len(is) / 2, nil
|
|
|
|
}
|
|
|
|
return len(is), nil
|
|
|
|
}
|
|
|
|
return cpuCount, nil
|
|
|
|
}
|