mirror of https://github.com/perkeep/perkeep.git
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:
parent
c5434e293d
commit
75c79b5a77
|
@ -25,6 +25,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -412,5 +413,26 @@ func (config *Config) InstallHandlers(hi HandlerInstaller, baseURL string, conte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hl.setupAll()
|
hl.setupAll()
|
||||||
|
|
||||||
|
if os.Getenv("CAMLI_HTTP_PPROF") != "" {
|
||||||
|
hi.Handle("/debug/pprof/", &ProfileHandler{})
|
||||||
|
}
|
||||||
return nil
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue