From 7498e8f5a2e3de83771b8dd9997fb9c02a39228d Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 8 May 2019 16:42:53 -0400 Subject: [PATCH] cmd/link: write memprofile in legacy format for compilebench 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 Reviewed-by: Cherry Zhang --- src/cmd/link/internal/ld/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go index f47e35301c..67e5ef9392 100644 --- a/src/cmd/link/internal/ld/main.go +++ b/src/cmd/link/internal/ld/main.go @@ -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) } }) -- 2.48.1