From 9473d01f0feef8530233305d7381a6b1cf2082c1 Mon Sep 17 00:00:00 2001 From: Tyler Davis Date: Tue, 7 Jul 2020 15:02:10 +1000 Subject: [PATCH 1/2] Fix MemoryMaps on ARM ARM has some tab characters in smaps instead of spaces, hence switching to strings.Fields instead of strings.Split which handles splitting on all whitespace instead of just spaces. --- process/process_linux.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/process/process_linux.go b/process/process_linux.go index afd5e28..b453371 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -576,7 +576,8 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M if len(field) < 2 { continue } - v := strings.Trim(field[1], " kB") // remove last "kB" + v := strings.Trim(field[1], "kB") // remove last "kB" + v = strings.TrimSpace(v) t, err := strconv.ParseUint(v, 10, 64) if err != nil { return m, err @@ -610,11 +611,11 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M blocks := make([]string, 16) for _, line := range lines { - field := strings.Split(line, " ") - if strings.HasSuffix(field[0], ":") == false { + fields := strings.Fields(line) + if len(fields) > 0 && strings.HasSuffix(fields[0], ":") == false { // new block section if len(blocks) > 0 { - g, err := getBlock(field, blocks) + g, err := getBlock(fields, blocks) if err != nil { return &ret, err } From 8d28f1b305b1c6e29d9c87b2a18f1eba50e035d8 Mon Sep 17 00:00:00 2001 From: Tyler Davis Date: Tue, 7 Jul 2020 18:02:06 +1000 Subject: [PATCH 2/2] Clean up boolean condition --- process/process_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/process_linux.go b/process/process_linux.go index b453371..f0e1a4d 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -612,7 +612,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M blocks := make([]string, 16) for _, line := range lines { fields := strings.Fields(line) - if len(fields) > 0 && strings.HasSuffix(fields[0], ":") == false { + if len(fields) > 0 && !strings.HasSuffix(fields[0], ":") { // new block section if len(blocks) > 0 { g, err := getBlock(fields, blocks)