tendermint/rpc/core/dev.go

52 lines
1.1 KiB
Go
Raw Normal View History

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