mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 02:10:46 +00:00
internal/debug: start pprof server by new function StartPProf (#16532)
This commit is contained in:
parent
66da805ccd
commit
23bc924585
1 changed files with 13 additions and 10 deletions
|
|
@ -312,17 +312,8 @@ func Setup(ctx *cli.Context) error {
|
||||||
|
|
||||||
// pprof server
|
// pprof server
|
||||||
if ctx.Bool(pprofFlag.Name) {
|
if ctx.Bool(pprofFlag.Name) {
|
||||||
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
|
|
||||||
// from the registry into expvar, and execute regular expvar handler.
|
|
||||||
exp.Exp(metrics.DefaultRegistry)
|
|
||||||
|
|
||||||
address := fmt.Sprintf("%s:%d", ctx.String(pprofAddrFlag.Name), ctx.Int(pprofPortFlag.Name))
|
address := fmt.Sprintf("%s:%d", ctx.String(pprofAddrFlag.Name), ctx.Int(pprofPortFlag.Name))
|
||||||
go func() {
|
StartPProf(address)
|
||||||
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
|
|
||||||
if err := http.ListenAndServe(address, nil); err != nil {
|
|
||||||
log.Error("Failure in running pprof server", "err", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(logFile) > 0 || rotation {
|
if len(logFile) > 0 || rotation {
|
||||||
|
|
@ -332,6 +323,18 @@ func Setup(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartPProf(address string) {
|
||||||
|
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
|
||||||
|
// from the registry into expvar, and execute regular expvar handler.
|
||||||
|
exp.Exp(metrics.DefaultRegistry)
|
||||||
|
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
|
||||||
|
go func() {
|
||||||
|
if err := http.ListenAndServe(address, nil); err != nil {
|
||||||
|
log.Error("Failure in running pprof server", "err", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// Exit stops all running profiles, flushing their output to the
|
// Exit stops all running profiles, flushing their output to the
|
||||||
// respective file.
|
// respective file.
|
||||||
func Exit() {
|
func Exit() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue