diff --git a/Makefile b/Makefile index fb55df4..e39d3e0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pkg/gordio/server/noprofile.go b/pkg/gordio/server/noprofile.go new file mode 100644 index 0000000..072adba --- /dev/null +++ b/pkg/gordio/server/noprofile.go @@ -0,0 +1,5 @@ +// +build !pprof + +package server + +func (s *Server) installPprof() {} diff --git a/pkg/gordio/server/profile.go b/pkg/gordio/server/profile.go new file mode 100644 index 0000000..cefd244 --- /dev/null +++ b/pkg/gordio/server/profile.go @@ -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) +} diff --git a/pkg/gordio/server/routes.go b/pkg/gordio/server/routes.go index 601c2db..19c03d9 100644 --- a/pkg/gordio/server/routes.go +++ b/pkg/gordio/server/routes.go @@ -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())