From ded95f530cd4dce7ff727e30d95a405425bb0dbb Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 6 Apr 2017 10:01:01 -0700 Subject: [PATCH] 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` 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 --- compilebench/main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compilebench/main.go b/compilebench/main.go index e2f586a9fa2..3072a11700f 100644 --- a/compilebench/main.go +++ b/compilebench/main.go @@ -158,7 +158,7 @@ func main() { continue } if runRE == nil || runRE.MatchString(tt.name) { - runBuild(tt.name, tt.dir) + runBuild(tt.name, tt.dir, i) } } } @@ -213,7 +213,7 @@ func runSize(name, path string) { } } -func runBuild(name, dir string) { +func runBuild(name, dir string, count int) { switch name { case "BenchmarkStdCmd": runStdCmd() @@ -299,7 +299,11 @@ func runBuild(name, dir string) { 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")