mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #11981 from unclejack/fix_profiler
api/server: fix profiler HTTP serving
This commit is contained in:
commit
b3e9c274dd
2 changed files with 5 additions and 19 deletions
|
@ -9,12 +9,9 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func NewProfiler() http.Handler {
|
||||
var (
|
||||
p = &Profiler{}
|
||||
r = mux.NewRouter()
|
||||
)
|
||||
r.HandleFunc("/vars", p.expVars)
|
||||
func ProfilerSetup(mainRouter *mux.Router, path string) {
|
||||
var r = mainRouter.PathPrefix(path).Subrouter()
|
||||
r.HandleFunc("/vars", expVars)
|
||||
r.HandleFunc("/pprof/", pprof.Index)
|
||||
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
|
||||
r.HandleFunc("/pprof/profile", pprof.Profile)
|
||||
|
@ -23,21 +20,10 @@ func NewProfiler() http.Handler {
|
|||
r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP)
|
||||
r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
|
||||
r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
|
||||
p.r = r
|
||||
return p
|
||||
}
|
||||
|
||||
// Profiler enables pprof and expvar support via a HTTP API.
|
||||
type Profiler struct {
|
||||
r *mux.Router
|
||||
}
|
||||
|
||||
func (p *Profiler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
p.r.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Replicated from expvar.go as not public.
|
||||
func (p *Profiler) expVars(w http.ResponseWriter, r *http.Request) {
|
||||
func expVars(w http.ResponseWriter, r *http.Request) {
|
||||
first := true
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
fmt.Fprintf(w, "{\n")
|
||||
|
|
|
@ -1300,7 +1300,7 @@ func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, local
|
|||
func createRouter(eng *engine.Engine, logging, enableCors bool, corsHeaders string, dockerVersion string) *mux.Router {
|
||||
r := mux.NewRouter()
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
r.Handle("/debug", NewProfiler())
|
||||
ProfilerSetup(r, "/debug/")
|
||||
}
|
||||
m := map[string]map[string]HttpApiFunc{
|
||||
"GET": {
|
||||
|
|
Loading…
Add table
Reference in a new issue