Skip to content

Commit ffd5609

Browse files
committed
fix GetCpuInfo/TestOS_Darwin_GetCpuInfo
1 parent 134673c commit ffd5609

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

os_darwin.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ func (ko *LkkOS) GetCpuInfo() *CpuInfo {
174174
Threads: 0,
175175
}
176176

177-
//打印CPU信息
178-
_, cpuInfos, _ := ko.System("sysctl machdep.cpu")
179-
println("cpuInfos: ", cpuInfos)
180-
181177
//调用系统命令获取,例如
182178
//$ sysctl machdep.cpu
183179
//machdep.cpu.cores_per_package: 10
@@ -189,25 +185,18 @@ func (ko *LkkOS) GetCpuInfo() *CpuInfo {
189185
//machdep.cpu.feature_bits: 151121000215084031
190186
//machdep.cpu.family: 6
191187

188+
//打印CPU信息
189+
//cpuInfos, _ := unix.Sysctl("machdep.cpu")
190+
//println("cpuInfos: ", cpuInfos)
191+
192192
res.Model, _ = unix.Sysctl("machdep.cpu.brand_string")
193-
res.Vendor, _ = unix.Sysctl("machdep.cpu.vendor")
193+
res.Vendor, _ = unix.Sysctl("machdep.cpu.vendor") //有可能为空
194194

195-
cacheSize, _ := unix.SysctlUint32("machdep.cpu.cache.size")
195+
cacheSize, _ := unix.SysctlUint32("machdep.cpu.cache.size") //有可能为空
196196
cpus, _ := unix.SysctlUint32("hw.physicalcpu")
197197
cores, _ := unix.SysctlUint32("machdep.cpu.core_count")
198198
threads, _ := unix.SysctlUint32("machdep.cpu.thread_count")
199199

200-
if cpus == 0 {
201-
infos := ko.getIOInfos()
202-
if len(infos) > 0 {
203-
infoStr := string(infos)
204-
tmpStr := trim(KStr.GetEquationValue(infoStr, "AppleARMCPU"), "<", ">", `"`, `'`)
205-
if tmpStr != "" {
206-
cpus = uint32(KConv.ToInt(tmpStr))
207-
}
208-
}
209-
}
210-
211200
res.Cache = uint(cacheSize)
212201
res.Cpus = uint(cpus)
213202
res.Cores = uint(cores)

os_darwin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func TestOS_Darwin_GetCpuInfo(t *testing.T) {
101101
res := KOS.GetCpuInfo()
102102
KDbug.DumpPrint(res)
103103
assert.NotNil(t, res)
104-
assert.NotEmpty(t, res.Vendor)
105104
assert.NotEmpty(t, res.Model)
105+
assert.NotEmpty(t, res.Threads)
106106
}
107107

108108
func BenchmarkOS_Darwin_GetCpuInfo(b *testing.B) {

0 commit comments

Comments
 (0)