mem[windows]: if no swap, total and/or used is 0.

pull/526/head
shirou 7 years ago
parent 57f370e130
commit 0f1576d63c

@ -4,6 +4,7 @@ package mem
import (
"context"
"errors"
"unsafe"
"github.com/shirou/gopsutil/internal/common"
@ -79,6 +80,10 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
}
tot := perfInfo.commitLimit * perfInfo.pageSize
used := perfInfo.commitTotal * perfInfo.pageSize
if tot == 0 || used == 0 {
return nil, errors.New("total or used memory is 0")
}
free := tot - used
ret := &SwapMemoryStat{
Total: tot,

Loading…
Cancel
Save