mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +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:
@ -453,14 +453,18 @@ func startProfiling() (func(), error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pprof.StartCPUProfile(ofi)
|
pprof.StartCPUProfile(ofi)
|
||||||
|
go func() {
|
||||||
|
for _ = range time.NewTicker(time.Second * 30).C {
|
||||||
|
err := writeHeapProfileToFile()
|
||||||
|
if err != nil {
|
||||||
|
log.Critical(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
stopProfiling := func() {
|
stopProfiling := func() {
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
defer ofi.Close() // captured by the closure
|
defer ofi.Close() // captured by the closure
|
||||||
err := writeHeapProfileToFile()
|
|
||||||
if err != nil {
|
|
||||||
log.Critical(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return stopProfiling, nil
|
return stopProfiling, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user