41 lines
851 B
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"
)
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()
profFile.Close()
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
}
pprof.WriteHeapProfile(memProfFile)
memProfFile.Close()
return &ctypes.ResultUnsafeProfile{}, nil
2016-03-07 18:38:05 -05:00
}