From 3f241a0b08d1466d4683030bc18b89c3f80b9c1b Mon Sep 17 00:00:00 2001 From: Vyacheslav Artemiev Date: Fri, 4 Oct 2024 01:57:36 +0400 Subject: [PATCH] feat(mem): Add windows commit stats Closes Expose MemCommit info for Windows #1719 --- mem/ex_windows.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mem/ex_windows.go b/mem/ex_windows.go index 4f1573b3c..5c49a478c 100644 --- a/mem/ex_windows.go +++ b/mem/ex_windows.go @@ -11,7 +11,10 @@ import ( // ExVirtualMemory represents Windows specific information // https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex +// https://learn.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-performance_information type ExVirtualMemory struct { + CommitLimit uint64 `json:"commitLimit"` + CommitTotal uint64 `json:"commitTotal"` VirtualTotal uint64 `json:"virtualTotal"` VirtualAvail uint64 `json:"virtualAvail"` } @@ -30,7 +33,16 @@ func (e *ExWindows) VirtualMemory() (*ExVirtualMemory, error) { return nil, windows.GetLastError() } + var perfInfo performanceInformation + perfInfo.cb = uint32(unsafe.Sizeof(perfInfo)) + perf, _, _ := procGetPerformanceInfo.Call(uintptr(unsafe.Pointer(&perfInfo)), uintptr(perfInfo.cb)) + if perf == 0 { + return nil, windows.GetLastError() + } + ret := &ExVirtualMemory{ + CommitLimit: perfInfo.commitLimit * perfInfo.pageSize, + CommitTotal: perfInfo.commitTotal * perfInfo.pageSize, VirtualTotal: memInfo.ullTotalVirtual, VirtualAvail: memInfo.ullAvailVirtual, }