1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00
shirou_gopsutil/mem_windows.go

48 lines
1.0 KiB
Go
Raw Normal View History

2014-04-18 21:28:00 +09:00
// +build windows
2014-04-22 09:44:22 +09:00
package gopsutil
2014-04-18 21:28:00 +09:00
import (
"syscall"
"unsafe"
)
var (
2014-04-20 01:54:14 +09:00
procGlobalMemoryStatusEx = modKernel32.NewProc("GlobalMemoryStatusEx")
)
type MEMORYSTATUSEX struct {
cbSize uint32
dwMemoryLoad uint32
ullTotalPhys uint64 // in bytes
ullAvailPhys uint64
ullTotalPageFile uint64
ullAvailPageFile uint64
ullTotalVirtual uint64
ullAvailVirtual uint64
ullAvailExtendedVirtual uint64
}
2014-04-22 21:39:18 +09:00
func Virtual_memory() (Virtual_memoryStat, error) {
ret := Virtual_memoryStat{}
2014-04-18 21:28:00 +09:00
var memInfo MEMORYSTATUSEX
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
2014-04-20 01:54:14 +09:00
mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo)))
if mem == 0 {
return ret, syscall.GetLastError()
}
ret.Total = memInfo.ullTotalPhys
ret.Available = memInfo.ullAvailPhys
ret.UsedPercent = float64(memInfo.dwMemoryLoad)
ret.Used = ret.Total - ret.Available
2014-04-18 21:28:00 +09:00
return ret, nil
}
2014-04-22 21:39:18 +09:00
func Swap_memory() (Swap_memoryStat, error) {
ret := Swap_memoryStat{}
2014-04-18 21:28:00 +09:00
return ret, nil
}