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>
This commit is contained in:
parent
60140f0909
commit
e31d36578a
|
@ -437,6 +437,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
|
||||||
}
|
}
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
|
|
||||||
|
haveAllocs := false
|
||||||
var allocs, allocbytes int64
|
var allocs, allocbytes int64
|
||||||
if *flagAlloc || *flagMemprofile != "" {
|
if *flagAlloc || *flagMemprofile != "" {
|
||||||
out, err := ioutil.ReadFile(dir + "/_compilebench_.memprof")
|
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 {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
haveAllocs = true
|
||||||
switch f[1] {
|
switch f[1] {
|
||||||
case "TotalAlloc":
|
case "TotalAlloc":
|
||||||
allocbytes = val
|
allocbytes = val
|
||||||
|
@ -459,6 +461,9 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
|
||||||
allocs = val
|
allocs = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !haveAllocs {
|
||||||
|
log.Println("missing stats in memprof (golang.org/issue/18641)")
|
||||||
|
}
|
||||||
|
|
||||||
if *flagMemprofile != "" {
|
if *flagMemprofile != "" {
|
||||||
outpath := *flagMemprofile
|
outpath := *flagMemprofile
|
||||||
|
@ -491,7 +496,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
|
||||||
userns := cmd.ProcessState.UserTime().Nanoseconds()
|
userns := cmd.ProcessState.UserTime().Nanoseconds()
|
||||||
|
|
||||||
fmt.Printf("%s 1 %d ns/op %d user-ns/op", name, wallns, userns)
|
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)
|
fmt.Printf(" %d B/op %d allocs/op", allocbytes, allocs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue