Commit 7498e8f5 authored by Austin Clements's avatar Austin Clements

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 <austin@google.com>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent d21c7b72
...@@ -319,8 +319,13 @@ func startProfile() { ...@@ -319,8 +319,13 @@ func startProfile() {
log.Fatalf("%v", err) log.Fatalf("%v", err)
} }
AtExit(func() { AtExit(func() {
runtime.GC() // profile all outstanding allocations // Profile all outstanding allocations.
if err := pprof.WriteHeapProfile(f); err != nil { 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) log.Fatalf("%v", err)
} }
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment