2016-03-07 18:38:05 -05:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime/pprof"
|
|
|
|
|
2017-04-26 19:57:33 -04:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2016-03-07 18:38:05 -05:00
|
|
|
)
|
|
|
|
|
2016-07-12 14:58:06 -04:00
|
|
|
func UnsafeFlushMempool() (*ctypes.ResultUnsafeFlushMempool, error) {
|
2016-10-14 21:36:42 -04:00
|
|
|
mempool.Flush()
|
2016-07-12 14:58:06 -04:00
|
|
|
return &ctypes.ResultUnsafeFlushMempool{}, nil
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:38:05 -05:00
|
|
|
var profFile *os.File
|
|
|
|
|
2016-03-11 21:45:19 -05:00
|
|
|
func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeProfile, error) {
|
2016-03-07 18:38:05 -05:00
|
|
|
var err error
|
|
|
|
profFile, err = os.Create(filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = pprof.StartCPUProfile(profFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-03-11 21:45:19 -05:00
|
|
|
return &ctypes.ResultUnsafeProfile{}, nil
|
2016-03-07 18:38:05 -05:00
|
|
|
}
|
|
|
|
|
2016-03-11 21:45:19 -05:00
|
|
|
func UnsafeStopCPUProfiler() (*ctypes.ResultUnsafeProfile, error) {
|
2016-03-07 18:38:05 -05:00
|
|
|
pprof.StopCPUProfile()
|
2017-09-06 11:50:43 -04:00
|
|
|
if err := profFile.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-03-11 21:45:19 -05:00
|
|
|
return &ctypes.ResultUnsafeProfile{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnsafeWriteHeapProfile(filename string) (*ctypes.ResultUnsafeProfile, error) {
|
|
|
|
memProfFile, err := os.Create(filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-09-06 11:50:43 -04:00
|
|
|
if err := pprof.WriteHeapProfile(memProfFile); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := memProfFile.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-03-11 21:45:19 -05:00
|
|
|
|
|
|
|
return &ctypes.ResultUnsafeProfile{}, nil
|
2016-03-07 18:38:05 -05:00
|
|
|
}
|