From e31d36578abb3d202c4007c3747bf8ebb7c51011 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 7 May 2019 21:46:40 -0400 Subject: [PATCH] compilebench: handle missing MemStats more gracefully Reporting MemStats requires the legacy profile format (see golang/go#18641). This CL detects when it couldn't get the MemStats from the profile and reports this, rather than reporting 0 allocs. Change-Id: Ib621ad975290cf05835fafa81e8e47762d82a519 Reviewed-on: https://go-review.googlesource.com/c/tools/+/175802 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox Reviewed-by: Cherry Zhang --- cmd/compilebench/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/compilebench/main.go b/cmd/compilebench/main.go index 029308a4..caa7051a 100644 --- a/cmd/compilebench/main.go +++ b/cmd/compilebench/main.go @@ -437,6 +437,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error } end := time.Now() + haveAllocs := false var allocs, allocbytes int64 if *flagAlloc || *flagMemprofile != "" { out, err := ioutil.ReadFile(dir + "/_compilebench_.memprof") @@ -452,6 +453,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error if err != nil { continue } + haveAllocs = true switch f[1] { case "TotalAlloc": allocbytes = val @@ -459,6 +461,9 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error allocs = val } } + if !haveAllocs { + log.Println("missing stats in memprof (golang.org/issue/18641)") + } if *flagMemprofile != "" { outpath := *flagMemprofile @@ -491,7 +496,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error userns := cmd.ProcessState.UserTime().Nanoseconds() fmt.Printf("%s 1 %d ns/op %d user-ns/op", name, wallns, userns) - if *flagAlloc { + if haveAllocs { fmt.Printf(" %d B/op %d allocs/op", allocbytes, allocs) }