mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 06:15:19 +00:00
config: rename prof_laddr to pprof_laddr and move it to rpc (#5315)
* config: rename prof_laddr to pprof_laddr and move it to rpc also, remove `/unsafe_start_cpu_profiler`, `/unsafe_stop_cpu_profiler` and `/unsafe_write_heap_profile` in favor of pprof server functionality. Closes #5303 * update changelog * log start
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
||||
)
|
||||
@@ -13,44 +10,3 @@ func UnsafeFlushMempool(ctx *rpctypes.Context) (*ctypes.ResultUnsafeFlushMempool
|
||||
env.Mempool.Flush()
|
||||
return &ctypes.ResultUnsafeFlushMempool{}, nil
|
||||
}
|
||||
|
||||
var profFile *os.File
|
||||
|
||||
// UnsafeStartCPUProfiler starts a pprof profiler using the given filename.
|
||||
func UnsafeStartCPUProfiler(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error) {
|
||||
var err error
|
||||
profFile, err = os.Create(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = pprof.StartCPUProfile(profFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ctypes.ResultUnsafeProfile{}, nil
|
||||
}
|
||||
|
||||
// UnsafeStopCPUProfiler stops the running pprof profiler.
|
||||
func UnsafeStopCPUProfiler(ctx *rpctypes.Context) (*ctypes.ResultUnsafeProfile, error) {
|
||||
pprof.StopCPUProfile()
|
||||
if err := profFile.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ctypes.ResultUnsafeProfile{}, nil
|
||||
}
|
||||
|
||||
// UnsafeWriteHeapProfile dumps a heap profile to the given filename.
|
||||
func UnsafeWriteHeapProfile(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error) {
|
||||
memProfFile, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := pprof.WriteHeapProfile(memProfFile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := memProfFile.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ctypes.ResultUnsafeProfile{}, nil
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ Available endpoints:
|
||||
/health
|
||||
/unconfirmed_txs
|
||||
/unsafe_flush_mempool
|
||||
/unsafe_stop_cpu_profiler
|
||||
/validators
|
||||
|
||||
Endpoints that require arguments:
|
||||
@@ -40,8 +39,6 @@ Endpoints that require arguments:
|
||||
/dial_persistent_peers?persistent_peers=_
|
||||
/subscribe?event=_
|
||||
/tx?hash=_&prove=_
|
||||
/unsafe_start_cpu_profiler?filename=_
|
||||
/unsafe_write_heap_profile?filename=_
|
||||
/unsubscribe?event=_
|
||||
```
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
// TODO: better system than "unsafe" prefix
|
||||
|
||||
// Routes is a map of available routes.
|
||||
var Routes = map[string]*rpc.RPCFunc{
|
||||
// subscribe/unsubscribe are reserved for websocket events.
|
||||
"subscribe": rpc.NewWSRPCFunc(Subscribe, "query"),
|
||||
@@ -45,14 +46,10 @@ var Routes = map[string]*rpc.RPCFunc{
|
||||
"broadcast_evidence": rpc.NewRPCFunc(BroadcastEvidence, "evidence"),
|
||||
}
|
||||
|
||||
// AddUnsafeRoutes adds unsafe routes.
|
||||
func AddUnsafeRoutes() {
|
||||
// control API
|
||||
Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds")
|
||||
Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent")
|
||||
Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "")
|
||||
|
||||
// profiler API
|
||||
Routes["unsafe_start_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStartCPUProfiler, "filename")
|
||||
Routes["unsafe_stop_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStopCPUProfiler, "")
|
||||
Routes["unsafe_write_heap_profile"] = rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user