2024-11-17 20:51:12 +00:00
|
|
|
//go:build windows
|
|
|
|
|
|
|
|
package perfdata
|
2024-09-10 22:34:10 +00:00
|
|
|
|
2024-10-03 21:44:36 +00:00
|
|
|
import "errors"
|
|
|
|
|
2024-11-19 22:36:37 +00:00
|
|
|
var ErrNoData = NewPdhError(PdhNoData)
|
|
|
|
|
2024-09-10 22:34:10 +00:00
|
|
|
// Error represents error returned from Performance Counters API.
|
|
|
|
type Error struct {
|
|
|
|
ErrorCode uint32
|
|
|
|
errorText string
|
|
|
|
}
|
|
|
|
|
2024-10-03 21:44:36 +00:00
|
|
|
func (m *Error) Is(err error) bool {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var e *Error
|
|
|
|
if errors.As(err, &e) {
|
|
|
|
return m.ErrorCode == e.ErrorCode
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-09-10 22:34:10 +00:00
|
|
|
func (m *Error) Error() string {
|
|
|
|
return m.errorText
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPdhError(code uint32) error {
|
|
|
|
return &Error{
|
|
|
|
ErrorCode: code,
|
|
|
|
errorText: PdhFormatError(code),
|
|
|
|
}
|
|
|
|
}
|