Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke 2023-07-10 02:06:04 +02:00
parent fff737998d
commit 81745eeedf
No known key found for this signature in database
3 changed files with 73 additions and 72 deletions

View File

@ -1,3 +1,5 @@
package perflib
/* /*
Go bindings for the HKEY_PERFORMANCE_DATA perflib / Performance Counters interface. Go bindings for the HKEY_PERFORMANCE_DATA perflib / Performance Counters interface.
@ -107,7 +109,6 @@ Data for some of the objects is also available through WMI:
TotalRequestsPerSecond : 59 TotalRequestsPerSecond : 59
UserQuotaViolationsPerSecond : 0 UserQuotaViolationsPerSecond : 0
*/ */
package perflib
import ( import (
"bytes" "bytes"
@ -125,7 +126,7 @@ var bo = binary.LittleEndian
const averageCount64Type = 1073874176 const averageCount64Type = 1073874176
// Top-level performance object (like "Process"). // PerfObject Top-level performance object (like "Process").
type PerfObject struct { type PerfObject struct {
Name string Name string
// Same index you pass to QueryPerformanceData // Same index you pass to QueryPerformanceData
@ -140,7 +141,7 @@ type PerfObject struct {
rawData *perfObjectType rawData *perfObjectType
} }
// Each object can have multiple instances. For example, // PerfInstance Each object can have multiple instances. For example,
// In case the object has no instances, we return one single PerfInstance with an empty name. // In case the object has no instances, we return one single PerfInstance with an empty name.
type PerfInstance struct { type PerfInstance struct {
// *not* resolved using a name table // *not* resolved using a name table
@ -187,7 +188,7 @@ var (
bufLenCostly = uint32(2000000) bufLenCostly = uint32(2000000)
) )
// Queries the performance counter buffer using RegQueryValueEx, returning raw bytes. See: // queryRawData Queries the performance counter buffer using RegQueryValueEx, returning raw bytes. See:
// https://msdn.microsoft.com/de-de/library/windows/desktop/aa373219(v=vs.85).aspx // https://msdn.microsoft.com/de-de/library/windows/desktop/aa373219(v=vs.85).aspx
func queryRawData(query string) ([]byte, error) { func queryRawData(query string) ([]byte, error) {
var ( var (
@ -261,7 +262,7 @@ func queryRawData(query string) ([]byte, error) {
} }
/* /*
Query all performance counters that match a given query. QueryPerformanceData Query all performance counters that match a given query.
The query can be any of the following: The query can be any of the following:

View File

@ -11,26 +11,26 @@ type binaryReaderFrom interface {
} }
/* /*
https://msdn.microsoft.com/de-de/library/windows/desktop/aa373157(v=vs.85).aspx perfDataBlock
See: https://msdn.microsoft.com/de-de/library/windows/desktop/aa373157(v=vs.85).aspx
typedef struct _PERF_DATA_BLOCK { typedef struct _PERF_DATA_BLOCK {
WCHAR Signature[4]; WCHAR Signature[4];
DWORD LittleEndian; DWORD LittleEndian;
DWORD Version; DWORD Version;
DWORD Revision; DWORD Revision;
DWORD TotalByteLength; DWORD TotalByteLength;
DWORD HeaderLength; DWORD HeaderLength;
DWORD NumObjectTypes; DWORD NumObjectTypes;
DWORD DefaultObject; DWORD DefaultObject;
SYSTEMTIME SystemTime; SYSTEMTIME SystemTime;
LARGE_INTEGER PerfTime; LARGE_INTEGER PerfTime;
LARGE_INTEGER PerfFreq; LARGE_INTEGER PerfFreq;
LARGE_INTEGER PerfTime100nSec; LARGE_INTEGER PerfTime100nSec;
DWORD SystemNameLength; DWORD SystemNameLength;
DWORD SystemNameOffset; DWORD SystemNameOffset;
} PERF_DATA_BLOCK; } PERF_DATA_BLOCK;
*/ */
type perfDataBlock struct { type perfDataBlock struct {
Signature [4]uint16 Signature [4]uint16
LittleEndian uint32 LittleEndian uint32
@ -54,26 +54,26 @@ func (p *perfDataBlock) BinaryReadFrom(r io.Reader) error {
} }
/* /*
https://msdn.microsoft.com/en-us/library/windows/desktop/aa373160(v=vs.85).aspx perfObjectType
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa373160(v=vs.85).aspx
typedef struct _PERF_OBJECT_TYPE { typedef struct _PERF_OBJECT_TYPE {
DWORD TotalByteLength; DWORD TotalByteLength;
DWORD DefinitionLength; DWORD DefinitionLength;
DWORD HeaderLength; DWORD HeaderLength;
DWORD ObjectNameTitleIndex; DWORD ObjectNameTitleIndex;
LPWSTR ObjectNameTitle; LPWSTR ObjectNameTitle;
DWORD ObjectHelpTitleIndex; DWORD ObjectHelpTitleIndex;
LPWSTR ObjectHelpTitle; LPWSTR ObjectHelpTitle;
DWORD DetailLevel; DWORD DetailLevel;
DWORD NumCounters; DWORD NumCounters;
DWORD DefaultCounter; DWORD DefaultCounter;
DWORD NumInstances; DWORD NumInstances;
DWORD CodePage; DWORD CodePage;
LARGE_INTEGER PerfTime; LARGE_INTEGER PerfTime;
LARGE_INTEGER PerfFreq; LARGE_INTEGER PerfFreq;
} PERF_OBJECT_TYPE; } PERF_OBJECT_TYPE;
*/ */
type perfObjectType struct { type perfObjectType struct {
TotalByteLength uint32 TotalByteLength uint32
DefinitionLength uint32 DefinitionLength uint32
@ -96,22 +96,22 @@ func (p *perfObjectType) BinaryReadFrom(r io.Reader) error {
} }
/* /*
https://msdn.microsoft.com/en-us/library/windows/desktop/aa373150(v=vs.85).aspx perfCounterDefinition
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa373150(v=vs.85).aspx
typedef struct _PERF_COUNTER_DEFINITION { typedef struct _PERF_COUNTER_DEFINITION {
DWORD ByteLength; DWORD ByteLength;
DWORD CounterNameTitleIndex; DWORD CounterNameTitleIndex;
LPWSTR CounterNameTitle; LPWSTR CounterNameTitle;
DWORD CounterHelpTitleIndex; DWORD CounterHelpTitleIndex;
LPWSTR CounterHelpTitle; LPWSTR CounterHelpTitle;
LONG DefaultScale; LONG DefaultScale;
DWORD DetailLevel; DWORD DetailLevel;
DWORD CounterType; DWORD CounterType;
DWORD CounterSize; DWORD CounterSize;
DWORD CounterOffset; DWORD CounterOffset;
} PERF_COUNTER_DEFINITION; } PERF_COUNTER_DEFINITION;
*/ */
type perfCounterDefinition struct { type perfCounterDefinition struct {
ByteLength uint32 ByteLength uint32
CounterNameTitleIndex uint32 CounterNameTitleIndex uint32
@ -138,13 +138,13 @@ func (p *perfCounterDefinition) LookupHelp() string {
} }
/* /*
https://msdn.microsoft.com/en-us/library/windows/desktop/aa373147(v=vs.85).aspx perfCounterBlock
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa373147(v=vs.85).aspx
typedef struct _PERF_COUNTER_BLOCK { typedef struct _PERF_COUNTER_BLOCK {
DWORD ByteLength; DWORD ByteLength;
} PERF_COUNTER_BLOCK; } PERF_COUNTER_BLOCK;
*/ */
type perfCounterBlock struct { type perfCounterBlock struct {
ByteLength uint32 ByteLength uint32
} }
@ -154,18 +154,18 @@ func (p *perfCounterBlock) BinaryReadFrom(r io.Reader) error {
} }
/* /*
https://msdn.microsoft.com/en-us/library/windows/desktop/aa373159(v=vs.85).aspx perfInstanceDefinition
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa373159(v=vs.85).aspx
typedef struct _PERF_INSTANCE_DEFINITION { typedef struct _PERF_INSTANCE_DEFINITION {
DWORD ByteLength; DWORD ByteLength;
DWORD ParentObjectTitleIndex; DWORD ParentObjectTitleIndex;
DWORD ParentObjectInstance; DWORD ParentObjectInstance;
DWORD UniqueID; DWORD UniqueID;
DWORD NameOffset; DWORD NameOffset;
DWORD NameLength; DWORD NameLength;
} PERF_INSTANCE_DEFINITION; } PERF_INSTANCE_DEFINITION;
*/ */
type perfInstanceDefinition struct { type perfInstanceDefinition struct {
ByteLength uint32 ByteLength uint32
ParentObjectTitleIndex uint32 ParentObjectTitleIndex uint32

View File

@ -6,7 +6,7 @@ import (
"syscall" "syscall"
) )
// Read an unterminated UTF16 string at a given position, specifying its length // readUTF16StringAtPos Read an unterminated UTF16 string at a given position, specifying its length
func readUTF16StringAtPos(r io.ReadSeeker, absPos int64, length uint32) (string, error) { func readUTF16StringAtPos(r io.ReadSeeker, absPos int64, length uint32) (string, error) {
value := make([]uint16, length/2) value := make([]uint16, length/2)
_, err := r.Seek(absPos, io.SeekStart) _, err := r.Seek(absPos, io.SeekStart)
@ -24,7 +24,7 @@ func readUTF16StringAtPos(r io.ReadSeeker, absPos int64, length uint32) (string,
return syscall.UTF16ToString(value), nil return syscall.UTF16ToString(value), nil
} }
// Reads a null-terminated UTF16 string at the current offset // readUTF16String Reads a null-terminated UTF16 string at the current offset
func readUTF16String(r io.Reader) (string, error) { func readUTF16String(r io.Reader) (string, error) {
var err error var err error