mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 19:44:44 +00:00
Make the analysis state more accurate
This commit is contained in:
BIN
bin/status-go
BIN
bin/status-go
Binary file not shown.
@@ -67,13 +67,14 @@ type ProcessInfo struct {
|
||||
}
|
||||
|
||||
type CPUStatus struct {
|
||||
Usage float64
|
||||
PerCore []float64
|
||||
Load1 float64
|
||||
Load5 float64
|
||||
Load15 float64
|
||||
CoreCount int
|
||||
LogicalCPU int
|
||||
Usage float64
|
||||
PerCore []float64
|
||||
PerCoreEstimated bool
|
||||
Load1 float64
|
||||
Load5 float64
|
||||
Load15 float64
|
||||
CoreCount int
|
||||
LogicalCPU int
|
||||
}
|
||||
|
||||
type GPUStatus struct {
|
||||
@@ -381,6 +382,7 @@ func collectCPU() (CPUStatus, error) {
|
||||
|
||||
percents, err := cpu.Percent(cpuSampleInterval, true)
|
||||
var totalPercent float64
|
||||
perCoreEstimated := false
|
||||
if err != nil || len(percents) == 0 {
|
||||
fallbackUsage, fallbackPerCore, fallbackErr := fallbackCPUUtilization(logical)
|
||||
if fallbackErr != nil {
|
||||
@@ -391,6 +393,7 @@ func collectCPU() (CPUStatus, error) {
|
||||
}
|
||||
totalPercent = fallbackUsage
|
||||
percents = fallbackPerCore
|
||||
perCoreEstimated = true
|
||||
} else {
|
||||
for _, v := range percents {
|
||||
totalPercent += v
|
||||
@@ -410,13 +413,14 @@ func collectCPU() (CPUStatus, error) {
|
||||
}
|
||||
|
||||
return CPUStatus{
|
||||
Usage: totalPercent,
|
||||
PerCore: percents,
|
||||
Load1: loadAvg.Load1,
|
||||
Load5: loadAvg.Load5,
|
||||
Load15: loadAvg.Load15,
|
||||
CoreCount: counts,
|
||||
LogicalCPU: logical,
|
||||
Usage: totalPercent,
|
||||
PerCore: percents,
|
||||
PerCoreEstimated: perCoreEstimated,
|
||||
Load1: loadAvg.Load1,
|
||||
Load5: loadAvg.Load5,
|
||||
Load15: loadAvg.Load15,
|
||||
CoreCount: counts,
|
||||
LogicalCPU: logical,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -597,7 +601,11 @@ func collectDisks() ([]DiskStatus, error) {
|
||||
if strings.HasPrefix(part.Mountpoint, "/private/") {
|
||||
continue
|
||||
}
|
||||
if seenDevice[part.Device] {
|
||||
baseDevice := baseDeviceName(part.Device)
|
||||
if baseDevice == "" {
|
||||
baseDevice = part.Device
|
||||
}
|
||||
if seenDevice[baseDevice] {
|
||||
continue
|
||||
}
|
||||
usage, err := disk.Usage(part.Mountpoint)
|
||||
@@ -622,7 +630,7 @@ func collectDisks() ([]DiskStatus, error) {
|
||||
UsedPercent: usage.UsedPercent,
|
||||
Fstype: part.Fstype,
|
||||
})
|
||||
seenDevice[part.Device] = true
|
||||
seenDevice[baseDevice] = true
|
||||
seenVolume[volKey] = true
|
||||
}
|
||||
|
||||
|
||||
@@ -188,24 +188,28 @@ func renderCPUCard(cpu CPUStatus) cardData {
|
||||
lines = append(lines, fmt.Sprintf("Total %s %5.1f%%", progressBar(cpu.Usage), cpu.Usage))
|
||||
lines = append(lines, subtleStyle.Render(fmt.Sprintf("%.2f / %.2f / %.2f (%d cores)", cpu.Load1, cpu.Load5, cpu.Load15, cpu.LogicalCPU)))
|
||||
|
||||
// Show top 3 busiest cores
|
||||
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 })
|
||||
if cpu.PerCoreEstimated {
|
||||
lines = append(lines, subtleStyle.Render("Per-core data unavailable (using averaged load)"))
|
||||
} else if len(cpu.PerCore) > 0 {
|
||||
// Show top 3 busiest cores
|
||||
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))
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
return cardData{icon: iconCPU, title: "CPU", lines: lines}
|
||||
@@ -232,12 +236,20 @@ func renderMemoryCard(mem MemoryStatus) cardData {
|
||||
var lines []string
|
||||
lines = append(lines, fmt.Sprintf("Used %s %5.1f%%", progressBar(mem.UsedPercent), mem.UsedPercent))
|
||||
lines = append(lines, subtleStyle.Render(fmt.Sprintf("%s / %s total", humanBytes(mem.Used), humanBytes(mem.Total))))
|
||||
lines = append(lines, "")
|
||||
// Show available memory
|
||||
available := mem.Total - mem.Used
|
||||
freePercent := 100 - mem.UsedPercent
|
||||
lines = append(lines, fmt.Sprintf("Free %s %5.1f%%", progressBar(freePercent), freePercent))
|
||||
lines = append(lines, subtleStyle.Render(fmt.Sprintf("%s available", humanBytes(available))))
|
||||
if mem.SwapTotal > 0 || mem.SwapUsed > 0 {
|
||||
var swapPercent float64
|
||||
if mem.SwapTotal > 0 {
|
||||
swapPercent = (float64(mem.SwapUsed) / float64(mem.SwapTotal)) * 100.0
|
||||
}
|
||||
swapText := subtleStyle.Render(fmt.Sprintf("%s / %s swap", humanBytes(mem.SwapUsed), humanBytes(mem.SwapTotal)))
|
||||
lines = append(lines, fmt.Sprintf("Swap %s %5.1f%% %s", progressBar(swapPercent), swapPercent, swapText))
|
||||
} else {
|
||||
lines = append(lines, fmt.Sprintf("Swap %s", subtleStyle.Render("not in use")))
|
||||
}
|
||||
// Memory pressure
|
||||
if mem.Pressure != "" {
|
||||
pressureStyle := okStyle
|
||||
|
||||
Reference in New Issue
Block a user