1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

Merge pull request #1251 from rishabh-arya95/master

Add support for reading smaps_rollup
This commit is contained in:
shirou 2022-02-20 14:33:47 +09:00 committed by GitHub
commit f6cc3564ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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