cmd/compilebench: generate separate cpu profiles when using -count
When the -count flag is provided,
instead of having each run overwrite the previous profile,
add a count suffix to the profile filename.
Then you can combine the profiles with
go tool pprof `go tool -n compile` <all profile files here>
This allows generation of precise profiles,
even for fast-compiling packages.
Change-Id: I006cf8fad143346b28a646a0b3582cc0f6eec310
Reviewed-on: https://go-review.googlesource.com/39718
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
diff --git a/compilebench/main.go b/compilebench/main.go
index e2f586a..3072a11 100644
--- a/compilebench/main.go
+++ b/compilebench/main.go
@@ -158,7 +158,7 @@
continue
}
if runRE == nil || runRE.MatchString(tt.name) {
- runBuild(tt.name, tt.dir)
+ runBuild(tt.name, tt.dir, i)
}
}
}
@@ -213,7 +213,7 @@
}
}
-func runBuild(name, dir string) {
+func runBuild(name, dir string, count int) {
switch name {
case "BenchmarkStdCmd":
runStdCmd()
@@ -299,7 +299,11 @@
if err != nil {
log.Print(err)
}
- if err := ioutil.WriteFile(*flagCpuprofile, out, 0666); err != nil {
+ outpath := *flagCpuprofile
+ if *flagCount != 1 {
+ outpath = fmt.Sprintf("%s_%d", outpath, count)
+ }
+ if err := ioutil.WriteFile(outpath, out, 0666); err != nil {
log.Print(err)
}
os.Remove(pkg.Dir + "/_compilebench_.cpuprof")