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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/cmd/compilebench/main.go b/cmd/compilebench/main.go
index 029308a..caa7051 100644
--- a/cmd/compilebench/main.go
+++ b/cmd/compilebench/main.go
@@ -437,6 +437,7 @@
}
end := time.Now()
+ haveAllocs := false
var allocs, allocbytes int64
if *flagAlloc || *flagMemprofile != "" {
out, err := ioutil.ReadFile(dir + "/_compilebench_.memprof")
@@ -452,6 +453,7 @@
if err != nil {
continue
}
+ haveAllocs = true
switch f[1] {
case "TotalAlloc":
allocbytes = val
@@ -459,6 +461,9 @@
allocs = val
}
}
+ if !haveAllocs {
+ log.Println("missing stats in memprof (golang.org/issue/18641)")
+ }
if *flagMemprofile != "" {
outpath := *flagMemprofile
@@ -491,7 +496,7 @@
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)
}