9 log "github.com/sirupsen/logrus"
12 func writeProfilesPeriodically(outdir string) {
13 for range time.NewTicker(time.Minute).C {
14 writeMemProfile(outdir)
15 writeCPUProfile(outdir)
19 func writeCPUProfile(outdir string) {
20 f, err := os.OpenFile(outdir+"/cpu.prof~", os.O_CREATE|os.O_WRONLY, 0666)
27 if err := pprof.StartCPUProfile(f); err != nil {
31 time.Sleep(time.Second)
32 pprof.StopCPUProfile()
38 err = os.Rename(outdir+"/cpu.prof~", outdir+"/cpu.prof")
45 func writeMemProfile(outdir string) {
46 f, err := os.OpenFile(outdir+"/mem.prof~", os.O_CREATE|os.O_WRONLY, 0666)
53 if err := pprof.WriteHeapProfile(f); err != nil {
62 err = os.Rename(outdir+"/mem.prof~", outdir+"/mem.prof")