Skip to content

Commit 755fedb

Browse files
authored
Merge pull request #22 from context-labs/main
Bring development inline with main
2 parents 3cc7f17 + 28cdb2f commit 755fedb

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727

2828
## Install via Homebrew
2929

30-
Help get us on the official Homebrew formulas by giving us a star and watching this repo! [mactop](https://github.com/context-labs/mactop)
31-
32-
```bash
33-
brew tap context-labs/mactop https://github.com/context-labs/mactop
34-
```
30+
You can install [mactop](https://github.com/context-labs/mactop) via Homebrew! https://brew.sh
3531

3632
```bash
3733
brew install mactop
@@ -108,10 +104,18 @@ Use the following keys to interact with the application while its running:
108104
## Confirmed tested working M series chips
109105

110106
- M1
107+
- M1 Pro
111108
- M1 Max
112109
- M1 Ultra
113-
114-
(If you have a confirmed working M series chip that is not listed, please open an issue!)
110+
- M2
111+
- M2 Pro
112+
- M2 Max
113+
- M2 Ultra
114+
- M3
115+
- M3 Pro
116+
- M3 Max
117+
118+
(If you have a confirmed working M series chip that is not listed, please open an issue, so we may add it here!)
115119

116120
## Contributing
117121

mactop.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
class Mactop < Formula
66
desc "Apple Silicon Monitor Top written in Go Lang"
77
homepage "https://github.com/context-labs/mactop"
8-
version "0.1.3"
8+
version "0.1.7"
99
depends_on :macos
1010

11-
if Hardware::CPU.arm?
12-
url "https://github.com/context-labs/mactop/releases/download/v0.1.3/mactop_0.1.3_darwin_arm64.tar.gz"
13-
sha256 "179d6fd03e41930164ca6f8843af635ccaffc3cfd1e1a2a089b5bfda68fc95e8"
11+
on_arm do
12+
url "https://github.com/context-labs/mactop/releases/download/v0.1.7/mactop_0.1.7_darwin_arm64.tar.gz"
13+
sha256 "40857c92beb8e13fb6a50b1563adb7c7ced5c6dbdc56d35d3546e4a6c4ffc52a"
1414

1515
def install
1616
bin.install "mactop"

main.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ var (
6161
updateInterval = 1000
6262
)
6363

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+
6476
func setupUI() {
6577
appleSiliconModel := getSOCInfo()
6678
modelText = w.NewParagraph()
@@ -401,10 +413,10 @@ func main() {
401413
}
402414

403415
func setupLogfile() (*os.File, error) {
404-
if err := os.MkdirAll("logs", 0755); err != nil {
416+
if err := os.MkdirAll("/var/log", 0755); err != nil {
405417
return nil, fmt.Errorf("failed to make the log directory: %v", err)
406418
}
407-
logfile, err := os.OpenFile("logs/mactop.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0660)
419+
logfile, err := os.OpenFile("/var/log/mactop.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0660)
408420
if err != nil {
409421
return nil, fmt.Errorf("failed to open log file: %v", err)
410422
}
@@ -525,7 +537,6 @@ func updateProcessUI(processMetrics []ProcessMetrics) {
525537

526538
func parseProcessMetrics(powermetricsOutput string, processMetrics []ProcessMetrics) []ProcessMetrics {
527539
lines := strings.Split(powermetricsOutput, "\n")
528-
dataRegex := regexp.MustCompile(`(?m)^\s*(\S.*?)\s+(\d+)\s+(\d+\.\d+)\s+\d+\.\d+\s+`)
529540
seen := make(map[int]bool) // Map to track seen process IDs
530541
for _, line := range lines {
531542
matches := dataRegex.FindStringSubmatch(line)
@@ -554,8 +565,7 @@ func parseProcessMetrics(powermetricsOutput string, processMetrics []ProcessMetr
554565
}
555566

556567
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+
559569
outMatches := outRegex.FindStringSubmatch(powermetricsOutput)
560570
inMatches := inRegex.FindStringSubmatch(powermetricsOutput)
561571
if len(outMatches) == 3 {
@@ -566,8 +576,7 @@ func parseActivityMetrics(powermetricsOutput string, netdiskMetrics NetDiskMetri
566576
netdiskMetrics.InPacketsPerSec, _ = strconv.ParseFloat(inMatches[1], 64)
567577
netdiskMetrics.InBytesPerSec, _ = strconv.ParseFloat(inMatches[2], 64)
568578
}
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+
571580
readMatches := readRegex.FindStringSubmatch(powermetricsOutput)
572581
writeMatches := writeRegex.FindStringSubmatch(powermetricsOutput)
573582
if len(readMatches) == 3 {
@@ -587,8 +596,7 @@ func parseCPUMetrics(powermetricsOutput string, cpuMetrics CPUMetrics, modelName
587596
pCores := []int{}
588597
var eClusterActiveSum, pClusterActiveSum, eClusterFreqSum, pClusterFreqSum float64
589598
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+
592600
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)
593601
for _, line := range lines {
594602

@@ -808,8 +816,7 @@ func max(nums ...int) int {
808816
}
809817

810818
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+
813820
lines := strings.Split(powermetricsOutput, "\n")
814821

815822
for _, line := range lines {

0 commit comments

Comments
 (0)