1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 log "github.com/sirupsen/logrus"
16 func writeProfilesPeriodically(outdir string) {
17 for range time.NewTicker(time.Minute).C {
18 writeMemProfile(outdir)
19 writeCPUProfile(outdir)
23 func writeCPUProfile(outdir string) {
24 f, err := os.OpenFile(outdir+"/cpu.prof~", os.O_CREATE|os.O_WRONLY, 0666)
31 if err := pprof.StartCPUProfile(f); err != nil {
35 time.Sleep(time.Second)
36 pprof.StopCPUProfile()
42 err = os.Rename(outdir+"/cpu.prof~", outdir+"/cpu.prof")
49 func writeMemProfile(outdir string) {
50 f, err := os.OpenFile(outdir+"/mem.prof~", os.O_CREATE|os.O_WRONLY, 0666)
57 if err := pprof.WriteHeapProfile(f); err != nil {
66 err = os.Rename(outdir+"/mem.prof~", outdir+"/mem.prof")