57 lines
1.5 KiB
Go
Raw Normal View History

2016-03-07 18:38:05 -05:00
package core
import (
"os"
"runtime/pprof"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
2019-03-01 18:51:35 +04:00
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
2016-03-07 18:38:05 -05:00
)
2019-03-01 18:51:35 +04:00
// UnsafeFlushMempool removes all transactions from the mempool.
func UnsafeFlushMempool(ctx *rpctypes.Context) (*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
2019-03-01 18:51:35 +04:00
// UnsafeStartCPUProfiler starts a pprof profiler using the given filename.
func UnsafeStartCPUProfiler(ctx *rpctypes.Context, 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
}
2019-03-01 18:51:35 +04:00
// UnsafeStopCPUProfiler stops the running pprof profiler.
func UnsafeStopCPUProfiler(ctx *rpctypes.Context) (*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
}
2019-03-01 18:51:35 +04:00
// UnsafeWriteHeapProfile dumps a heap profile to the given filename.
func UnsafeWriteHeapProfile(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error) {
2016-03-11 21:45:19 -05:00
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
}