mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-08 19:29:25 +08:00
Fix FreeBSD total memory.
Like this.
FreeBSD: fix total memory giampaolo/psutil@bd9a58b bd9a58b2af
This commit is contained in:
parent
8048a2e9c5
commit
48da6ade9e
@ -19,7 +19,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pageCount, err := unix.SysctlUint32("vm.stats.vm.v_page_count")
|
||||
physmem, err := unix.SysctlUint64("hw.physmem")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -50,7 +50,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
|
||||
|
||||
p := uint64(pageSize)
|
||||
ret := &VirtualMemoryStat{
|
||||
Total: uint64(pageCount) * p,
|
||||
Total: uint64(physmem),
|
||||
Free: uint64(free) * p,
|
||||
Active: uint64(active) * p,
|
||||
Inactive: uint64(inactive) * p,
|
||||
|
@ -32,6 +32,10 @@ func TestVirtual_memory(t *testing.T) {
|
||||
total = v.Used + v.Available
|
||||
totalStr = "used + available"
|
||||
}
|
||||
if runtime.GOOS == "freebsd" {
|
||||
total = v.Used + v.Free + v.Cached + v.Inactive
|
||||
totalStr = "used + free + cached + inactive"
|
||||
}
|
||||
assert.Equal(t, v.Total, total,
|
||||
"Total should be computable (%v): %v", totalStr, v)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user