Skip to content

Manual M2 Max patch #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func main() {
err error
setColor, setInterval bool
)
version := "v0.1.6"
version := "v0.1.7"
for i := 1; i < len(os.Args); i++ {
switch os.Args[i] {
case "--help", "-h":
Expand Down Expand Up @@ -589,10 +589,14 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
var eClusterCount, pClusterCount, eClusterActiveTotal, pClusterActiveTotal, eClusterFreqTotal, pClusterFreqTotal int
residencyRe := regexp.MustCompile(`(\w+-Cluster)\s+HW active residency:\s+(\d+\.\d+)%`)
frequencyRe := regexp.MustCompile(`(\w+-Cluster)\s+HW active frequency:\s+(\d+)\s+MHz`)
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)
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)
for _, line := range lines {

for i := 0; i <= 15; i++ {
maxCores := 15 // 16 Cores for M3 Max (4+12)
if modelName == "Apple M2 Max" {
maxCores = 11 // 12 Cores M2 Max (4+8)
}
for i := 0; i <= maxCores; i++ {
re := regexp.MustCompile(`CPU ` + strconv.Itoa(i) + ` active residency:\s+(\d+\.\d+)%`)
matches := re.FindStringSubmatch(powermetricsOutput)
if len(matches) > 1 {
Expand All @@ -606,7 +610,7 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
}
}
}
for i := 0; i <= 15; i++ {
for i := 0; i <= maxCores; i++ {
fre := regexp.MustCompile(`^CPU\s+` + strconv.Itoa(i) + `\s+frequency:\s+(\d+)\s+MHz$`)
matches := fre.FindStringSubmatch(powermetricsOutput)
if len(matches) > 1 {
Expand All @@ -627,7 +631,6 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
if pClusterCount > 0 && pClusterActiveSum > 0.0 && pClusterActiveSum < 100.0 && pClusterActiveSum != 0 {
cpuMetrics.PClusterActive = int(pClusterActiveSum / float64(pClusterCount))
}

if eClusterCount > 0 && eClusterFreqSum > 0.0 && eClusterFreqSum != 0 {
cpuMetrics.EClusterFreqMHz = int(eClusterFreqSum / float64(eClusterCount))
}
Expand Down Expand Up @@ -791,7 +794,6 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
cpuMetrics.EClusterActive = eClusterActiveTotal / eClusterCount
}
}

return cpuMetrics
}

Expand Down