diff --git a/internal/lsp/debug/serve.go b/internal/lsp/debug/serve.go index 43460ec733..c329b0d44f 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 }