61
61
updateInterval = 1000
62
62
)
63
63
64
+ var (
65
+ dataRegex = regexp .MustCompile (`(?m)^\s*(\S.*?)\s+(\d+)\s+(\d+\.\d+)\s+\d+\.\d+\s+` )
66
+ outRegex = regexp .MustCompile (`out:\s*([\d.]+)\s*packets/s,\s*([\d.]+)\s*bytes/s` )
67
+ inRegex = regexp .MustCompile (`in:\s*([\d.]+)\s*packets/s,\s*([\d.]+)\s*bytes/s` )
68
+ readRegex = regexp .MustCompile (`read:\s*([\d.]+)\s*ops/s\s*([\d.]+)\s*KBytes/s` )
69
+ writeRegex = regexp .MustCompile (`write:\s*([\d.]+)\s*ops/s\s*([\d.]+)\s*KBytes/s` )
70
+ residencyRe = regexp .MustCompile (`(\w+-Cluster)\s+HW active residency:\s+(\d+\.\d+)%` )
71
+ frequencyRe = regexp .MustCompile (`(\w+-Cluster)\s+HW active frequency:\s+(\d+)\s+MHz` )
72
+ re = regexp .MustCompile (`GPU\s*(HW)?\s*active\s*(residency|frequency):\s+(\d+\.\d+)%?` )
73
+ freqRe = regexp .MustCompile (`(\d+)\s*MHz:\s*(\d+)%` )
74
+ )
75
+
64
76
func setupUI () {
65
77
appleSiliconModel := getSOCInfo ()
66
78
modelText = w .NewParagraph ()
@@ -525,7 +537,6 @@ func updateProcessUI(processMetrics []ProcessMetrics) {
525
537
526
538
func parseProcessMetrics (powermetricsOutput string , processMetrics []ProcessMetrics ) []ProcessMetrics {
527
539
lines := strings .Split (powermetricsOutput , "\n " )
528
- dataRegex := regexp .MustCompile (`(?m)^\s*(\S.*?)\s+(\d+)\s+(\d+\.\d+)\s+\d+\.\d+\s+` )
529
540
seen := make (map [int ]bool ) // Map to track seen process IDs
530
541
for _ , line := range lines {
531
542
matches := dataRegex .FindStringSubmatch (line )
@@ -554,8 +565,7 @@ func parseProcessMetrics(powermetricsOutput string, processMetrics []ProcessMetr
554
565
}
555
566
556
567
func parseActivityMetrics (powermetricsOutput string , netdiskMetrics NetDiskMetrics ) NetDiskMetrics {
557
- outRegex := regexp .MustCompile (`out:\s*([\d.]+)\s*packets/s,\s*([\d.]+)\s*bytes/s` )
558
- inRegex := regexp .MustCompile (`in:\s*([\d.]+)\s*packets/s,\s*([\d.]+)\s*bytes/s` )
568
+
559
569
outMatches := outRegex .FindStringSubmatch (powermetricsOutput )
560
570
inMatches := inRegex .FindStringSubmatch (powermetricsOutput )
561
571
if len (outMatches ) == 3 {
@@ -566,8 +576,7 @@ func parseActivityMetrics(powermetricsOutput string, netdiskMetrics NetDiskMetri
566
576
netdiskMetrics .InPacketsPerSec , _ = strconv .ParseFloat (inMatches [1 ], 64 )
567
577
netdiskMetrics .InBytesPerSec , _ = strconv .ParseFloat (inMatches [2 ], 64 )
568
578
}
569
- readRegex := regexp .MustCompile (`read:\s*([\d.]+)\s*ops/s\s*([\d.]+)\s*KBytes/s` )
570
- writeRegex := regexp .MustCompile (`write:\s*([\d.]+)\s*ops/s\s*([\d.]+)\s*KBytes/s` )
579
+
571
580
readMatches := readRegex .FindStringSubmatch (powermetricsOutput )
572
581
writeMatches := writeRegex .FindStringSubmatch (powermetricsOutput )
573
582
if len (readMatches ) == 3 {
@@ -587,8 +596,7 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
587
596
pCores := []int {}
588
597
var eClusterActiveSum , pClusterActiveSum , eClusterFreqSum , pClusterFreqSum float64
589
598
var eClusterCount , pClusterCount , eClusterActiveTotal , pClusterActiveTotal , eClusterFreqTotal , pClusterFreqTotal int
590
- residencyRe := regexp .MustCompile (`(\w+-Cluster)\s+HW active residency:\s+(\d+\.\d+)%` )
591
- frequencyRe := regexp .MustCompile (`(\w+-Cluster)\s+HW active frequency:\s+(\d+)\s+MHz` )
599
+
592
600
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)
593
601
for _ , line := range lines {
594
602
@@ -808,8 +816,7 @@ func max(nums ...int) int {
808
816
}
809
817
810
818
func parseGPUMetrics (powermetricsOutput string , gpuMetrics GPUMetrics ) GPUMetrics {
811
- re := regexp .MustCompile (`GPU\s*(HW)?\s*active\s*(residency|frequency):\s+(\d+\.\d+)%?` )
812
- freqRe := regexp .MustCompile (`(\d+)\s*MHz:\s*(\d+)%` )
819
+
813
820
lines := strings .Split (powermetricsOutput , "\n " )
814
821
815
822
for _ , line := range lines {
0 commit comments