]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: remove "deleted" suffix while parsing maps file
authorMarko Kevac <marko@kevac.org>
Tue, 5 Jun 2018 19:41:18 +0000 (22:41 +0300)
committerHyang-Ah Hana Kim <hyangah@gmail.com>
Fri, 7 Sep 2018 09:45:52 +0000 (09:45 +0000)
If binary file of a running program was deleted or moved, maps
file (/proc/pid/maps) will contain lines that have this binary
filename suffixed with "(deleted)" string. This suffix stayed
as a part of the filename and made remote profiling slightly more
difficult by requiring from a user to rename binary file to
include this suffix.

This change cleans up the filename and removes this suffix and
thus simplify debugging.

Fixes #25740

Change-Id: Ib3c8c3b9ef536c2ac037fcc14e8037fa5c960036
Reviewed-on: https://go-review.googlesource.com/116395
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
src/runtime/pprof/proto.go
src/runtime/pprof/proto_test.go

index cbd0b8337641666632fe2d4168d01dd5acc09780..bd5c8f7afcb8526bcd2d2c49b108a7d2adb3dcdc 100644 (file)
@@ -524,6 +524,14 @@ func parseProcSelfMaps(data []byte, addMapping func(lo, hi, offset uint64, file,
                        continue
                }
                file := string(line)
+
+               // Trim deleted file marker.
+               deletedStr := " (deleted)"
+               deletedLen := len(deletedStr)
+               if len(file) >= deletedLen && file[len(file)-deletedLen:] == deletedStr {
+                       file = file[:len(file)-deletedLen]
+               }
+
                if len(inode) == 1 && inode[0] == '0' && file == "" {
                        // Huge-page text mappings list the initial fragment of
                        // mapped but unpopulated memory as being inode 0.
index 76bd46da028dbb13125246485283675dca1230b6..4452d5123158e5c40af264536d92a21624000ddc 100644 (file)
@@ -216,24 +216,89 @@ c000000000-c000036000 rw-p 00000000 00:00 0
 07000000 07093000 06c00000 /path/to/gobench_server_main
 `
 
+var profSelfMapsTestsWithDeleted = `
+00400000-0040b000 r-xp 00000000 fc:01 787766                             /bin/cat (deleted)
+0060a000-0060b000 r--p 0000a000 fc:01 787766                             /bin/cat (deleted)
+0060b000-0060c000 rw-p 0000b000 fc:01 787766                             /bin/cat (deleted)
+014ab000-014cc000 rw-p 00000000 00:00 0                                  [heap]
+7f7d76af8000-7f7d7797c000 r--p 00000000 fc:01 1318064                    /usr/lib/locale/locale-archive
+7f7d7797c000-7f7d77b36000 r-xp 00000000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77b36000-7f7d77d36000 ---p 001ba000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d36000-7f7d77d3a000 r--p 001ba000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d3a000-7f7d77d3c000 rw-p 001be000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d3c000-7f7d77d41000 rw-p 00000000 00:00 0
+7f7d77d41000-7f7d77d64000 r-xp 00000000 fc:01 1180217                    /lib/x86_64-linux-gnu/ld-2.19.so
+7f7d77f3f000-7f7d77f42000 rw-p 00000000 00:00 0
+7f7d77f61000-7f7d77f63000 rw-p 00000000 00:00 0
+7f7d77f63000-7f7d77f64000 r--p 00022000 fc:01 1180217                    /lib/x86_64-linux-gnu/ld-2.19.so
+7f7d77f64000-7f7d77f65000 rw-p 00023000 fc:01 1180217                    /lib/x86_64-linux-gnu/ld-2.19.so
+7f7d77f65000-7f7d77f66000 rw-p 00000000 00:00 0
+7ffc342a2000-7ffc342c3000 rw-p 00000000 00:00 0                          [stack]
+7ffc34343000-7ffc34345000 r-xp 00000000 00:00 0                          [vdso]
+ffffffffff600000-ffffffffff601000 r-xp 00000090 00:00 0                  [vsyscall]
+->
+00400000 0040b000 00000000 /bin/cat
+7f7d7797c000 7f7d77b36000 00000000 /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d41000 7f7d77d64000 00000000 /lib/x86_64-linux-gnu/ld-2.19.so
+7ffc34343000 7ffc34345000 00000000 [vdso]
+ffffffffff600000 ffffffffff601000 00000090 [vsyscall]
+
+00400000-0040b000 r-xp 00000000 fc:01 787766                             /bin/cat with space
+0060a000-0060b000 r--p 0000a000 fc:01 787766                             /bin/cat with space
+0060b000-0060c000 rw-p 0000b000 fc:01 787766                             /bin/cat with space
+014ab000-014cc000 rw-p 00000000 00:00 0                                  [heap]
+7f7d76af8000-7f7d7797c000 r--p 00000000 fc:01 1318064                    /usr/lib/locale/locale-archive
+7f7d7797c000-7f7d77b36000 r-xp 00000000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77b36000-7f7d77d36000 ---p 001ba000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d36000-7f7d77d3a000 r--p 001ba000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d3a000-7f7d77d3c000 rw-p 001be000 fc:01 1180226                    /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d3c000-7f7d77d41000 rw-p 00000000 00:00 0
+7f7d77d41000-7f7d77d64000 r-xp 00000000 fc:01 1180217                    /lib/x86_64-linux-gnu/ld-2.19.so
+7f7d77f3f000-7f7d77f42000 rw-p 00000000 00:00 0
+7f7d77f61000-7f7d77f63000 rw-p 00000000 00:00 0
+7f7d77f63000-7f7d77f64000 r--p 00022000 fc:01 1180217                    /lib/x86_64-linux-gnu/ld-2.19.so
+7f7d77f64000-7f7d77f65000 rw-p 00023000 fc:01 1180217                    /lib/x86_64-linux-gnu/ld-2.19.so
+7f7d77f65000-7f7d77f66000 rw-p 00000000 00:00 0
+7ffc342a2000-7ffc342c3000 rw-p 00000000 00:00 0                          [stack]
+7ffc34343000-7ffc34345000 r-xp 00000000 00:00 0                          [vdso]
+ffffffffff600000-ffffffffff601000 r-xp 00000090 00:00 0                  [vsyscall]
+->
+00400000 0040b000 00000000 /bin/cat with space
+7f7d7797c000 7f7d77b36000 00000000 /lib/x86_64-linux-gnu/libc-2.19.so
+7f7d77d41000 7f7d77d64000 00000000 /lib/x86_64-linux-gnu/ld-2.19.so
+7ffc34343000 7ffc34345000 00000000 [vdso]
+ffffffffff600000 ffffffffff601000 00000090 [vsyscall]
+`
+
 func TestProcSelfMaps(t *testing.T) {
-       for tx, tt := range strings.Split(profSelfMapsTests, "\n\n") {
-               i := strings.Index(tt, "->\n")
-               if i < 0 {
-                       t.Fatal("malformed test case")
-               }
-               in, out := tt[:i], tt[i+len("->\n"):]
-               if len(out) > 0 && out[len(out)-1] != '\n' {
-                       out += "\n"
-               }
-               var buf bytes.Buffer
-               parseProcSelfMaps([]byte(in), func(lo, hi, offset uint64, file, buildID string) {
-                       fmt.Fprintf(&buf, "%08x %08x %08x %s\n", lo, hi, offset, file)
-               })
-               if buf.String() != out {
-                       t.Errorf("#%d: have:\n%s\nwant:\n%s\n%q\n%q", tx, buf.String(), out, buf.String(), out)
+
+       f := func(t *testing.T, input string) {
+               for tx, tt := range strings.Split(input, "\n\n") {
+                       i := strings.Index(tt, "->\n")
+                       if i < 0 {
+                               t.Fatal("malformed test case")
+                       }
+                       in, out := tt[:i], tt[i+len("->\n"):]
+                       if len(out) > 0 && out[len(out)-1] != '\n' {
+                               out += "\n"
+                       }
+                       var buf bytes.Buffer
+                       parseProcSelfMaps([]byte(in), func(lo, hi, offset uint64, file, buildID string) {
+                               fmt.Fprintf(&buf, "%08x %08x %08x %s\n", lo, hi, offset, file)
+                       })
+                       if buf.String() != out {
+                               t.Errorf("#%d: have:\n%s\nwant:\n%s\n%q\n%q", tx, buf.String(), out, buf.String(), out)
+                       }
                }
        }
+
+       t.Run("Normal", func(t *testing.T) {
+               f(t, profSelfMapsTests)
+       })
+
+       t.Run("WithDeletedFile", func(t *testing.T) {
+               f(t, profSelfMapsTestsWithDeleted)
+       })
 }
 
 // TestMapping checkes the mapping section of CPU profiles