diff --git a/wmi/perflib/perflib.go b/wmi/perflib/perflib.go index 3a64c27c..f9d27543 100644 --- a/wmi/perflib/perflib.go +++ b/wmi/perflib/perflib.go @@ -1,3 +1,5 @@ +package perflib + /* 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 UserQuotaViolationsPerSecond : 0 */ -package perflib import ( "bytes" @@ -125,7 +126,7 @@ var bo = binary.LittleEndian const averageCount64Type = 1073874176 -// Top-level performance object (like "Process"). +// PerfObject Top-level performance object (like "Process"). type PerfObject struct { Name string // Same index you pass to QueryPerformanceData @@ -140,7 +141,7 @@ type PerfObject struct { 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. type PerfInstance struct { // *not* resolved using a name table @@ -187,7 +188,7 @@ var ( 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 func queryRawData(query string) ([]byte, error) { 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: diff --git a/wmi/perflib/raw_types.go b/wmi/perflib/raw_types.go index 0baab304..891bd8ee 100644 --- a/wmi/perflib/raw_types.go +++ b/wmi/perflib/raw_types.go @@ -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 { - WCHAR Signature[4]; - DWORD LittleEndian; - DWORD Version; - DWORD Revision; - DWORD TotalByteLength; - DWORD HeaderLength; - DWORD NumObjectTypes; - DWORD DefaultObject; - SYSTEMTIME SystemTime; - LARGE_INTEGER PerfTime; - LARGE_INTEGER PerfFreq; - LARGE_INTEGER PerfTime100nSec; - DWORD SystemNameLength; - DWORD SystemNameOffset; -} PERF_DATA_BLOCK; + typedef struct _PERF_DATA_BLOCK { + WCHAR Signature[4]; + DWORD LittleEndian; + DWORD Version; + DWORD Revision; + DWORD TotalByteLength; + DWORD HeaderLength; + DWORD NumObjectTypes; + DWORD DefaultObject; + SYSTEMTIME SystemTime; + LARGE_INTEGER PerfTime; + LARGE_INTEGER PerfFreq; + LARGE_INTEGER PerfTime100nSec; + DWORD SystemNameLength; + DWORD SystemNameOffset; + } PERF_DATA_BLOCK; */ - type perfDataBlock struct { Signature [4]uint16 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 { - DWORD TotalByteLength; - DWORD DefinitionLength; - DWORD HeaderLength; - DWORD ObjectNameTitleIndex; - LPWSTR ObjectNameTitle; - DWORD ObjectHelpTitleIndex; - LPWSTR ObjectHelpTitle; - DWORD DetailLevel; - DWORD NumCounters; - DWORD DefaultCounter; - DWORD NumInstances; - DWORD CodePage; - LARGE_INTEGER PerfTime; - LARGE_INTEGER PerfFreq; -} PERF_OBJECT_TYPE; + typedef struct _PERF_OBJECT_TYPE { + DWORD TotalByteLength; + DWORD DefinitionLength; + DWORD HeaderLength; + DWORD ObjectNameTitleIndex; + LPWSTR ObjectNameTitle; + DWORD ObjectHelpTitleIndex; + LPWSTR ObjectHelpTitle; + DWORD DetailLevel; + DWORD NumCounters; + DWORD DefaultCounter; + DWORD NumInstances; + DWORD CodePage; + LARGE_INTEGER PerfTime; + LARGE_INTEGER PerfFreq; + } PERF_OBJECT_TYPE; */ - type perfObjectType struct { TotalByteLength 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 { - DWORD ByteLength; - DWORD CounterNameTitleIndex; - LPWSTR CounterNameTitle; - DWORD CounterHelpTitleIndex; - LPWSTR CounterHelpTitle; - LONG DefaultScale; - DWORD DetailLevel; - DWORD CounterType; - DWORD CounterSize; - DWORD CounterOffset; -} PERF_COUNTER_DEFINITION; + typedef struct _PERF_COUNTER_DEFINITION { + DWORD ByteLength; + DWORD CounterNameTitleIndex; + LPWSTR CounterNameTitle; + DWORD CounterHelpTitleIndex; + LPWSTR CounterHelpTitle; + LONG DefaultScale; + DWORD DetailLevel; + DWORD CounterType; + DWORD CounterSize; + DWORD CounterOffset; + } PERF_COUNTER_DEFINITION; */ - type perfCounterDefinition struct { ByteLength 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 { - DWORD ByteLength; -} PERF_COUNTER_BLOCK; + typedef struct _PERF_COUNTER_BLOCK { + DWORD ByteLength; + } PERF_COUNTER_BLOCK; */ - type perfCounterBlock struct { 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 { - DWORD ByteLength; - DWORD ParentObjectTitleIndex; - DWORD ParentObjectInstance; - DWORD UniqueID; - DWORD NameOffset; - DWORD NameLength; -} PERF_INSTANCE_DEFINITION; + typedef struct _PERF_INSTANCE_DEFINITION { + DWORD ByteLength; + DWORD ParentObjectTitleIndex; + DWORD ParentObjectInstance; + DWORD UniqueID; + DWORD NameOffset; + DWORD NameLength; + } PERF_INSTANCE_DEFINITION; */ - type perfInstanceDefinition struct { ByteLength uint32 ParentObjectTitleIndex uint32 diff --git a/wmi/perflib/utf16.go b/wmi/perflib/utf16.go index 3b0cec9e..003bd620 100644 --- a/wmi/perflib/utf16.go +++ b/wmi/perflib/utf16.go @@ -6,7 +6,7 @@ import ( "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) { value := make([]uint16, length/2) _, 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 } -// 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) { var err error