Merge pull request #567 from tagirb/grouped_memorymaps
implement grouped memorymaps output
This commit is contained in:
commit
a33a26bd97
|
@ -581,6 +581,9 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
|||
func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) {
|
||||
pid := p.Pid
|
||||
var ret []MemoryMapsStat
|
||||
if grouped {
|
||||
ret = make([]MemoryMapsStat, 1)
|
||||
}
|
||||
smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps")
|
||||
contents, err := ioutil.ReadFile(smapsPath)
|
||||
if err != nil {
|
||||
|
@ -643,7 +646,20 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||
if err != nil {
|
||||
return &ret, err
|
||||
}
|
||||
ret = append(ret, g)
|
||||
if grouped {
|
||||
ret[0].Size += g.Size
|
||||
ret[0].Rss += g.Rss
|
||||
ret[0].Pss += g.Pss
|
||||
ret[0].SharedClean += g.SharedClean
|
||||
ret[0].SharedDirty += g.SharedDirty
|
||||
ret[0].PrivateClean += g.PrivateClean
|
||||
ret[0].PrivateDirty += g.PrivateDirty
|
||||
ret[0].Referenced += g.Referenced
|
||||
ret[0].Anonymous += g.Anonymous
|
||||
ret[0].Swap += g.Swap
|
||||
} else {
|
||||
ret = append(ret, g)
|
||||
}
|
||||
}
|
||||
// starts new block
|
||||
blocks = make([]string, 16)
|
||||
|
|
|
@ -89,6 +89,7 @@ func Test_Process_memory_maps(t *testing.T) {
|
|||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
||||
// ungrouped memory maps
|
||||
mmaps, err := ret.MemoryMaps(false)
|
||||
if err != nil {
|
||||
t.Errorf("memory map get error %v", err)
|
||||
|
@ -99,6 +100,18 @@ func Test_Process_memory_maps(t *testing.T) {
|
|||
t.Errorf("memory map get error %v", m)
|
||||
}
|
||||
}
|
||||
|
||||
// grouped memory maps
|
||||
mmaps, err = ret.MemoryMaps(true)
|
||||
if err != nil {
|
||||
t.Errorf("memory map get error %v", err)
|
||||
}
|
||||
if len(*mmaps) != 1 {
|
||||
t.Errorf("grouped memory maps length (%v) is not equal to 1", len(*mmaps))
|
||||
}
|
||||
if (*mmaps)[0] == empty {
|
||||
t.Errorf("memory map is empty")
|
||||
}
|
||||
}
|
||||
func Test_Process_MemoryInfo(t *testing.T) {
|
||||
p := testGetProcess()
|
||||
|
|
Loading…
Reference in New Issue