Skip to content

Commit

Permalink
Enable pprof
Browse files Browse the repository at this point in the history
AB#8893
  • Loading branch information
eccles committed Nov 29, 2024
1 parent 1f628f5 commit 32acd02
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .env.tools
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export TOOLS_BUILDNUMBER=20240829.1
export TOOLS_BUILDNUMBER=20241108.3
23 changes: 23 additions & 0 deletions httpserver/pprofserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package httpserver

import (
"net/http"
"net/http/pprof"
_ "net/http/pprof"

"github.com/datatrails/go-datatrails-common/environment"
)

func NewPPROF(log Logger, name string) *Server {
port, err := environment.GetRequired("PPROF_PORT")
if err != nil {
return nil
}
h := http.NewServeMux()
h.HandleFunc("/debug/pprof/", pprof.Index)
h.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
h.HandleFunc("/debug/pprof/profile", pprof.Profile)
h.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
h.HandleFunc("/debug/pprof/trace", pprof.Trace)
return New(log, name, port, h)
}
11 changes: 11 additions & 0 deletions startup/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func WithListeners(listeners ...Listener) ListenersOption {
}
}

// WithOptionalListeners add multiple listeners. Nil listeners are ignored.
func WithOptionalListeners(listeners ...Listener) ListenersOption {
return func(l *Listeners) {
for _, listener := range listeners {
if listener != nil {
l.listeners = append(l.listeners, listener)
}
}
}
}

func NewListeners(log Logger, name string, opts ...ListenersOption) Listeners {
l := Listeners{name: strings.ToLower(name)}
for _, opt := range opts {
Expand Down

0 comments on commit 32acd02

Please sign in to comment.