Add pprof

This commit is contained in:
Daniel 2024-10-27 10:35:03 -04:00
parent 5da1eb2944
commit 56f77bb509
4 changed files with 27 additions and 1 deletions

View file

@ -7,9 +7,12 @@ all: checkcalls
go build -o gordio ${LDFLAGS} ./cmd/gordio/
go build -o calls ${LDFLAGS} ./cmd/calls/
buildpprof:
go build -o gordio-pprof ${LDFLAGS} -tags pprof ./cmd/gordio
clean:
rm -rf client/calls/ && mkdir client/calls && touch client/calls/.gitkeep
rm -f gordio calls
rm -f gordio calls gordio-pprof
checkcalls:
@test -e client/calls/index.html || make getcalls

View file

@ -0,0 +1,5 @@
// +build !pprof
package server
func (s *Server) installPprof() {}

View file

@ -0,0 +1,16 @@
// +build pprof
package server
import (
"net/http/pprof"
)
func (s *Server) installPprof() {
r := s.r
r.HandleFunc("/debug/pprof/", pprof.Index)
r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
r.HandleFunc("/debug/pprof/profile", pprof.Profile)
r.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
r.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

View file

@ -28,6 +28,8 @@ func (s *Server) setupRoutes() {
r := s.r
r.Use(middleware.WithValue(database.DBCTXKeyValue, s.db))
s.installPprof()
r.Group(func(r chi.Router) {
// authenticated routes
r.Use(s.auth.VerifyMiddleware(), s.auth.AuthMiddleware())