Skip to content

Commit

Permalink
fix zoneinfo name parsing (#398)
Browse files Browse the repository at this point in the history
Add aditional test coverage for Normal, Movable and Devize zones

Signed-off-by: binjip978 <binjip978@gmail.com>
  • Loading branch information
Sergei Semenchuk committed Jul 21, 2021
1 parent 8506463 commit f8ee60a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion zoneinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func parseZoneinfo(zoneinfoData []byte) ([]Zoneinfo, error) {
continue
}
if strings.HasPrefix(strings.TrimSpace(line), "per-node stats") {
zoneinfoElement.Zone = ""
continue
}
parts := strings.Fields(strings.TrimSpace(line))
Expand Down
20 changes: 16 additions & 4 deletions zoneinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@ import (

func TestZoneinfo(t *testing.T) {
fs := getProcFixtures(t)
protection1 := []*int64{newPInt64(0), newPInt64(2877), newPInt64(7826), newPInt64(7826), newPInt64(7826)}
protection2 := []*int64{newPInt64(0), newPInt64(0), newPInt64(4949), newPInt64(4949), newPInt64(4949)}

protectionDMA := []*int64{newPInt64(0), newPInt64(2877), newPInt64(7826), newPInt64(7826), newPInt64(7826)}
protectionDMA32 := []*int64{newPInt64(0), newPInt64(0), newPInt64(4949), newPInt64(4949), newPInt64(4949)}
protectionNormal := []*int64{newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0)}
protectionMovable := []*int64{newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0)}
protectionDevice := []*int64{newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0)}

refs := []Zoneinfo{
{Node: "0", Zone: "", NrFreePages: newPInt64(3952), Min: newPInt64(33), Low: newPInt64(41), High: newPInt64(49), Spanned: newPInt64(4095), Present: newPInt64(3975), Managed: newPInt64(3956), NrActiveAnon: newPInt64(547580), NrInactiveAnon: newPInt64(230981), NrIsolatedAnon: newPInt64(0), NrAnonPages: newPInt64(795576), NrAnonTransparentHugepages: newPInt64(0), NrActiveFile: newPInt64(346282), NrInactiveFile: newPInt64(316904), NrIsolatedFile: newPInt64(0), NrFilePages: newPInt64(761874), NrSlabReclaimable: newPInt64(131220), NrSlabUnreclaimable: newPInt64(47320), NrKernelStack: newPInt64(0), NrMapped: newPInt64(215483), NrDirty: newPInt64(908), NrWriteback: newPInt64(0), NrUnevictable: newPInt64(115467), NrShmem: newPInt64(224925), NrDirtied: newPInt64(8007423), NrWritten: newPInt64(7752121), NumaHit: newPInt64(1), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(0), NumaLocal: newPInt64(1), NumaOther: newPInt64(0), Protection: protection1},
{Node: "0", Zone: "DMA32", NrFreePages: newPInt64(204252), Min: newPInt64(19510), Low: newPInt64(21059), High: newPInt64(22608), Spanned: newPInt64(1044480), Present: newPInt64(759231), Managed: newPInt64(742806), NrKernelStack: newPInt64(2208), NumaHit: newPInt64(113952967), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(0), NumaLocal: newPInt64(113952967), NumaOther: newPInt64(0), Protection: protection2},
{Node: "0", Zone: "DMA", NrFreePages: newPInt64(3952), Min: newPInt64(33), Low: newPInt64(41), High: newPInt64(49), Spanned: newPInt64(4095), Present: newPInt64(3975), Managed: newPInt64(3956), NrActiveAnon: newPInt64(547580), NrInactiveAnon: newPInt64(230981), NrIsolatedAnon: newPInt64(0), NrAnonPages: newPInt64(795576), NrAnonTransparentHugepages: newPInt64(0), NrActiveFile: newPInt64(346282), NrInactiveFile: newPInt64(316904), NrIsolatedFile: newPInt64(0), NrFilePages: newPInt64(761874), NrSlabReclaimable: newPInt64(131220), NrSlabUnreclaimable: newPInt64(47320), NrKernelStack: newPInt64(0), NrMapped: newPInt64(215483), NrDirty: newPInt64(908), NrWriteback: newPInt64(0), NrUnevictable: newPInt64(115467), NrShmem: newPInt64(224925), NrDirtied: newPInt64(8007423), NrWritten: newPInt64(7752121), NumaHit: newPInt64(1), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(0), NumaLocal: newPInt64(1), NumaOther: newPInt64(0), Protection: protectionDMA},
{Node: "0", Zone: "DMA32", NrFreePages: newPInt64(204252), Min: newPInt64(19510), Low: newPInt64(21059), High: newPInt64(22608), Spanned: newPInt64(1044480), Present: newPInt64(759231), Managed: newPInt64(742806), NrKernelStack: newPInt64(2208), NumaHit: newPInt64(113952967), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(0), NumaLocal: newPInt64(113952967), NumaOther: newPInt64(0), Protection: protectionDMA32},
{Node: "0", Zone: "Normal", NrFreePages: newPInt64(18553), Min: newPInt64(11176), Low: newPInt64(13842), High: newPInt64(16508), Spanned: newPInt64(1308160), Present: newPInt64(1308160), Managed: newPInt64(1268711), NrKernelStack: newPInt64(15136), NumaHit: newPInt64(162718019), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(26812), NumaLocal: newPInt64(162718019), NumaOther: newPInt64(0), Protection: protectionNormal},
{Node: "0", Zone: "Movable", Min: newPInt64(0), Low: newPInt64(0), High: newPInt64(0), Spanned: newPInt64(0), Present: newPInt64(0), Managed: newPInt64(0), Protection: protectionMovable},
{Node: "0", Zone: "Device", Min: newPInt64(0), Low: newPInt64(0), High: newPInt64(0), Spanned: newPInt64(0), Present: newPInt64(0), Managed: newPInt64(0), Protection: protectionDevice},
}

data, err := fs.Zoneinfo()
if err != nil {
t.Fatalf("failed to parse zoneinfo: %v", err)
}
if len(data) != 5 {
t.Fatal("failed to get all all node info")
}

for index, ref := range refs {
want, got := ref, data[index]
Expand Down

0 comments on commit f8ee60a

Please sign in to comment.