|
|
|
@ -11,6 +11,7 @@ import (
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
|
|
|
|
|
procGetPerformanceInfo = common.ModPsapi.NewProc("GetPerformanceInfo")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type memoryStatusEx struct {
|
|
|
|
@ -43,8 +44,40 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type performanceInformation struct {
|
|
|
|
|
cb uint32
|
|
|
|
|
commitTotal uint64
|
|
|
|
|
commitLimit uint64
|
|
|
|
|
commitPeak uint64
|
|
|
|
|
physicalTotal uint64
|
|
|
|
|
physicalAvailable uint64
|
|
|
|
|
systemCache uint64
|
|
|
|
|
kernelTotal uint64
|
|
|
|
|
kernelPaged uint64
|
|
|
|
|
kernelNonpaged uint64
|
|
|
|
|
pageSize uint64
|
|
|
|
|
handleCount uint32
|
|
|
|
|
processCount uint32
|
|
|
|
|
threadCount uint32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SwapMemory() (*SwapMemoryStat, error) {
|
|
|
|
|
ret := &SwapMemoryStat{}
|
|
|
|
|
var perfInfo performanceInformation
|
|
|
|
|
perfInfo.cb = uint32(unsafe.Sizeof(perfInfo))
|
|
|
|
|
mem, _, _ := procGetPerformanceInfo.Call(uintptr(unsafe.Pointer(&perfInfo)), uintptr(perfInfo.cb))
|
|
|
|
|
if mem == 0 {
|
|
|
|
|
return nil, windows.GetLastError()
|
|
|
|
|
}
|
|
|
|
|
tot := perfInfo.commitLimit * perfInfo.pageSize
|
|
|
|
|
used := perfInfo.commitTotal * perfInfo.pageSize
|
|
|
|
|
free := tot - used
|
|
|
|
|
ret := &SwapMemoryStat{
|
|
|
|
|
Total: tot,
|
|
|
|
|
Used: used,
|
|
|
|
|
Free: free,
|
|
|
|
|
UsedPercent: float64(used/tot),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|