etcdserver, embed, v2http: move pprof setup to embed
Seems like a better place for prof setup since it's not specific to v2.
This commit is contained in:
@ -20,6 +20,7 @@ import (
|
||||
defaultLog "log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -35,6 +36,8 @@ import (
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
const pprofPrefix = "/debug/pprof"
|
||||
|
||||
type serveCtx struct {
|
||||
l net.Listener
|
||||
secure bool
|
||||
@ -181,3 +184,23 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
||||
httpmux.Handle("/", handler)
|
||||
return httpmux
|
||||
}
|
||||
|
||||
func (sctx *serveCtx) registerPprof() {
|
||||
f := func(s string, h http.Handler) {
|
||||
if sctx.userHandlers[s] != nil {
|
||||
plog.Warningf("path %s already registered by user handler", s)
|
||||
return
|
||||
}
|
||||
sctx.userHandlers[s] = h
|
||||
}
|
||||
f(pprofPrefix+"/", http.HandlerFunc(pprof.Index))
|
||||
f(pprofPrefix+"/profile", http.HandlerFunc(pprof.Profile))
|
||||
f(pprofPrefix+"/symbol", http.HandlerFunc(pprof.Symbol))
|
||||
f(pprofPrefix+"/cmdline", http.HandlerFunc(pprof.Cmdline))
|
||||
f(pprofPrefix+"/trace", http.HandlerFunc(pprof.Trace))
|
||||
|
||||
f(pprofPrefix+"/heap", pprof.Handler("heap"))
|
||||
f(pprofPrefix+"/goroutine", pprof.Handler("goroutine"))
|
||||
f(pprofPrefix+"/threadcreate", pprof.Handler("threadcreate"))
|
||||
f(pprofPrefix+"/block", pprof.Handler("block"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user