mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 12:37:25 +01:00
Avoid slice cloning. Directly use the cache
This commit is contained in:
parent
1f5856c671
commit
094f124a18
@ -31,13 +31,16 @@ type HwthreadEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cache struct {
|
var cache struct {
|
||||||
SocketList []int
|
|
||||||
uniqSocketList []int
|
|
||||||
HwthreadList []int
|
HwthreadList []int
|
||||||
uniqHwthreadList []int
|
uniqHwthreadList []int
|
||||||
CoreList []int
|
|
||||||
uniqCoreList []int
|
CoreList []int
|
||||||
CpuData []HwthreadEntry
|
uniqCoreList []int
|
||||||
|
|
||||||
|
SocketList []int
|
||||||
|
uniqSocketList []int
|
||||||
|
|
||||||
|
CpuData []HwthreadEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -304,14 +307,11 @@ type CpuInformation struct {
|
|||||||
// CpuInformation reports basic information about the CPU
|
// CpuInformation reports basic information about the CPU
|
||||||
func CpuInfo() CpuInformation {
|
func CpuInfo() CpuInformation {
|
||||||
|
|
||||||
cpuData := CpuData()
|
|
||||||
smtList := make([]int, 0)
|
smtList := make([]int, 0)
|
||||||
numaList := make([]int, 0)
|
numaList := make([]int, 0)
|
||||||
dieList := make([]int, 0)
|
dieList := make([]int, 0)
|
||||||
socketList := make([]int, 0)
|
for i := range cache.CpuData {
|
||||||
coreList := make([]int, 0)
|
d := &cache.CpuData[i]
|
||||||
for i := range cpuData {
|
|
||||||
d := &cpuData[i]
|
|
||||||
if ok := slices.Contains(smtList, d.SMT); !ok {
|
if ok := slices.Contains(smtList, d.SMT); !ok {
|
||||||
smtList = append(smtList, d.SMT)
|
smtList = append(smtList, d.SMT)
|
||||||
}
|
}
|
||||||
@ -321,29 +321,22 @@ func CpuInfo() CpuInformation {
|
|||||||
if ok := slices.Contains(dieList, d.Die); !ok {
|
if ok := slices.Contains(dieList, d.Die); !ok {
|
||||||
dieList = append(dieList, d.Die)
|
dieList = append(dieList, d.Die)
|
||||||
}
|
}
|
||||||
if ok := slices.Contains(socketList, d.Socket); !ok {
|
|
||||||
socketList = append(socketList, d.Socket)
|
|
||||||
}
|
|
||||||
if ok := slices.Contains(coreList, d.Core); !ok {
|
|
||||||
coreList = append(coreList, d.Core)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return CpuInformation{
|
return CpuInformation{
|
||||||
NumNumaDomains: len(numaList),
|
NumNumaDomains: len(numaList),
|
||||||
SMTWidth: len(smtList),
|
SMTWidth: len(smtList),
|
||||||
NumDies: len(dieList),
|
NumDies: len(dieList),
|
||||||
NumCores: len(coreList),
|
NumCores: len(cache.uniqCoreList),
|
||||||
NumSockets: len(socketList),
|
NumSockets: len(cache.uniqSocketList),
|
||||||
NumHWthreads: len(cpuData),
|
NumHWthreads: len(cache.uniqHwthreadList),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHwthreadSocket gets the CPU socket ID for a given hardware thread ID
|
// GetHwthreadSocket gets the CPU socket ID for a given hardware thread ID
|
||||||
// In case hardware thread ID is not found -1 is returned
|
// In case hardware thread ID is not found -1 is returned
|
||||||
func GetHwthreadSocket(cpuID int) int {
|
func GetHwthreadSocket(cpuID int) int {
|
||||||
cpuData := CpuData()
|
for i := range cache.CpuData {
|
||||||
for i := range cpuData {
|
d := &cache.CpuData[i]
|
||||||
d := &cpuData[i]
|
|
||||||
if d.CpuID == cpuID {
|
if d.CpuID == cpuID {
|
||||||
return d.Socket
|
return d.Socket
|
||||||
}
|
}
|
||||||
@ -354,9 +347,8 @@ func GetHwthreadSocket(cpuID int) int {
|
|||||||
// GetHwthreadNumaDomain gets the NUMA domain ID for a given hardware thread ID
|
// GetHwthreadNumaDomain gets the NUMA domain ID for a given hardware thread ID
|
||||||
// In case hardware thread ID is not found -1 is returned
|
// In case hardware thread ID is not found -1 is returned
|
||||||
func GetHwthreadNumaDomain(cpuID int) int {
|
func GetHwthreadNumaDomain(cpuID int) int {
|
||||||
cpuData := CpuData()
|
for i := range cache.CpuData {
|
||||||
for i := range cpuData {
|
d := &cache.CpuData[i]
|
||||||
d := &cpuData[i]
|
|
||||||
if d.CpuID == cpuID {
|
if d.CpuID == cpuID {
|
||||||
return d.NumaDomain
|
return d.NumaDomain
|
||||||
}
|
}
|
||||||
@ -367,9 +359,8 @@ func GetHwthreadNumaDomain(cpuID int) int {
|
|||||||
// GetHwthreadDie gets the CPU die ID for a given hardware thread ID
|
// GetHwthreadDie gets the CPU die ID for a given hardware thread ID
|
||||||
// In case hardware thread ID is not found -1 is returned
|
// In case hardware thread ID is not found -1 is returned
|
||||||
func GetHwthreadDie(cpuID int) int {
|
func GetHwthreadDie(cpuID int) int {
|
||||||
cpuData := CpuData()
|
for i := range cache.CpuData {
|
||||||
for i := range cpuData {
|
d := &cache.CpuData[i]
|
||||||
d := &cpuData[i]
|
|
||||||
if d.CpuID == cpuID {
|
if d.CpuID == cpuID {
|
||||||
return d.Die
|
return d.Die
|
||||||
}
|
}
|
||||||
@ -380,9 +371,8 @@ func GetHwthreadDie(cpuID int) int {
|
|||||||
// GetHwthreadCore gets the CPU core ID for a given hardware thread ID
|
// GetHwthreadCore gets the CPU core ID for a given hardware thread ID
|
||||||
// In case hardware thread ID is not found -1 is returned
|
// In case hardware thread ID is not found -1 is returned
|
||||||
func GetHwthreadCore(cpuID int) int {
|
func GetHwthreadCore(cpuID int) int {
|
||||||
cpuData := CpuData()
|
for i := range cache.CpuData {
|
||||||
for i := range cpuData {
|
d := &cache.CpuData[i]
|
||||||
d := &cpuData[i]
|
|
||||||
if d.CpuID == cpuID {
|
if d.CpuID == cpuID {
|
||||||
return d.Core
|
return d.Core
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user