Refactoring

This commit is contained in:
Holger Obermaier 2022-01-24 22:03:13 +01:00
parent 9157fdbab2
commit 3d377760b8

View File

@ -36,10 +36,10 @@ type CPUFreqCollectorTopology struct {
processor string // logical processor number (continuous, starting at 0) processor string // logical processor number (continuous, starting at 0)
coreID string // socket local core ID coreID string // socket local core ID
coreID_int int coreID_int int
physicalID string // socket / package ID physicalPackageID string // socket / package ID
physicalID_int int physicalPackageID_int int
numPhysicalID string // number of sockets / packages numPhysicalPackages string // number of sockets / packages
numPhysicalID_int int numPhysicalPackages_int int
isHT bool isHT bool
numNonHT string // number of non hyperthreading processors numNonHT string // number of non hyperthreading processors
numNonHT_int int numNonHT_int int
@ -94,12 +94,12 @@ func (m *CPUFreqCollector) Init(config []byte) error {
} }
// Read package ID // Read package ID
packageIDFile := filepath.Join(cpuDir, "topology", "physical_package_id") physicalPackageIDFile := filepath.Join(cpuDir, "topology", "physical_package_id")
packageID, ok := readOneLine(packageIDFile) physicalPackageID, ok := readOneLine(physicalPackageIDFile)
if !ok { if !ok {
return fmt.Errorf("CPUFreqCollector.Init() unable to read physical package ID from %s", packageIDFile) return fmt.Errorf("CPUFreqCollector.Init() unable to read physical package ID from %s", physicalPackageIDFile)
} }
packageID_int, err := strconv.Atoi(packageID) physicalPackageID_int, err := strconv.Atoi(physicalPackageID)
if err != nil { if err != nil {
return fmt.Errorf("CPUFreqCollector.Init() unable to convert packageID to int: %v", err) return fmt.Errorf("CPUFreqCollector.Init() unable to convert packageID to int: %v", err)
} }
@ -124,8 +124,8 @@ func (m *CPUFreqCollector) Init(config []byte) error {
t := &m.topology[processor_int] t := &m.topology[processor_int]
t.processor = processor t.processor = processor
t.physicalID = packageID t.physicalPackageID = physicalPackageID
t.physicalID_int = packageID_int t.physicalPackageID_int = physicalPackageID_int
t.coreID = coreID t.coreID = coreID
t.coreID_int = coreID_int t.coreID_int = coreID_int
t.scalingCurFreqFile = scalingCurFreqFile t.scalingCurFreqFile = scalingCurFreqFile
@ -136,7 +136,7 @@ func (m *CPUFreqCollector) Init(config []byte) error {
for i := range m.topology { for i := range m.topology {
t := &m.topology[i] t := &m.topology[i]
globalID := t.physicalID + ":" + t.coreID globalID := t.physicalPackageID + ":" + t.coreID
t.isHT = coreSeenBefore[globalID] t.isHT = coreSeenBefore[globalID]
coreSeenBefore[globalID] = true coreSeenBefore[globalID] = true
} }
@ -148,8 +148,8 @@ func (m *CPUFreqCollector) Init(config []byte) error {
t := &m.topology[i] t := &m.topology[i]
// Update maxPackageID // Update maxPackageID
if t.physicalID_int > maxPhysicalID { if t.physicalPackageID_int > maxPhysicalID {
maxPhysicalID = t.physicalID_int maxPhysicalID = t.physicalPackageID_int
} }
if !t.isHT { if !t.isHT {
@ -162,20 +162,19 @@ func (m *CPUFreqCollector) Init(config []byte) error {
numNonHT := fmt.Sprint(numNonHT_int) numNonHT := fmt.Sprint(numNonHT_int)
for i := range m.topology { for i := range m.topology {
t := &m.topology[i] t := &m.topology[i]
t.numPhysicalID = numPhysicalID t.numPhysicalPackages = numPhysicalID
t.numPhysicalID_int = numPhysicalID_int t.numPhysicalPackages_int = numPhysicalID_int
t.numNonHT = numNonHT t.numNonHT = numNonHT
t.numNonHT_int = numNonHT_int t.numNonHT_int = numNonHT_int
t.tagSet = map[string]string{ t.tagSet = map[string]string{
"type": "cpu", "type": "cpu",
"type-id": t.processor, "type-id": t.processor,
"num_core": t.numNonHT, "num_core": t.numNonHT,
"package_id": t.physicalID, "package_id": t.physicalPackageID,
"num_package": t.numPhysicalID, "num_package": t.numPhysicalPackages,
} }
} }
fmt.Printf("%+v\n", m.topology)
m.init = true m.init = true
return nil return nil
} }