win_perf_counters: Format errors reported by pdh.dll in human-readable format (#2338)
This commit is contained in:
committed by
Daniel Nelson
parent
748ca7d503
commit
b03d78d00f
@@ -33,8 +33,11 @@
|
||||
package win_perf_counters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// Error codes
|
||||
@@ -417,3 +420,13 @@ func UTF16PtrToString(s *uint16) string {
|
||||
}
|
||||
return syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(s))[0:])
|
||||
}
|
||||
|
||||
func PdhFormatError(msgId uint32) string {
|
||||
var flags uint32 = windows.FORMAT_MESSAGE_FROM_HMODULE | windows.FORMAT_MESSAGE_ARGUMENT_ARRAY | windows.FORMAT_MESSAGE_IGNORE_INSERTS
|
||||
buf := make([]uint16, 300)
|
||||
_, err := windows.FormatMessage(flags, uintptr(libpdhDll.Handle), msgId, 0, buf, nil)
|
||||
if err == nil {
|
||||
return fmt.Sprintf("%s", UTF16PtrToString(&buf[0]))
|
||||
}
|
||||
return fmt.Sprintf("(pdhErr=%d) %s", msgId, err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user