Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 98fc303

Browse files
mschfhpavelbrm
andauthoredMay 16, 2024··
Add pprof flag (#181)
--------- Co-authored-by: Pavel Brm <[email protected]>
1 parent 505f879 commit 98fc303

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎server/server.go

+13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"fmt"
77
"log"
88
"net/http"
9+
_ "net/http/pprof" // pprof magic
910
"os"
11+
"strconv"
1012
"time"
1113

1214
"github.com/brave-intl/bat-go/middleware"
@@ -60,6 +62,17 @@ func StartServer() {
6062
}
6163
}()
6264

65+
// Add profiling flag to enable profiling routes.
66+
if on, _ := strconv.ParseBool(os.Getenv("PPROF_ENABLED")); on {
67+
// pprof attaches routes to default serve mux
68+
// host:6061/debug/pprof/
69+
go func() {
70+
if err := http.ListenAndServe(":6061", http.DefaultServeMux); err != nil {
71+
logger.WithError(err).Error("Server failed to start")
72+
}
73+
}()
74+
}
75+
6376
serverCtx, r := setupRouter(serverCtx, logger, false)
6477
port := ":8192"
6578
fmt.Printf("Starting server: http://localhost%s", port)

0 commit comments

Comments
 (0)
Please sign in to comment.