]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: write memprofile in legacy format for compilebench
authorAustin Clements <austin@google.com>
Wed, 8 May 2019 20:42:53 +0000 (16:42 -0400)
committerAustin Clements <austin@google.com>
Wed, 8 May 2019 21:06:26 +0000 (21:06 +0000)
compilebench depends on the legacy heap profile format to read the
allocation stats of build tools. We're adding a benchmark for the
linker to compilebench, so we need the linker to emit the heap profile
in the legacy format.

This is the linker equivalent of CL 35484, which did this for the
compiler.

Change-Id: I16ad60c4f0fd80b4b6d608a5677ebe04e1fb5e5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/176057
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/main.go

index f47e35301c68558a2a4638b3c175e8e8ce770cea..67e5ef939209ffb5613983555360bde8fb50b793 100644 (file)
@@ -319,8 +319,13 @@ func startProfile() {
                        log.Fatalf("%v", err)
                }
                AtExit(func() {
-                       runtime.GC() // profile all outstanding allocations
-                       if err := pprof.WriteHeapProfile(f); err != nil {
+                       // Profile all outstanding allocations.
+                       runtime.GC()
+                       // compilebench parses the memory profile to extract memstats,
+                       // which are only written in the legacy pprof format.
+                       // See golang.org/issue/18641 and runtime/pprof/pprof.go:writeHeap.
+                       const writeLegacyFormat = 1
+                       if err := pprof.Lookup("heap").WriteTo(f, writeLegacyFormat); err != nil {
                                log.Fatalf("%v", err)
                        }
                })