if err := pprof.StartCPUProfile(f); err != nil {
base.Fatalf("%v", err)
}
- base.AtExit(pprof.StopCPUProfile)
+ base.AtExit(func() {
+ pprof.StopCPUProfile()
+ if err = f.Close(); err != nil {
+ base.Fatalf("error closing cpu profile: %v", err)
+ }
+ })
}
if base.Flag.MemProfile != "" {
if base.Flag.MemProfileRate != 0 {
if err := pprof.Lookup("heap").WriteTo(f, format); err != nil {
base.Fatalf("%v", err)
}
+ if err = f.Close(); err != nil {
+ base.Fatalf("error closing memory profile: %v", err)
+ }
})
} else {
// Not doing memory profiling; disable it entirely.
if err := tracepkg.Start(f); err != nil {
base.Fatalf("%v", err)
}
- base.AtExit(tracepkg.Stop)
+ base.AtExit(func() {
+ tracepkg.Stop()
+ if err = f.Close(); err != nil {
+ base.Fatalf("error closing trace profile: %v", err)
+ }
+ })
}
}