Merge pull request #1027 from it-novum/fixwindowscounter

Fixes #1026 windows counters on non english systems
pull/1032/head
shirou 4 years ago committed by GitHub
commit d765dfc473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -71,7 +71,7 @@ var (
ProcNtWow64ReadVirtualMemory64 = ModNt.NewProc("NtWow64ReadVirtualMemory64") ProcNtWow64ReadVirtualMemory64 = ModNt.NewProc("NtWow64ReadVirtualMemory64")
PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery") PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery")
PdhAddCounter = ModPdh.NewProc("PdhAddCounterW") PdhAddEnglishCounterW = ModPdh.NewProc("PdhAddEnglishCounterW")
PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData") PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData")
PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue") PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue")
PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery") PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery")
@ -113,10 +113,10 @@ func CreateQuery() (windows.Handle, error) {
return query, nil return query, nil
} }
// CreateCounter with a PdhAddCounter call // CreateCounter with a PdhAddEnglishCounterW call
func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, error) { func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, error) {
var counter windows.Handle var counter windows.Handle
r, _, err := PdhAddCounter.Call( r, _, err := PdhAddEnglishCounterW.Call(
uintptr(query), uintptr(query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cname))), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cname))),
0, 0,
@ -159,7 +159,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
PostName: postName, PostName: postName,
CounterName: counterName, CounterName: counterName,
} }
r, _, err := PdhAddCounter.Call( r, _, err := PdhAddEnglishCounterW.Call(
uintptr(counter.Query), uintptr(counter.Query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(counter.CounterName))), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(counter.CounterName))),
0, 0,

@ -36,7 +36,7 @@ func loadAvgGoroutine() {
counter, err := common.ProcessorQueueLengthCounter() counter, err := common.ProcessorQueueLengthCounter()
if err != nil || counter == nil { if err != nil || counter == nil {
log.Println("gopsutil: unexpected processor queue length counter error, please file an issue on github") log.Println("gopsutil: unexpected processor queue length counter error, please file an issue on github: err")
return return
} }

@ -71,7 +71,7 @@ var (
ProcNtWow64ReadVirtualMemory64 = ModNt.NewProc("NtWow64ReadVirtualMemory64") ProcNtWow64ReadVirtualMemory64 = ModNt.NewProc("NtWow64ReadVirtualMemory64")
PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery") PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery")
PdhAddCounter = ModPdh.NewProc("PdhAddCounterW") PdhAddEnglishCounterW = ModPdh.NewProc("PdhAddEnglishCounterW")
PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData") PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData")
PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue") PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue")
PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery") PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery")
@ -113,10 +113,10 @@ func CreateQuery() (windows.Handle, error) {
return query, nil return query, nil
} }
// CreateCounter with a PdhAddCounter call // CreateCounter with a PdhAddEnglishCounterW call
func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, error) { func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, error) {
var counter windows.Handle var counter windows.Handle
r, _, err := PdhAddCounter.Call( r, _, err := PdhAddEnglishCounterW.Call(
uintptr(query), uintptr(query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cname))), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cname))),
0, 0,
@ -159,7 +159,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
PostName: postName, PostName: postName,
CounterName: counterName, CounterName: counterName,
} }
r, _, err := PdhAddCounter.Call( r, _, err := PdhAddEnglishCounterW.Call(
uintptr(counter.Query), uintptr(counter.Query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(counter.CounterName))), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(counter.CounterName))),
0, 0,

@ -36,7 +36,7 @@ func loadAvgGoroutine() {
counter, err := common.ProcessorQueueLengthCounter() counter, err := common.ProcessorQueueLengthCounter()
if err != nil || counter == nil { if err != nil || counter == nil {
log.Println("gopsutil: unexpected processor queue length counter error, please file an issue on github") log.Println("gopsutil: unexpected processor queue length counter error, please file an issue on github: err")
return return
} }

Loading…
Cancel
Save