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 3f47def
Show file tree
Hide file tree
Showing 3 changed files with 34 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
22 changes: 22 additions & 0 deletions httpserver/pprofserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package httpserver

import (
"net/http"
"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(prefix+"/debug/pprof/", prof.Index)

Check failure on line 16 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prefix

Check failure on line 16 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prof
h.HandleFunc(prefix+"/debug/pprof/cmdline", prof.Cmdline)

Check failure on line 17 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prefix

Check failure on line 17 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prof
h.HandleFunc(prefix+"/debug/pprof/profile", prof.Profile)

Check failure on line 18 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prefix

Check failure on line 18 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prof
h.HandleFunc(prefix+"/debug/pprof/symbol", prof.Symbol)

Check failure on line 19 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prefix

Check failure on line 19 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prof
h.HandleFunc(prefix+"/debug/pprof/trace", prof.Trace)

Check failure on line 20 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prefix

Check failure on line 20 in httpserver/pprofserver.go

View workflow job for this annotation

GitHub Actions / Quality Control

undefined: prof
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 3f47def

Please sign in to comment.