1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-03 21:08:17 +08:00

Merge pull request #1149 from ipfs/fix/better-mem-prof

write memory profiles every 30 seconds when enabled
This commit is contained in:
Juan Batiz-Benet
2015-05-02 12:12:22 -07:00

View File

@ -453,15 +453,19 @@ func startProfiling() (func(), error) {
return nil, err return nil, err
} }
pprof.StartCPUProfile(ofi) pprof.StartCPUProfile(ofi)
go func() {
stopProfiling := func() { for _ = range time.NewTicker(time.Second * 30).C {
pprof.StopCPUProfile()
defer ofi.Close() // captured by the closure
err := writeHeapProfileToFile() err := writeHeapProfileToFile()
if err != nil { if err != nil {
log.Critical(err) log.Critical(err)
} }
} }
}()
stopProfiling := func() {
pprof.StopCPUProfile()
defer ofi.Close() // captured by the closure
}
return stopProfiling, nil return stopProfiling, nil
} }