nezhahq-agent/pkg/gpu/stat/stat_darwin_cgo.go
UUBulb 65bf012579
feat: add GPU information retrieval for darwin using cgo (#40)
* feat: add GPU information retrieval for darwin using cgo

* fix kIOMasterPortDefault thing

* return 0
2024-07-19 19:00:59 +08:00

26 lines
579 B
Go

//go:build darwin && cgo
package stat
// #cgo LDFLAGS: -framework IOKit -framework CoreFoundation
// #include "gpu_darwin.h"
import "C"
import (
"unsafe"
)
func extractGPUStat(key *C.char, dict_key *C.char) (int, error) {
utilization := C.find_utilization(key, dict_key)
return int(utilization), nil
}
func GetGPUStat() (float64, error) {
key := C.CString("PerformanceStatistics")
dict_key := C.CString("Device Utilization %")
defer C.free(unsafe.Pointer(key))
defer C.free(unsafe.Pointer(dict_key))
gs, _ := extractGPUStat(key, dict_key)
return float64(gs), nil
}