Skip to content

Commit

Permalink
Fix windows counters on non english systems
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdr committed Feb 1, 2021
1 parent a9a6146 commit 6e7f4ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions v3/internal/common/common_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var (

PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery")
PdhAddCounter = ModPdh.NewProc("PdhAddCounterW")
PdhAddEnglishCounterW = ModPdh.NewProc("PdhAddEnglishCounterW")
PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData")
PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue")
PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery")
Expand Down Expand Up @@ -113,10 +114,10 @@ func CreateQuery() (windows.Handle, error) {
return query, nil
}

// CreateCounter with a PdhAddCounter call
// CreateCounter with a PdhAddEnglishCounterW call
func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, error) {
var counter windows.Handle
r, _, err := PdhAddCounter.Call(
r, _, err := PdhAddEnglishCounterW.Call(
uintptr(query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cname))),
0,
Expand Down Expand Up @@ -159,7 +160,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
PostName: postName,
CounterName: counterName,
}
r, _, err := PdhAddCounter.Call(
r, _, err := PdhAddEnglishCounterW.Call(
uintptr(counter.Query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(counter.CounterName))),
0,
Expand Down
2 changes: 1 addition & 1 deletion v3/load/load_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func loadAvgGoroutine() {

counter, err := common.ProcessorQueueLengthCounter()
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
}

Expand Down

0 comments on commit 6e7f4ff

Please sign in to comment.