mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 18:34:46 +00:00
refactor: improve CPU/GPU display for better readability
- Keep showing top 3 busiest cores instead of all cores - Simplify core info display: 'Load x.xx / x.xx / x.xx (8P+4E)' - Remove excessive comments in GPU card rendering - Add missing sort import for core sorting logic Co-authored-by: bsisduck <bluescreen@duck.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -186,9 +187,8 @@ func renderCPUCard(cpu CPUStatus) cardData {
|
||||
var lines []string
|
||||
lines = append(lines, fmt.Sprintf("Total %s %5.1f%%", progressBar(cpu.Usage), cpu.Usage))
|
||||
|
||||
// Show core topology info if available (Apple Silicon)
|
||||
if cpu.PCoreCount > 0 && cpu.ECoreCount > 0 {
|
||||
lines = append(lines, subtleStyle.Render(fmt.Sprintf("%.2f / %.2f / %.2f (%dP + %dE cores)",
|
||||
lines = append(lines, subtleStyle.Render(fmt.Sprintf("Load %.2f / %.2f / %.2f (%dP+%dE)",
|
||||
cpu.Load1, cpu.Load5, cpu.Load15, cpu.PCoreCount, cpu.ECoreCount)))
|
||||
} else {
|
||||
lines = append(lines, subtleStyle.Render(fmt.Sprintf("%.2f / %.2f / %.2f (%d cores)",
|
||||
@@ -198,23 +198,23 @@ func renderCPUCard(cpu CPUStatus) cardData {
|
||||
if cpu.PerCoreEstimated {
|
||||
lines = append(lines, subtleStyle.Render("Per-core data unavailable (using averaged load)"))
|
||||
} else if len(cpu.PerCore) > 0 {
|
||||
// Apple Silicon: Group cores into P-CPU and E-CPU
|
||||
if cpu.PCoreCount > 0 && cpu.ECoreCount > 0 {
|
||||
// P-cores (Performance) come first
|
||||
lines = append(lines, titleStyle.Render("P-CPU"))
|
||||
for i := 0; i < cpu.PCoreCount && i < len(cpu.PerCore); i++ {
|
||||
lines = append(lines, fmt.Sprintf("Core%-2d %s %5.1f%%", i+1, progressBar(cpu.PerCore[i]), cpu.PerCore[i]))
|
||||
}
|
||||
// E-cores (Efficiency) come after P-cores
|
||||
lines = append(lines, titleStyle.Render("E-CPU"))
|
||||
for i := cpu.PCoreCount; i < cpu.PCoreCount+cpu.ECoreCount && i < len(cpu.PerCore); i++ {
|
||||
lines = append(lines, fmt.Sprintf("Core%-2d %s %5.1f%%", i+1, progressBar(cpu.PerCore[i]), cpu.PerCore[i]))
|
||||
}
|
||||
} else {
|
||||
// Non-Apple Silicon: Show all cores without grouping
|
||||
for i, v := range cpu.PerCore {
|
||||
lines = append(lines, fmt.Sprintf("Core%-2d %s %5.1f%%", i+1, progressBar(v), v))
|
||||
}
|
||||
type coreUsage struct {
|
||||
idx int
|
||||
val float64
|
||||
}
|
||||
var cores []coreUsage
|
||||
for i, v := range cpu.PerCore {
|
||||
cores = append(cores, coreUsage{i, v})
|
||||
}
|
||||
sort.Slice(cores, func(i, j int) bool { return cores[i].val > cores[j].val })
|
||||
|
||||
maxCores := 3
|
||||
if len(cores) < maxCores {
|
||||
maxCores = len(cores)
|
||||
}
|
||||
for i := 0; i < maxCores; i++ {
|
||||
c := cores[i]
|
||||
lines = append(lines, fmt.Sprintf("Core%-2d %s %5.1f%%", c.idx+1, progressBar(c.val), c.val))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,17 +227,14 @@ func renderGPUCard(gpus []GPUStatus) cardData {
|
||||
lines = append(lines, subtleStyle.Render("No GPU detected"))
|
||||
} else {
|
||||
for _, g := range gpus {
|
||||
// Line 1: Usage bar (if available)
|
||||
if g.Usage >= 0 {
|
||||
lines = append(lines, fmt.Sprintf("Total %s %5.1f%%", progressBar(g.Usage), g.Usage))
|
||||
}
|
||||
// Line 2: GPU name and core count
|
||||
coreInfo := ""
|
||||
if g.CoreCount > 0 {
|
||||
coreInfo = fmt.Sprintf(" (%d cores)", g.CoreCount)
|
||||
}
|
||||
lines = append(lines, subtleStyle.Render(g.Name+coreInfo))
|
||||
// Line 3: Hint for sudo if usage unavailable
|
||||
if g.Usage < 0 {
|
||||
lines = append(lines, subtleStyle.Render("Run with sudo for usage metrics"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user