shirou / gopsutil

psutil for golang
Other
10.66k stars 1.59k forks source link

feat(cpu, mem, sensors, disk, process)(darwin): cgo-free implementations #1702

Closed uubulb closed 1 month ago

uubulb commented 2 months ago

This PR provides cgo-free implementations for the following packages: cpu, mem, sensors, disk, process This has been achieved by porting C structs to Go structs and calling C functions using purego.

Additionally, I have modified the behavior of sensors.TemperaturesWithContext on darwin arm64 to display the complete sensor name and return only a single value per sensor. You can view the differences here: https://gist.github.com/uubulb/d75e5c7f490c14c398987f9a9a898a03

Tested on Mac15,6 (arm64, 14.6.1) and MacBookPro7,1 (amd64, 10.13.6).

Changes in interval/common/common_darwin.go are preparatory for further porting, but the current approach is somewhat complex. If anyone has better ideas, please share them!


Update: Added ports for disk and process, and removed go-m1cpu as a dependency since it requires cgo.