Skip to content

Commit

Permalink
Enable CLI based PPROF
Browse files Browse the repository at this point in the history
  • Loading branch information
Zohaib Sibte Hassan committed Dec 28, 2023
1 parent 609dd2d commit 57177a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var SaveSnapshotFlag = flag.Bool("save-snapshot", false, "Only take snapshot and
var ClusterAddrFlag = flag.String("cluster-addr", "", "Cluster listening address")
var ClusterPeersFlag = flag.String("cluster-peers", "", "Comma separated list of clusters")
var LeafServerFlag = flag.String("leaf-servers", "", "Comma separated list of leaf servers")
var ProfServer = flag.String("pprof", "", "PProf listening address")

var DataRootDir = os.TempDir()
var Config = &Configuration{
Expand Down
20 changes: 19 additions & 1 deletion marmot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"flag"
"io"
"net/http"
"net/http/pprof"
_ "net/http/pprof"
"os"
"time"

Expand All @@ -22,7 +25,6 @@ import (

func main() {
flag.Parse()

err := cfg.Load(*cfg.ConfigPathFlag)
if err != nil {
panic(err)
Expand All @@ -44,6 +46,22 @@ func main() {
log.Logger = gLog.Level(zerolog.InfoLevel)
}

if *cfg.ProfServer != "" {
go func() {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

err := http.ListenAndServe(*cfg.ProfServer, mux)
if err != nil {
log.Error().Err(err).Msg("unable to bind profiler server")
}
}()
}

log.Debug().Msg("Initializing telemetry")
telemetry.InitializeTelemetry()

Expand Down

0 comments on commit 57177a2

Please sign in to comment.