Skip to content

Commit

Permalink
v0.0.9 - 在实在找不到型号的时候,直接输出CPU制造的厂商
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Feb 5, 2025
1 parent fd7d982 commit 255481f
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions system/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ func getCpuInfoFromLscpu(ret *model.SystemInfo) {
L3cache = value
}
}
// 在实在找不到型号的时候,直接输出CPU制造的厂商
if strings.Contains(ret.CpuModel, "@") && len(ret.CpuModel[:strings.Index(ret.CpuModel, "@")]) < 3 {
for _, line := range lines {
fields := strings.Split(line, ":")
if len(fields) < 2 {
continue
}
if strings.Contains(fields[0], "Vendor ID") {
newModel := strings.TrimSpace(strings.Join(fields[1:], " "))
if strings.Contains(ret.CpuModel, "@") && len(ret.CpuModel[:strings.Index(ret.CpuModel, "@")]) < len(newModel) {
freqPart := ret.CpuModel[strings.Index(ret.CpuModel, "@"):]
ret.CpuModel = newModel + " " + freqPart
} else {
ret.CpuModel = newModel
}
}
}
}
updateCpuCache(ret, L1dcache, L1icache, L2cache, L3cache)
}

Expand Down Expand Up @@ -229,14 +247,12 @@ func getLinuxCpuInfo(ret *model.SystemInfo) (*model.SystemInfo, error) {
ci, err := cpu.Info()
if err == nil {
for i := 0; i < len(ci); i++ {
if len(ret.CpuModel) < len(ci[i].ModelName) {
newModel := strings.TrimSpace(ci[i].ModelName)
if strings.Contains(ret.CpuModel, "@") {
freqPart := ret.CpuModel[strings.Index(ret.CpuModel, "@"):]
ret.CpuModel = newModel + " " + freqPart
} else {
ret.CpuModel = newModel
}
newModel := strings.TrimSpace(ci[i].ModelName)
if strings.Contains(ret.CpuModel, "@") && len(ret.CpuModel[:strings.Index(ret.CpuModel, "@")]) < len(ci[i].ModelName) {
freqPart := ret.CpuModel[strings.Index(ret.CpuModel, "@"):]
ret.CpuModel = newModel + " " + freqPart
} else {
ret.CpuModel = newModel
}
}
}
Expand Down

0 comments on commit 255481f

Please sign in to comment.