Skip to content

Commit f5f68c6

Browse files
authored
Merge pull request #11 from context-labs/development
Manual M2 Max patch
2 parents a711b9a + 3cc7f17 commit f5f68c6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func main() {
222222
err error
223223
setColor, setInterval bool
224224
)
225-
version := "v0.1.6"
225+
version := "v0.1.7"
226226
for i := 1; i < len(os.Args); i++ {
227227
switch os.Args[i] {
228228
case "--help", "-h":
@@ -589,10 +589,14 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
589589
var eClusterCount, pClusterCount, eClusterActiveTotal, pClusterActiveTotal, eClusterFreqTotal, pClusterFreqTotal int
590590
residencyRe := regexp.MustCompile(`(\w+-Cluster)\s+HW active residency:\s+(\d+\.\d+)%`)
591591
frequencyRe := regexp.MustCompile(`(\w+-Cluster)\s+HW active frequency:\s+(\d+)\s+MHz`)
592-
if modelName == "Apple M3 Max" { // For the M3 Max, we need to manually parse the CPU Usage from the powermetrics output (as current bug in Apple's powermetrics)
592+
if modelName == "Apple M3 Max" || modelName == "Apple M2 Max" { // For the M3/M2 Max, we need to manually parse the CPU Usage from the powermetrics output (as current bug in Apple's powermetrics)
593593
for _, line := range lines {
594594

595-
for i := 0; i <= 15; i++ {
595+
maxCores := 15 // 16 Cores for M3 Max (4+12)
596+
if modelName == "Apple M2 Max" {
597+
maxCores = 11 // 12 Cores M2 Max (4+8)
598+
}
599+
for i := 0; i <= maxCores; i++ {
596600
re := regexp.MustCompile(`CPU ` + strconv.Itoa(i) + ` active residency:\s+(\d+\.\d+)%`)
597601
matches := re.FindStringSubmatch(powermetricsOutput)
598602
if len(matches) > 1 {
@@ -606,7 +610,7 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
606610
}
607611
}
608612
}
609-
for i := 0; i <= 15; i++ {
613+
for i := 0; i <= maxCores; i++ {
610614
fre := regexp.MustCompile(`^CPU\s+` + strconv.Itoa(i) + `\s+frequency:\s+(\d+)\s+MHz$`)
611615
matches := fre.FindStringSubmatch(powermetricsOutput)
612616
if len(matches) > 1 {
@@ -627,7 +631,6 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
627631
if pClusterCount > 0 && pClusterActiveSum > 0.0 && pClusterActiveSum < 100.0 && pClusterActiveSum != 0 {
628632
cpuMetrics.PClusterActive = int(pClusterActiveSum / float64(pClusterCount))
629633
}
630-
631634
if eClusterCount > 0 && eClusterFreqSum > 0.0 && eClusterFreqSum != 0 {
632635
cpuMetrics.EClusterFreqMHz = int(eClusterFreqSum / float64(eClusterCount))
633636
}
@@ -791,7 +794,6 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
791794
cpuMetrics.EClusterActive = eClusterActiveTotal / eClusterCount
792795
}
793796
}
794-
795797
return cpuMetrics
796798
}
797799

0 commit comments

Comments
 (0)