mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-27 23:59:05 +01:00
Fix function getNumaDomain, it always returned 0
This commit is contained in:
parent
6a2b74b0dc
commit
4b16ca4a30
@ -218,69 +218,54 @@ type HwthreadEntry struct {
|
|||||||
|
|
||||||
func CpuData() []HwthreadEntry {
|
func CpuData() []HwthreadEntry {
|
||||||
|
|
||||||
// fileToInt := func(path string) int {
|
getCore :=
|
||||||
// buffer, err := os.ReadFile(path)
|
func(basePath string) int {
|
||||||
// if err != nil {
|
return fileToInt(fmt.Sprintf("%s/core_id", basePath))
|
||||||
// log.Print(err)
|
|
||||||
// //cclogger.ComponentError("ccTopology", "Reading", path, ":", err.Error())
|
|
||||||
// return -1
|
|
||||||
// }
|
|
||||||
// sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
// var id int64
|
|
||||||
// //_, err = fmt.Scanf("%d", sbuffer, &id)
|
|
||||||
// id, err = strconv.ParseInt(sbuffer, 10, 32)
|
|
||||||
// if err != nil {
|
|
||||||
// cclogger.ComponentError("ccTopology", "Parsing", path, ":", sbuffer, err.Error())
|
|
||||||
// return -1
|
|
||||||
// }
|
|
||||||
// return int(id)
|
|
||||||
// }
|
|
||||||
getCore := func(basepath string) int {
|
|
||||||
return fileToInt(fmt.Sprintf("%s/core_id", basepath))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSocket := func(basepath string) int {
|
getSocket :=
|
||||||
return fileToInt(fmt.Sprintf("%s/physical_package_id", basepath))
|
func(basePath string) int {
|
||||||
|
return fileToInt(fmt.Sprintf("%s/physical_package_id", basePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
getDie := func(basepath string) int {
|
getDie :=
|
||||||
return fileToInt(fmt.Sprintf("%s/die_id", basepath))
|
func(basePath string) int {
|
||||||
|
return fileToInt(fmt.Sprintf("%s/die_id", basePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
getSMT := func(cpuid int, basepath string) int {
|
getSMT :=
|
||||||
buffer, err := os.ReadFile(fmt.Sprintf("%s/thread_siblings_list", basepath))
|
func(cpuID int, basePath string) int {
|
||||||
|
buffer, err := os.ReadFile(fmt.Sprintf("%s/thread_siblings_list", basePath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
||||||
}
|
}
|
||||||
threadlist := make([]int, 0)
|
threadList := make([]int, 0)
|
||||||
sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
stringBuffer := strings.TrimSpace(string(buffer))
|
||||||
for _, x := range strings.Split(sbuffer, ",") {
|
for _, x := range strings.Split(stringBuffer, ",") {
|
||||||
id, err := strconv.ParseInt(x, 10, 32)
|
id, err := strconv.ParseInt(x, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
||||||
}
|
}
|
||||||
threadlist = append(threadlist, int(id))
|
threadList = append(threadList, int(id))
|
||||||
}
|
}
|
||||||
for i, x := range threadlist {
|
if i := slices.Index(threadList, cpuID); i != -1 {
|
||||||
if x == cpuid {
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
getNumaDomain := func(basepath string) int {
|
getNumaDomain :=
|
||||||
globPath := filepath.Join(basepath, "node*")
|
func(basePath string) int {
|
||||||
regexPath := filepath.Join(basepath, "node(\\d+)")
|
globPath := filepath.Join(basePath, "node*")
|
||||||
|
regexPath := filepath.Join(basePath, "node([[:digit:]]+)")
|
||||||
regex := regexp.MustCompile(regexPath)
|
regex := regexp.MustCompile(regexPath)
|
||||||
files, err := filepath.Glob(globPath)
|
files, err := filepath.Glob(globPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getNumaDomain", err.Error())
|
cclogger.ComponentError("CCTopology", "CpuData:getNumaDomain", err.Error())
|
||||||
}
|
}
|
||||||
for _, f := range files {
|
for _, file := range files {
|
||||||
finfo, err := os.Lstat(f)
|
matches := regex.FindStringSubmatch(file)
|
||||||
if err == nil && finfo.IsDir() {
|
fmt.Println(len(matches))
|
||||||
matches := regex.FindStringSubmatch(f)
|
|
||||||
if len(matches) == 2 {
|
if len(matches) == 2 {
|
||||||
id, err := strconv.Atoi(matches[1])
|
id, err := strconv.Atoi(matches[1])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -288,46 +273,47 @@ func CpuData() []HwthreadEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
clist := make([]HwthreadEntry, 0)
|
cList := make([]HwthreadEntry, 0)
|
||||||
for _, c := range HwthreadList() {
|
for _, c := range HwthreadList() {
|
||||||
clist = append(clist, HwthreadEntry{CpuID: c})
|
cList = append(cList,
|
||||||
|
HwthreadEntry{
|
||||||
|
CpuID: c,
|
||||||
|
Socket: -1,
|
||||||
|
NumaDomain: -1,
|
||||||
|
Die: -1,
|
||||||
|
Core: -1,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for i, centry := range clist {
|
for i := range cList {
|
||||||
centry.Socket = -1
|
cEntry := &cList[i]
|
||||||
centry.NumaDomain = -1
|
|
||||||
centry.Die = -1
|
|
||||||
centry.Core = -1
|
|
||||||
// Set base directory for topology lookup
|
// Set base directory for topology lookup
|
||||||
cpustr := fmt.Sprintf("cpu%d", centry.CpuID)
|
cpuStr := fmt.Sprintf("cpu%d", cEntry.CpuID)
|
||||||
base := filepath.Join("/sys/devices/system/cpu", cpustr)
|
base := filepath.Join("/sys/devices/system/cpu", cpuStr)
|
||||||
topoBase := filepath.Join(base, "topology")
|
topoBase := filepath.Join(base, "topology")
|
||||||
|
|
||||||
// Lookup CPU core id
|
// Lookup CPU core id
|
||||||
centry.Core = getCore(topoBase)
|
cEntry.Core = getCore(topoBase)
|
||||||
|
|
||||||
// Lookup CPU socket id
|
// Lookup CPU socket id
|
||||||
centry.Socket = getSocket(topoBase)
|
cEntry.Socket = getSocket(topoBase)
|
||||||
|
|
||||||
// Lookup CPU die id
|
// Lookup CPU die id
|
||||||
centry.Die = getDie(topoBase)
|
cEntry.Die = getDie(topoBase)
|
||||||
if centry.Die < 0 {
|
if cEntry.Die < 0 {
|
||||||
centry.Die = centry.Socket
|
cEntry.Die = cEntry.Socket
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup SMT thread id
|
// Lookup SMT thread id
|
||||||
centry.SMT = getSMT(centry.CpuID, topoBase)
|
cEntry.SMT = getSMT(cEntry.CpuID, topoBase)
|
||||||
|
|
||||||
// Lookup NUMA domain id
|
// Lookup NUMA domain id
|
||||||
centry.NumaDomain = getNumaDomain(base)
|
cEntry.NumaDomain = getNumaDomain(base)
|
||||||
|
|
||||||
// Update values in output list
|
|
||||||
clist[i] = centry
|
|
||||||
}
|
}
|
||||||
return clist
|
return cList
|
||||||
}
|
}
|
||||||
|
|
||||||
// Structure holding basic information about a CPU
|
// Structure holding basic information about a CPU
|
||||||
|
Loading…
Reference in New Issue
Block a user