From 75c79b5a77a2c57f5a1e6c56aabef473f7ddd23c Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sun, 18 Aug 2013 20:11:10 -0700 Subject: [PATCH] serverconfig: conditionally install pprof handler. This change enables the ability to profile with: go tool pprof http://:/debug/pprof/profile Setting CAMLI_HTTP_PPROF=1 in your environment before running camlistored will enable the handler. Change-Id: I91993f5166e257e5be406a4d2c3e6bc0028a435a --- pkg/serverconfig/serverconfig.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/serverconfig/serverconfig.go b/pkg/serverconfig/serverconfig.go index e4e35b509..0c7ff415c 100644 --- a/pkg/serverconfig/serverconfig.go +++ b/pkg/serverconfig/serverconfig.go @@ -25,6 +25,7 @@ import ( "fmt" "log" "net/http" + "net/http/pprof" "os" "runtime" "strconv" @@ -412,5 +413,26 @@ func (config *Config) InstallHandlers(hi HandlerInstaller, baseURL string, conte } } hl.setupAll() + + if os.Getenv("CAMLI_HTTP_PPROF") != "" { + hi.Handle("/debug/pprof/", &ProfileHandler{}) + } return nil } + +// ProfileHandler publishes server profile information. +type ProfileHandler struct { +} + +func (ph *ProfileHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { + switch req.URL.Path { + case "/debug/pprof/cmdline": + pprof.Cmdline(rw, req) + case "/debug/pprof/profile": + pprof.Profile(rw, req) + case "/debug/pprof/symbol": + pprof.Symbol(rw, req) + default: + pprof.Index(rw, req) + } +}