From 98c84ed30a47da8ee52b1e642de16b7c17284d2a Mon Sep 17 00:00:00 2001 From: shirou Date: Sun, 13 Jan 2019 17:23:01 +0900 Subject: [PATCH] [process]: move HWM to MemoryInfo at least FreeBSD and Darwin has HWM. --- process/process.go | 1 + process/process_linux.go | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/process/process.go b/process/process.go index 036ad91..807c85d 100644 --- a/process/process.go +++ b/process/process.go @@ -43,6 +43,7 @@ type OpenFilesStat struct { type MemoryInfoStat struct { RSS uint64 `json:"rss"` // bytes VMS uint64 `json:"vms"` // bytes + HWM uint64 `json:"hwm"` // bytes Data uint64 `json:"data"` // bytes Stack uint64 `json:"stack"` // bytes Locked uint64 `json:"locked"` // bytes diff --git a/process/process_linux.go b/process/process_linux.go index 877fd0d..a3a7403 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -33,7 +33,6 @@ const ( type MemoryInfoExStat struct { RSS uint64 `json:"rss"` // bytes VMS uint64 `json:"vms"` // bytes - HWM uint64 `json:"hwm"` . // bytes Shared uint64 `json:"shared"` // bytes Text uint64 `json:"text"` // bytes Lib uint64 `json:"lib"` // bytes @@ -582,8 +581,8 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M pid := p.Pid var ret []MemoryMapsStat if grouped { - ret = make([]MemoryMapsStat, 1) - } + ret = make([]MemoryMapsStat, 1) + } smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps") contents, err := ioutil.ReadFile(smapsPath) if err != nil { @@ -647,19 +646,19 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M return &ret, err } 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) - } + 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) @@ -1121,13 +1120,13 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error { return err } p.memInfo.Swap = v * 1024 - case "VmHWM": + case "VmHWM": value := strings.Trim(value, " kB") // remove last "kB" v, err := strconv.ParseUint(value, 10, 64) if err != nil { return err } - p.memInfo.HWM = v * 1024 + p.memInfo.HWM = v * 1024 case "VmData": value := strings.Trim(value, " kB") // remove last "kB" v, err := strconv.ParseUint(value, 10, 64)