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