m.curMark = &mark{name: name}
// Unlikely we need to a GC here, as one was likely just done in closeMark.
if m.shouldPProf() {
- f, err := os.Create(makePProfFilename(m.filebase, name))
+ f, err := os.Create(makePProfFilename(m.filebase, name, "cpuprof"))
if err != nil {
panic(err)
}
pprof.StopCPUProfile()
m.pprofFile.Close()
m.pprofFile = nil
+ if m.gc == GC {
+ // Collect a profile of the live heap. Do a
+ // second GC to force sweep completion so we
+ // get a complete snapshot of the live heap at
+ // the end of this phase.
+ runtime.GC()
+ f, err := os.Create(makePProfFilename(m.filebase, m.curMark.name, "memprof"))
+ if err != nil {
+ panic(err)
+ }
+ err = pprof.WriteHeapProfile(f)
+ if err != nil {
+ panic(err)
+ }
+ err = f.Close()
+ if err != nil {
+ panic(err)
+ }
+ }
}
m.marks = append(m.marks, m.curMark)
m.curMark = nil
return string(ret)
}
-func makePProfFilename(filebase, name string) string {
- return fmt.Sprintf("%s_%s.profile", filebase, makeBenchString(name))
+func makePProfFilename(filebase, name, typ string) string {
+ return fmt.Sprintf("%s_%s.%s", filebase, makeBenchString(name), typ)
}
}
func TestPProfNames(t *testing.T) {
- want := "foo_BenchmarkTest.profile"
- if v := makePProfFilename("foo", "test"); v != want {
+ want := "foo_BenchmarkTest.cpuprof"
+ if v := makePProfFilename("foo", "test", "cpuprof"); v != want {
t.Errorf("makePProfFilename() == %q, want %q", v, want)
}
}