serverconfig: conditionally install pprof handler.

This change enables the ability to profile with:
go tool pprof http://<host>:<port>/debug/pprof/profile

Setting CAMLI_HTTP_PPROF=1 in your environment before running camlistored will
enable the handler.

Change-Id: I91993f5166e257e5be406a4d2c3e6bc0028a435a
This commit is contained in:
Bill Thiede 2013-08-18 20:11:10 -07:00
parent c5434e293d
commit 75c79b5a77
1 changed files with 22 additions and 0 deletions

View File

@ -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)
}
}