Skip to content

Commit

Permalink
Add pprof flag (#181)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Pavel Brm <5097196+pavelbrm@users.noreply.github.com>
  • Loading branch information
mschfh and pavelbrm authored May 16, 2024
1 parent 505f879 commit 98fc303
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"log"
"net/http"
_ "net/http/pprof" // pprof magic
"os"
"strconv"
"time"

"github.com/brave-intl/bat-go/middleware"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 98fc303

Please sign in to comment.