mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
mem[windows]: if no swap, just return 0 used percent default
This commit is contained in:
parent
0f1576d63c
commit
3adcafe5fd
@ -4,7 +4,6 @@ package mem
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
@ -80,16 +79,18 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
|
|||||||
}
|
}
|
||||||
tot := perfInfo.commitLimit * perfInfo.pageSize
|
tot := perfInfo.commitLimit * perfInfo.pageSize
|
||||||
used := perfInfo.commitTotal * 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
|
free := tot - used
|
||||||
|
var usedPercent float64
|
||||||
|
if tot == 0 {
|
||||||
|
usedPercent = 0
|
||||||
|
} else {
|
||||||
|
usedPercent = float64(used) / float64(tot)
|
||||||
|
}
|
||||||
ret := &SwapMemoryStat{
|
ret := &SwapMemoryStat{
|
||||||
Total: tot,
|
Total: tot,
|
||||||
Used: used,
|
Used: used,
|
||||||
Free: free,
|
Free: free,
|
||||||
UsedPercent: float64(used) / float64(tot),
|
UsedPercent: usedPercent,
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user