From 0bf4299250fc2ad88b05452c582fa0ddb6b3b307 Mon Sep 17 00:00:00 2001 From: Rishabh Arya Date: Thu, 17 Feb 2022 20:12:19 +0000 Subject: [PATCH] Add support for reading smaps_rollup --- process/process_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/process/process_linux.go b/process/process_linux.go index 8b7d3fd..45de82c 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -380,10 +380,16 @@ func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) { pid := p.Pid var ret []MemoryMapsStat + smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps") if grouped { ret = make([]MemoryMapsStat, 1) + // If smaps_rollup exists (require kernel >= 4.15), then we will use it + // for pre-summed memory information for a process. + smapsRollupPath := common.HostProc(strconv.Itoa(int(pid)), "smaps_rollup") + if _, err := os.Stat(smapsRollupPath); !os.IsNotExist(err) { + smapsPath = smapsRollupPath + } } - smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps") contents, err := ioutil.ReadFile(smapsPath) if err != nil { return nil, err