-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpu-windows.go
More file actions
54 lines (44 loc) · 1.18 KB
/
cpu-windows.go
File metadata and controls
54 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// +build windows
package cpu
import (
"runtime"
"github.com/StackExchange/wmi"
)
func Info() CPU {
// fetch info from WMI
var win32descriptions []win32Processor
if err := wmi.Query(wmqlProcessor, &win32descriptions); err != nil {
return CPU{
Architecture: CPU_Uknown,
}
}
if len(win32descriptions) <= 0 {
return CPU{
Architecture: CPU_Uknown,
}
}
cpuInfo := CPU{
Count: len(win32descriptions),
CoresPerCPU: int(win32descriptions[0].NumberOfCores),
ThreadsPerCore: int(win32descriptions[0].NumberOfLogicalProcessors),
TotalThreads: runtime.NumCPU(),
Architecture: getCPUArchitecture(),
Variant: CPUVariant{
Name: getCPUArchitectureVariantFromString(win32descriptions[0].Name),
},
Manufacturer: win32descriptions[0].Manufacturer,
AdditionalInfo: AdditionalInfo{
"goos": runtime.GOOS,
"goarch": runtime.GOARCH,
},
}
cpuInfo.setID()
return cpuInfo
}
const wmqlProcessor = "SELECT Manufacturer, Name, NumberOfLogicalProcessors, NumberOfCores FROM Win32_Processor"
type win32Processor struct {
Manufacturer string
Name string
NumberOfLogicalProcessors uint32
NumberOfCores uint32
}