in internal/system/resources.go [117:178]
func getCoresInfo(cpuDirs []string) ([]core, error) {
cores := make([]core, 0, len(cpuDirs))
for _, cpuDir := range cpuDirs {
cpuID, err := getCPUID(cpuDir)
if err != nil {
return nil, fmt.Errorf("unexpected format of CPU directory, cpuDirRegExp %s, cpuDir: %s", cpuDirRegExp, cpuDir)
}
if !IsCPUOnline(cpuID) {
continue
}
rawPhysicalID, err := getCoreID(cpuDir)
if os.IsNotExist(err) {
zap.L().Warn("Cannot read core id for input cpuDir, core_id file does not exist",
zap.String("cpuDir", cpuDir), zap.Error(err))
continue
} else if err != nil {
return nil, err
}
physicalID, err := strconv.Atoi(rawPhysicalID)
if err != nil {
return nil, err
}
rawPhysicalPackageID, err := getCPUPhysicalPackageID(cpuDir)
if os.IsNotExist(err) {
zap.L().Warn("Cannot read physical package id for input cpuDir, physical_package_id file does not exist",
zap.String("cpuDir", cpuDir), zap.Error(err))
continue
} else if err != nil {
return nil, err
}
physicalPackageID, err := strconv.Atoi(rawPhysicalPackageID)
if err != nil {
return nil, err
}
coreIDx := -1
for id, core := range cores {
if core.Id == physicalID && core.SocketID == physicalPackageID {
coreIDx = id
}
}
if coreIDx == -1 {
cores = append(cores, core{})
coreIDx = len(cores) - 1
}
desiredCore := &cores[coreIDx]
desiredCore.Id = physicalID
desiredCore.SocketID = physicalPackageID
if len(desiredCore.Threads) == 0 {
desiredCore.Threads = []int{cpuID}
} else {
desiredCore.Threads = append(desiredCore.Threads, cpuID)
}
}
return cores, nil
}