Skip to content

Commit e31d365

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 60140f0 commit e31d365

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/compilebench/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
437437
}
438438
end := time.Now()
439439

440+
haveAllocs := false
440441
var allocs, allocbytes int64
441442
if *flagAlloc || *flagMemprofile != "" {
442443
out, err := ioutil.ReadFile(dir + "/_compilebench_.memprof")
@@ -452,13 +453,17 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
452453
if err != nil {
453454
continue
454455
}
456+
haveAllocs = true
455457
switch f[1] {
456458
case "TotalAlloc":
457459
allocbytes = val
458460
case "Mallocs":
459461
allocs = val
460462
}
461463
}
464+
if !haveAllocs {
465+
log.Println("missing stats in memprof (golang.org/issue/18641)")
466+
}
462467

463468
if *flagMemprofile != "" {
464469
outpath := *flagMemprofile
@@ -491,7 +496,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
491496
userns := cmd.ProcessState.UserTime().Nanoseconds()
492497

493498
fmt.Printf("%s 1 %d ns/op %d user-ns/op", name, wallns, userns)
494-
if *flagAlloc {
499+
if haveAllocs {
495500
fmt.Printf(" %d B/op %d allocs/op", allocbytes, allocs)
496501
}
497502

0 commit comments

Comments
 (0)