github.com/jaypipes/ghw@v0.21.1/pkg/cpu/cpu_windows.go (about) 1 //go:build !linux 2 // +build !linux 3 4 // Use and distribution licensed under the Apache license version 2. 5 // 6 // See the COPYING file in the root project directory for full text. 7 // 8 9 package cpu 10 11 import ( 12 "github.com/yusufpapurcu/wmi" 13 ) 14 15 const wmqlProcessor = "SELECT Manufacturer, Name, NumberOfLogicalProcessors, NumberOfCores FROM Win32_Processor" 16 17 type win32Processor struct { 18 Manufacturer *string 19 Name *string 20 NumberOfLogicalProcessors uint32 21 NumberOfCores uint32 22 } 23 24 func (i *Info) load() error { 25 // Getting info from WMI 26 var win32descriptions []win32Processor 27 if err := wmi.Query(wmqlProcessor, &win32descriptions); err != nil { 28 return err 29 } 30 // Converting into standard structures 31 i.Processors = processorsGet(win32descriptions) 32 var totCores uint32 33 var totThreads uint32 34 for _, p := range i.Processors { 35 totCores += p.TotalCores 36 totThreads += p.TotalHardwareThreads 37 } 38 i.TotalCores = totCores 39 i.TotalHardwareThreads = totThreads 40 // TODO(jaypipes): Remove TotalThreads by v1.0 41 i.TotalThreads = totThreads 42 return nil 43 } 44 45 func processorsGet(win32descriptions []win32Processor) []*Processor { 46 var procs []*Processor 47 // Converting into standard structures 48 for index, description := range win32descriptions { 49 p := &Processor{ 50 ID: index, 51 Model: *description.Name, 52 Vendor: *description.Manufacturer, 53 TotalCores: description.NumberOfCores, 54 // TODO(jaypipes): Remove NumCores before v1.0 55 NumCores: description.NumberOfCores, 56 TotalHardwareThreads: description.NumberOfLogicalProcessors, 57 // TODO(jaypipes): Remove NumThreads before v1.0 58 NumThreads: description.NumberOfLogicalProcessors, 59 } 60 procs = append(procs, p) 61 } 62 return procs 63 }