Skip to content

Commit d9666b0

Browse files
committed
Fixes to work on more Apple Silicon
Fixes E-GPU display for more Apple Silicon
1 parent b7f1610 commit d9666b0

File tree

2 files changed

+25
-52
lines changed

2 files changed

+25
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
goasitop
44
dist/
5+
.DS_Store

main.go

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func collectMetrics(done chan struct{}, cpumetricsChan chan CPUMetrics, gpumetri
347347
}
348348

349349
func updateTotalPowerChart(newPowerValue float64) {
350-
stderrLogger.Printf("Rendering TotalPowerChart with data: %v\n", TotalPowerChart.Data)
350+
// stderrLogger.Printf("Rendering TotalPowerChart with data: %v\n", TotalPowerChart.Data)
351351
if len(TotalPowerChart.Data[0]) == 0 {
352352
TotalPowerChart.Data[0] = append(TotalPowerChart.Data[0], 0) // Ensure there's at least one data point
353353
}
@@ -494,6 +494,12 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics) CPUMetric
494494
lines := strings.Split(powermetricsOutput, "\n")
495495
eCores := []int{}
496496
pCores := []int{}
497+
eClusterActiveTotal := 0
498+
eClusterCount := 0
499+
pClusterActiveTotal := 0
500+
pClusterCount := 0
501+
eClusterFreqTotal := 0
502+
pClusterFreqTotal := 0
497503
residencyRe := regexp.MustCompile(`(\w+-Cluster)\s+HW active residency:\s+(\d+\.\d+)%`)
498504
frequencyRe := regexp.MustCompile(`(\w+-Cluster)\s+HW active frequency:\s+(\d+)\s+MHz`)
499505

@@ -504,38 +510,24 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics) CPUMetric
504510
if residencyMatches != nil {
505511
cluster := residencyMatches[1]
506512
percent, _ := strconv.ParseFloat(residencyMatches[2], 64)
507-
switch cluster {
508-
case "E0-Cluster":
509-
cpuMetrics.E0ClusterActive = int(percent)
510-
case "E1-Cluster":
511-
cpuMetrics.E1ClusterActive = int(percent)
512-
case "P0-Cluster":
513-
cpuMetrics.P0ClusterActive = int(percent)
514-
case "P1-Cluster":
515-
cpuMetrics.P1ClusterActive = int(percent)
516-
case "P2-Cluster":
517-
cpuMetrics.P2ClusterActive = int(percent)
518-
case "P3-Cluster":
519-
cpuMetrics.P3ClusterActive = int(percent)
513+
if strings.HasPrefix(cluster, "E") {
514+
eClusterActiveTotal += int(percent)
515+
eClusterCount++
516+
} else if strings.HasPrefix(cluster, "P") {
517+
pClusterActiveTotal += int(percent)
518+
pClusterCount++
520519
}
521520
}
522521

523522
if frequencyMatches != nil {
524523
cluster := frequencyMatches[1]
525524
freqMHz, _ := strconv.Atoi(frequencyMatches[2])
526-
switch cluster {
527-
case "E0-Cluster":
528-
cpuMetrics.E0ClusterFreqMHz = freqMHz
529-
case "E1-Cluster":
530-
cpuMetrics.E1ClusterFreqMHz = freqMHz
531-
case "P0-Cluster":
532-
cpuMetrics.P0ClusterFreqMHz = freqMHz
533-
case "P1-Cluster":
534-
cpuMetrics.P1ClusterFreqMHz = freqMHz
535-
case "P2-Cluster":
536-
cpuMetrics.P2ClusterFreqMHz = freqMHz
537-
case "P3-Cluster":
538-
cpuMetrics.P3ClusterFreqMHz = freqMHz
525+
if strings.HasPrefix(cluster, "E") {
526+
eClusterFreqTotal += int(freqMHz)
527+
cpuMetrics.EClusterFreqMHz = eClusterFreqTotal
528+
} else if strings.HasPrefix(cluster, "P") {
529+
pClusterFreqTotal += int(freqMHz)
530+
cpuMetrics.PClusterFreqMHz = pClusterFreqTotal
539531
}
540532
}
541533

@@ -579,22 +571,12 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics) CPUMetric
579571
cpuMetrics.ECores = eCores
580572
cpuMetrics.PCores = pCores
581573

582-
// Additional calculations for M1 Ultra or other logic as needed
583-
if cpuMetrics.E0ClusterActive != 0 && cpuMetrics.E1ClusterActive != 0 {
584-
cpuMetrics.EClusterActive = (cpuMetrics.E0ClusterActive + cpuMetrics.E1ClusterActive) / 2
585-
cpuMetrics.EClusterFreqMHz = max(cpuMetrics.E0ClusterFreqMHz, cpuMetrics.E1ClusterFreqMHz)
586-
} else {
587-
cpuMetrics.EClusterActive = cpuMetrics.E0ClusterActive
588-
cpuMetrics.EClusterFreqMHz = cpuMetrics.E0ClusterFreqMHz
574+
// Calculate average active residency and frequency for E and P clusters
575+
if eClusterCount > 0 {
576+
cpuMetrics.EClusterActive = eClusterActiveTotal / eClusterCount
589577
}
590-
591-
if cpuMetrics.P2ClusterActive != 0 && cpuMetrics.P3ClusterActive != 0 {
592-
cpuMetrics.PClusterActive = (cpuMetrics.P0ClusterActive + cpuMetrics.P1ClusterActive + cpuMetrics.P2ClusterActive + cpuMetrics.P3ClusterActive) / 4
593-
freqs := []int{cpuMetrics.P0ClusterFreqMHz, cpuMetrics.P1ClusterFreqMHz, cpuMetrics.P2ClusterFreqMHz, cpuMetrics.P3ClusterFreqMHz}
594-
cpuMetrics.PClusterFreqMHz = max(freqs...)
595-
} else {
596-
cpuMetrics.PClusterActive = (cpuMetrics.P0ClusterActive + cpuMetrics.P1ClusterActive) / 2
597-
cpuMetrics.PClusterFreqMHz = max(cpuMetrics.P0ClusterFreqMHz, cpuMetrics.P1ClusterFreqMHz)
578+
if pClusterCount > 0 {
579+
cpuMetrics.PClusterActive = pClusterActiveTotal / pClusterCount
598580
}
599581

600582
return cpuMetrics
@@ -621,16 +603,6 @@ func parseGPUMetrics(powermetricsOutput string, gpuMetrics GPUMetrics) GPUMetric
621603
return gpuMetrics
622604
}
623605

624-
func max(values ...int) int {
625-
maxVal := values[0]
626-
for _, val := range values {
627-
if val > maxVal {
628-
maxVal = val
629-
}
630-
}
631-
return maxVal
632-
}
633-
634606
func getSOCInfo() map[string]interface{} {
635607
cpuInfoDict := getCPUInfo()
636608
coreCountsDict := getCoreCounts()

0 commit comments

Comments
 (0)