shoenig/go-m1cpu

GitHub: shoenig/go-m1cpu

go-m1cpu 是一个 Go 库,通过调用 Apple IOKit 框架来查询 Apple Silicon M1/M2 CPU 的核心频率、数量及缓存等硬件信息。

Stars: 20 | Forks: 7

# m1cpu [![Go 参考](https://pkg.go.dev/badge/github.com/shoenig/go-m1cpu.svg)](https://pkg.go.dev/github.com/shoenig/go-m1cpu) [![MPL 许可证](https://img.shields.io/github/license/shoenig/go-m1cpu?color=g&style=flat-square)](https://github.com/shoenig/go-m1cpu/blob/main/LICENSE) [![运行 CI 测试](https://static.pigsec.cn/wp-content/uploads/repos/cas/82/8233e5b6925596217ea234306de17adda63fe78f54abd5c296fd2fbc564e0a46.svg)](https://github.com/shoenig/go-m1cpu/actions/workflows/ci.yaml) `go-m1cpu` 模块是一个用于在 Go 中检查 Apple Silicon CPU 的库。 使用 `m1cpu` Go 包来查询 Apple M1 和 M2 CPU 的 CPU 频率。 # 安装 ``` go get github.com/shoenig/go-m1cpu@latest ``` # CGO 此包需要使用 [CGO](https://go.dev/blog/cgo)。 提取 CPU 属性是通过 Apple 的 [IOKit](https://developer.apple.com/documentation/iokit?language=objc) 框架完成的,该框架只能通过系统 C 库访问。 # 示例 打印 Apple Silicon M1/M2 CPU 速度的简单 Go 程序。 ``` package main import ( "fmt" "github.com/shoenig/go-m1cpu" ) func main() { fmt.Println("Apple Silicon", m1cpu.IsAppleSilicon()) fmt.Println("pCore GHz", m1cpu.PCoreGHz()) fmt.Println("eCore GHz", m1cpu.ECoreGHz()) fmt.Println("pCore Hz", m1cpu.PCoreHz()) fmt.Println("eCore Hz", m1cpu.ECoreHz()) } ``` 使用 `go test` 打印可用信息。 ``` ➜ go test -v -run Show === RUN Test_Show cpu_test.go:42: pCore Hz 3504000000 cpu_test.go:43: eCore Hz 2424000000 cpu_test.go:44: pCore GHz 3.504 cpu_test.go:45: eCore GHz 2.424 cpu_test.go:46: pCore count 8 cpu_test.go:47: eCoreCount 4 cpu_test.go:50: pCore Caches 196608 131072 16777216 cpu_test.go:53: eCore Caches 131072 65536 4194304 --- PASS: Test_Show (0.00s) ``` # 许可证 基于 [MPL](LICENSE) 的开源项目
标签:Apple Silicon, CGO, CPU监控, EVTX分析, Go语言, 日志审计, 硬件信息, 程序破解, 系统开发