pull/871/merge
Euqaidoz 2 weeks ago committed by GitHub
commit 411349b302
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -315,15 +315,14 @@ func (p *Process) CPUAffinityWithContext(_ context.Context) ([]int32, error) {
} }
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) { func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
meminfo, _, err := p.fillFromStatmWithContext(ctx) if err := p.fillFromStatusWithContext(ctx); err != nil {
if err != nil {
return nil, err return nil, err
} }
return meminfo, nil return p.memInfo, nil
} }
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) { func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
_, memInfoEx, err := p.fillFromStatmWithContext(ctx) memInfoEx, err := p.fillFromStatmWithContext(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -757,43 +756,38 @@ func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, e
} }
// Get memory info from /proc/(pid)/statm // Get memory info from /proc/(pid)/statm
func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat, *MemoryInfoExStat, error) { func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
pid := p.Pid pid := p.Pid
memPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "statm") memPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "statm")
contents, err := os.ReadFile(memPath) contents, err := os.ReadFile(memPath)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
fields := strings.Split(string(contents), " ") fields := strings.Split(string(contents), " ")
vms, err := strconv.ParseUint(fields[0], 10, 64) vms, err := strconv.ParseUint(fields[0], 10, 64)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
rss, err := strconv.ParseUint(fields[1], 10, 64) rss, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil { if err != nil {
return nil, nil, err return nil, err
}
memInfo := &MemoryInfoStat{
RSS: rss * pageSize,
VMS: vms * pageSize,
} }
shared, err := strconv.ParseUint(fields[2], 10, 64) shared, err := strconv.ParseUint(fields[2], 10, 64)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
text, err := strconv.ParseUint(fields[3], 10, 64) text, err := strconv.ParseUint(fields[3], 10, 64)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
lib, err := strconv.ParseUint(fields[4], 10, 64) lib, err := strconv.ParseUint(fields[4], 10, 64)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
dirty, err := strconv.ParseUint(fields[5], 10, 64) dirty, err := strconv.ParseUint(fields[5], 10, 64)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
memInfoEx := &MemoryInfoExStat{ memInfoEx := &MemoryInfoExStat{
@ -805,7 +799,7 @@ func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat
Dirty: dirty * pageSize, Dirty: dirty * pageSize,
} }
return memInfo, memInfoEx, nil return memInfoEx, nil
} }
// Get name from /proc/(pid)/comm or /proc/(pid)/status // Get name from /proc/(pid)/comm or /proc/(pid)/status

Loading…
Cancel
Save