-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1004 from Lomanic/issue1002
[mem][linux] Fix #1002 only try to parse /proc/meminfo numeric values on fields we're interested in
- Loading branch information
Showing
8 changed files
with
686 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package mem | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestVirtualMemoryEx(t *testing.T) { | ||
v, err := VirtualMemoryEx() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
t.Log(v) | ||
} | ||
|
||
var virtualMemoryTests = []struct { | ||
mockedRootFS string | ||
stat *VirtualMemoryStat | ||
}{ | ||
{"intelcorei5", &VirtualMemoryStat{ | ||
Total: 16502300672, | ||
Available: 11495358464, | ||
Used: 3437277184, | ||
UsedPercent: 20.82907863769651, | ||
Free: 8783491072, | ||
Active: 4347392000, | ||
Inactive: 2938834944, | ||
Wired: 0, | ||
Laundry: 0, | ||
Buffers: 212496384, | ||
Cached: 4069036032, | ||
Writeback: 0, | ||
Dirty: 176128, | ||
WritebackTmp: 0, | ||
Shared: 1222402048, | ||
Slab: 253771776, | ||
SReclaimable: 186470400, | ||
SUnreclaim: 67301376, | ||
PageTables: 65241088, | ||
SwapCached: 0, | ||
CommitLimit: 16509730816, | ||
CommittedAS: 12360818688, | ||
HighTotal: 0, | ||
HighFree: 0, | ||
LowTotal: 0, | ||
LowFree: 0, | ||
SwapTotal: 8258580480, | ||
SwapFree: 8258580480, | ||
Mapped: 1172627456, | ||
VMallocTotal: 35184372087808, | ||
VMallocUsed: 0, | ||
VMallocChunk: 0, | ||
HugePagesTotal: 0, | ||
HugePagesFree: 0, | ||
HugePageSize: 2097152}, | ||
}, | ||
{"issue1002", &VirtualMemoryStat{ | ||
Total: 260579328, | ||
Available: 215199744, | ||
Used: 34328576, | ||
UsedPercent: 13.173944481121694, | ||
Free: 124506112, | ||
Active: 108785664, | ||
Inactive: 8581120, | ||
Wired: 0, | ||
Laundry: 0, | ||
Buffers: 4915200, | ||
Cached: 96829440, | ||
Writeback: 0, | ||
Dirty: 0, | ||
WritebackTmp: 0, | ||
Shared: 0, | ||
Slab: 9293824, | ||
SReclaimable: 2764800, | ||
SUnreclaim: 6529024, | ||
PageTables: 405504, | ||
SwapCached: 0, | ||
CommitLimit: 130289664, | ||
CommittedAS: 25567232, | ||
HighTotal: 134217728, | ||
HighFree: 67784704, | ||
LowTotal: 126361600, | ||
LowFree: 56721408, | ||
SwapTotal: 0, | ||
SwapFree: 0, | ||
Mapped: 38793216, | ||
VMallocTotal: 1996488704, | ||
VMallocUsed: 0, | ||
VMallocChunk: 0, | ||
HugePagesTotal: 0, | ||
HugePagesFree: 0, | ||
HugePageSize: 0}, | ||
}, | ||
} | ||
|
||
func TestVirtualMemoryLinux(t *testing.T) { | ||
origProc := os.Getenv("HOST_PROC") | ||
defer os.Setenv("HOST_PROC", origProc) | ||
|
||
for _, tt := range virtualMemoryTests { | ||
t.Run(tt.mockedRootFS, func(t *testing.T) { | ||
os.Setenv("HOST_PROC", filepath.Join("testdata/linux/virtualmemory/", tt.mockedRootFS, "proc")) | ||
|
||
stat, err := VirtualMemory() | ||
skipIfNotImplementedErr(t, err) | ||
if err != nil { | ||
t.Errorf("error %v", err) | ||
} | ||
if !reflect.DeepEqual(stat, tt.stat) { | ||
t.Errorf("got: %+v\nwant: %+v", stat, tt.stat) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
MemTotal: 16115528 kB | ||
MemFree: 8577628 kB | ||
MemAvailable: 11225936 kB | ||
Buffers: 207516 kB | ||
Cached: 3791568 kB | ||
SwapCached: 0 kB | ||
Active: 4245500 kB | ||
Inactive: 2869956 kB | ||
Active(anon): 3123508 kB | ||
Inactive(anon): 1186612 kB | ||
Active(file): 1121992 kB | ||
Inactive(file): 1683344 kB | ||
Unevictable: 32 kB | ||
Mlocked: 32 kB | ||
SwapTotal: 8065020 kB | ||
SwapFree: 8065020 kB | ||
Dirty: 172 kB | ||
Writeback: 0 kB | ||
AnonPages: 3116472 kB | ||
Mapped: 1145144 kB | ||
Shmem: 1193752 kB | ||
Slab: 247824 kB | ||
SReclaimable: 182100 kB | ||
SUnreclaim: 65724 kB | ||
KernelStack: 14224 kB | ||
PageTables: 63712 kB | ||
NFS_Unstable: 0 kB | ||
Bounce: 0 kB | ||
WritebackTmp: 0 kB | ||
CommitLimit: 16122784 kB | ||
Committed_AS: 12071112 kB | ||
VmallocTotal: 34359738367 kB | ||
VmallocUsed: 0 kB | ||
VmallocChunk: 0 kB | ||
HardwareCorrupted: 0 kB | ||
AnonHugePages: 0 kB | ||
ShmemHugePages: 0 kB | ||
ShmemPmdMapped: 0 kB | ||
HugePages_Total: 0 | ||
HugePages_Free: 0 | ||
HugePages_Rsvd: 0 | ||
HugePages_Surp: 0 | ||
Hugepagesize: 2048 kB | ||
DirectMap4k: 143564 kB | ||
DirectMap2M: 6871040 kB | ||
DirectMap1G: 10485760 kB |
Oops, something went wrong.