From 98fc3038af8dc1574162e1fc3846ec0ade517217 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Thu, 16 May 2024 00:22:56 -0500 Subject: [PATCH] Add pprof flag (#181) --------- Co-authored-by: Pavel Brm <5097196+pavelbrm@users.noreply.github.com> --- server/server.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/server.go b/server/server.go index 1fbbabb9..b0f2751e 100644 --- a/server/server.go +++ b/server/server.go @@ -6,7 +6,9 @@ import ( "fmt" "log" "net/http" + _ "net/http/pprof" // pprof magic "os" + "strconv" "time" "github.com/brave-intl/bat-go/middleware" @@ -60,6 +62,17 @@ func StartServer() { } }() + // Add profiling flag to enable profiling routes. + if on, _ := strconv.ParseBool(os.Getenv("PPROF_ENABLED")); on { + // pprof attaches routes to default serve mux + // host:6061/debug/pprof/ + go func() { + if err := http.ListenAndServe(":6061", http.DefaultServeMux); err != nil { + logger.WithError(err).Error("Server failed to start") + } + }() + } + serverCtx, r := setupRouter(serverCtx, logger, false) port := ":8192" fmt.Printf("Starting server: http://localhost%s", port)