Browse Source

rpc: unsafe_write_heap_profile

pull/205/head
Ethan Buchman 9 years ago
parent
commit
cb80a7aa42
3 changed files with 29 additions and 7 deletions
  1. +15
    -4
      rpc/core/dev.go
  2. +9
    -0
      rpc/core/routes.go
  3. +5
    -3
      rpc/core/types/responses.go

+ 15
- 4
rpc/core/dev.go View File

@ -36,7 +36,7 @@ func UnsafeSetConfig(typ, key, value string) (*ctypes.ResultUnsafeSetConfig, err
var profFile *os.File var profFile *os.File
func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeCPUProfiler, error) {
func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeProfile, error) {
var err error var err error
profFile, err = os.Create(filename) profFile, err = os.Create(filename)
if err != nil { if err != nil {
@ -46,11 +46,22 @@ func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeCPUProfiler, e
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &ctypes.ResultUnsafeCPUProfiler{}, nil
return &ctypes.ResultUnsafeProfile{}, nil
} }
func UnsafeStopCPUProfiler() (*ctypes.ResultUnsafeCPUProfiler, error) {
func UnsafeStopCPUProfiler() (*ctypes.ResultUnsafeProfile, error) {
pprof.StopCPUProfile() pprof.StopCPUProfile()
profFile.Close() profFile.Close()
return &ctypes.ResultUnsafeCPUProfiler{}, nil
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
} }

+ 9
- 0
rpc/core/routes.go View File

@ -27,6 +27,7 @@ var Routes = map[string]*rpc.RPCFunc{
"unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"), "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"), "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
"unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""), "unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
"unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
} }
func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) { func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
@ -164,3 +165,11 @@ func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
return r, nil return r, nil
} }
} }
func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
if r, err := UnsafeWriteHeapProfile(filename); err != nil {
return nil, err
} else {
return r, nil
}
}

+ 5
- 3
rpc/core/types/responses.go View File

@ -70,7 +70,7 @@ type ResultUnconfirmedTxs struct {
type ResultUnsafeSetConfig struct{} type ResultUnsafeSetConfig struct{}
type ResultUnsafeCPUProfiler struct{}
type ResultUnsafeProfile struct{}
type ResultSubscribe struct { type ResultSubscribe struct {
} }
@ -114,6 +114,7 @@ const (
ResultTypeUnsafeSetConfig = byte(0xa0) ResultTypeUnsafeSetConfig = byte(0xa0)
ResultTypeUnsafeStartCPUProfiler = byte(0xa1) ResultTypeUnsafeStartCPUProfiler = byte(0xa1)
ResultTypeUnsafeStopCPUProfiler = byte(0xa2) ResultTypeUnsafeStopCPUProfiler = byte(0xa2)
ResultTypeUnsafeWriteHeapProfile = byte(0xa3)
) )
type TMResult interface { type TMResult interface {
@ -137,6 +138,7 @@ var _ = wire.RegisterInterface(
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe}, wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
wire.ConcreteType{&ResultEvent{}, ResultTypeEvent}, wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
wire.ConcreteType{&ResultUnsafeSetConfig{}, ResultTypeUnsafeSetConfig}, wire.ConcreteType{&ResultUnsafeSetConfig{}, ResultTypeUnsafeSetConfig},
wire.ConcreteType{&ResultUnsafeCPUProfiler{}, ResultTypeUnsafeStartCPUProfiler},
wire.ConcreteType{&ResultUnsafeCPUProfiler{}, ResultTypeUnsafeStopCPUProfiler},
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeStartCPUProfiler},
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeStopCPUProfiler},
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeWriteHeapProfile},
) )

Loading…
Cancel
Save