From ab136c9d47137e9efce9a5142045610154871775 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Fri, 14 Jun 2019 18:31:00 -0400 Subject: [PATCH] internal/lsp: switching debug pages to not use the default mux Change-Id: I270fd1d4d44986aed6655da93e7388628f7b8b9c Reviewed-on: https://go-review.googlesource.com/c/tools/+/182467 Run-TryBot: Ian Cottrell Run-TryBot: Rebecca Stambler Reviewed-by: Rebecca Stambler --- internal/lsp/debug/serve.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/lsp/debug/serve.go b/internal/lsp/debug/serve.go index 43460ec7..c329b0d4 100644 --- a/internal/lsp/debug/serve.go +++ b/internal/lsp/debug/serve.go @@ -12,6 +12,7 @@ import ( "log" "net" "net/http" + "net/http/pprof" _ "net/http/pprof" // pull in the standard pprof handlers "path" "runtime" @@ -57,17 +58,6 @@ var ( }{} ) -func init() { - http.HandleFunc("/", Render(mainTmpl, func(*http.Request) interface{} { return data })) - http.HandleFunc("/debug/", Render(debugTmpl, nil)) - http.HandleFunc("/cache/", Render(cacheTmpl, getCache)) - http.HandleFunc("/session/", Render(sessionTmpl, getSession)) - http.HandleFunc("/view/", Render(viewTmpl, getView)) - http.HandleFunc("/file/", Render(fileTmpl, getFile)) - http.HandleFunc("/info", Render(infoTmpl, getInfo)) - http.HandleFunc("/memory", Render(memoryTmpl, getMemory)) -} - // AddCache adds a cache to the set being served func AddCache(cache Cache) { mu.Lock() @@ -223,7 +213,21 @@ func Serve(ctx context.Context, addr string) error { } log.Printf("Debug serving on port: %d", listener.Addr().(*net.TCPAddr).Port) go func() { - if err := http.Serve(listener, nil); err != nil { + mux := http.NewServeMux() + mux.HandleFunc("/", Render(mainTmpl, func(*http.Request) interface{} { return data })) + mux.HandleFunc("/debug/", Render(debugTmpl, nil)) + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + mux.HandleFunc("/cache/", Render(cacheTmpl, getCache)) + mux.HandleFunc("/session/", Render(sessionTmpl, getSession)) + mux.HandleFunc("/view/", Render(viewTmpl, getView)) + mux.HandleFunc("/file/", Render(fileTmpl, getFile)) + mux.HandleFunc("/info", Render(infoTmpl, getInfo)) + mux.HandleFunc("/memory", Render(memoryTmpl, getMemory)) + if err := http.Serve(listener, mux); err != nil { log.Printf("Debug server failed with %v", err) return }