fatedier 0f1005ff61 using glide | 7 jaren geleden | |
---|---|---|
.. | ||
private | 7 jaren geleden | |
testdata | 7 jaren geleden | |
.gitignore | 7 jaren geleden | |
.travis.yml | 7 jaren geleden | |
LICENSE | 7 jaren geleden | |
README.md | 7 jaren geleden | |
cpuid.go | 7 jaren geleden | |
cpuid_386.s | 7 jaren geleden | |
cpuid_amd64.s | 7 jaren geleden | |
cpuid_test.go | 7 jaren geleden | |
detect_intel.go | 7 jaren geleden | |
detect_ref.go | 7 jaren geleden | |
generate.go | 7 jaren geleden | |
mockcpu_test.go | 7 jaren geleden | |
private-gen.go | 7 jaren geleden |
Package cpuid provides information about the CPU running the current program.
CPU features are detected on startup, and kept for fast access through the life of the application. Currently x86 / x64 (AMD64) is supported, and no external C (cgo) code is used, which should make the library very easy to use.
You can access the CPU information by accessing the shared CPU variable of the cpuid library.
Package home: https://github.com/klauspost/cpuid
# example
Go package main
import (
"fmt"
"github.com/klauspost/cpuid"
)
func main() {
// Print basic CPU information:
fmt.Println("Name:", cpuid.CPU.BrandName)
fmt.Println("PhysicalCores:", cpuid.CPU.PhysicalCores)
fmt.Println("ThreadsPerCore:", cpuid.CPU.ThreadsPerCore)
fmt.Println("LogicalCores:", cpuid.CPU.LogicalCores)
fmt.Println("Family", cpuid.CPU.Family, "Model:", cpuid.CPU.Model)
fmt.Println("Features:", cpuid.CPU.Features)
fmt.Println("Cacheline bytes:", cpuid.CPU.CacheLine)
fmt.Println("L1 Data Cache:", cpuid.CPU.Cache.L1D, "bytes")
fmt.Println("L1 Instruction Cache:", cpuid.CPU.Cache.L1D, "bytes")
fmt.Println("L2 Cache:", cpuid.CPU.Cache.L2, "bytes")
fmt.Println("L3 Cache:", cpuid.CPU.Cache.L3, "bytes")
// Test if we have a specific feature:
if cpuid.CPU.SSE() {
fmt.Println("We have Streaming SIMD Extensions")
}
}
Sample output:
go run main.go Name: Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz PhysicalCores: 2 ThreadsPerCore: 2 LogicalCores: 4 Family 6 Model: 42 Features: CMOV,MMX,MMXEXT,SSE,SSE2,SSE3,SSSE3,SSE4.1,SSE4.2,AVX,AESNI,CLMUL Cacheline bytes: 64 We have Streaming SIMD Extensions ```
In the "private" folder you can find an autogenerated version of the library you can include in your own packages.
For this purpose all exports are removed, and functions and constants are lowercased.
This is not a recommended way of using the library, but provided for convenience, if it is difficult for you to use external packages.
This code is published under an MIT license. See LICENSE file for more information.