mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-27 07:39:05 +01:00
Cache CpuData
This commit is contained in:
parent
3ac1ada204
commit
5fa53a7ab8
@ -20,10 +20,21 @@ const (
|
|||||||
PROCFS_CPUINFO = `/proc/cpuinfo`
|
PROCFS_CPUINFO = `/proc/cpuinfo`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Structure holding all information about a hardware thread
|
||||||
|
type HwthreadEntry struct {
|
||||||
|
CpuID int
|
||||||
|
SMT int
|
||||||
|
Core int
|
||||||
|
Socket int
|
||||||
|
NumaDomain int
|
||||||
|
Die int
|
||||||
|
}
|
||||||
|
|
||||||
var cache struct {
|
var cache struct {
|
||||||
SocketList []int
|
SocketList []int
|
||||||
HwthreadList []int
|
HwthreadList []int
|
||||||
CoreList []int
|
CoreList []int
|
||||||
|
CpuData []HwthreadEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
// fileToInt reads an integer value from a file
|
// fileToInt reads an integer value from a file
|
||||||
@ -78,7 +89,6 @@ func initSocketHwthreadCoreList() {
|
|||||||
if found := slices.Contains(cache.HwthreadList, id); !found {
|
if found := slices.Contains(cache.HwthreadList, id); !found {
|
||||||
cache.HwthreadList = append(cache.HwthreadList, id)
|
cache.HwthreadList = append(cache.HwthreadList, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "core id":
|
case "core id":
|
||||||
id, err := strconv.Atoi(value)
|
id, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -153,7 +163,6 @@ func NumaNodeList() []int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return numaList
|
return numaList
|
||||||
}
|
}
|
||||||
@ -199,36 +208,26 @@ func GetTypeList(topology_type string) []int {
|
|||||||
return []int{}
|
return []int{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Structure holding all information about a hardware thread
|
func initCpuData() {
|
||||||
type HwthreadEntry struct {
|
|
||||||
CpuID int
|
|
||||||
SMT int
|
|
||||||
Core int
|
|
||||||
Socket int
|
|
||||||
NumaDomain int
|
|
||||||
Die int
|
|
||||||
}
|
|
||||||
|
|
||||||
func CpuData() []HwthreadEntry {
|
|
||||||
|
|
||||||
getCore :=
|
getCore :=
|
||||||
func(basePath string) int {
|
func(basePath string) int {
|
||||||
return fileToInt(fmt.Sprintf("%s/core_id", basePath))
|
return fileToInt(filepath.Join(basePath, "core_id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
getSocket :=
|
getSocket :=
|
||||||
func(basePath string) int {
|
func(basePath string) int {
|
||||||
return fileToInt(fmt.Sprintf("%s/physical_package_id", basePath))
|
return fileToInt(filepath.Join(basePath, "physical_package_id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
getDie :=
|
getDie :=
|
||||||
func(basePath string) int {
|
func(basePath string) int {
|
||||||
return fileToInt(fmt.Sprintf("%s/die_id", basePath))
|
return fileToInt(filepath.Join(basePath, "die_id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
getSMT :=
|
getSMT :=
|
||||||
func(cpuID int, basePath string) int {
|
func(cpuID int, basePath string) int {
|
||||||
buffer, err := os.ReadFile(fmt.Sprintf("%s/thread_siblings_list", basePath))
|
buffer, err := os.ReadFile(filepath.Join(basePath, "thread_siblings_list"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
||||||
}
|
}
|
||||||
@ -268,9 +267,8 @@ func CpuData() []HwthreadEntry {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
cList := make([]HwthreadEntry, 0)
|
|
||||||
for _, c := range HwthreadList() {
|
for _, c := range HwthreadList() {
|
||||||
cList = append(cList,
|
cache.CpuData = append(cache.CpuData,
|
||||||
HwthreadEntry{
|
HwthreadEntry{
|
||||||
CpuID: c,
|
CpuID: c,
|
||||||
Socket: -1,
|
Socket: -1,
|
||||||
@ -279,8 +277,8 @@ func CpuData() []HwthreadEntry {
|
|||||||
Core: -1,
|
Core: -1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for i := range cList {
|
for i := range cache.CpuData {
|
||||||
cEntry := &cList[i]
|
cEntry := &cache.CpuData[i]
|
||||||
|
|
||||||
// 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)
|
||||||
@ -305,7 +303,13 @@ func CpuData() []HwthreadEntry {
|
|||||||
// Lookup NUMA domain id
|
// Lookup NUMA domain id
|
||||||
cEntry.NumaDomain = getNumaDomain(base)
|
cEntry.NumaDomain = getNumaDomain(base)
|
||||||
}
|
}
|
||||||
return cList
|
}
|
||||||
|
|
||||||
|
func CpuData() []HwthreadEntry {
|
||||||
|
if cache.CpuData == nil {
|
||||||
|
initCpuData()
|
||||||
|
}
|
||||||
|
return slices.Clone(cache.CpuData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Structure holding basic information about a CPU
|
// Structure holding basic information about a CPU
|
||||||
|
Loading…
Reference in New Issue
Block a user