Skip to content

Commit

Permalink
internal/debug: start pprof server by new function StartPProf (ethere…
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Dec 13, 2024
1 parent 66da805 commit 23bc924
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,8 @@ func Setup(ctx *cli.Context) error {

// pprof server
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))
go func() {
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)
}
}()
StartPProf(address)
}

if len(logFile) > 0 || rotation {
Expand All @@ -332,6 +323,18 @@ func Setup(ctx *cli.Context) error {
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
// respective file.
func Exit() {
Expand Down

0 comments on commit 23bc924

Please sign in to comment.