internal/lsp/debug: add links to profiles and GC

This change adds to the memstats page a button to run the GC
and reload the stats. It also adds the missing navigation
link to the menu of pprof profile types.

Change-Id: Icf91111ce6e253cd2040725a0b86178209ebec1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/498558
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/lsp/debug/serve.go b/gopls/internal/lsp/debug/serve.go
index f36a238..bc60fba 100644
--- a/gopls/internal/lsp/debug/serve.go
+++ b/gopls/internal/lsp/debug/serve.go
@@ -460,11 +460,11 @@
 		mux.HandleFunc("/memory", render(MemoryTmpl, getMemory))
 
 		// Internal debugging helpers.
-		mux.HandleFunc("/_dogc", func(w http.ResponseWriter, r *http.Request) {
+		mux.HandleFunc("/gc", func(w http.ResponseWriter, r *http.Request) {
 			runtime.GC()
 			runtime.GC()
 			runtime.GC()
-			http.Error(w, "OK", 200)
+			http.Redirect(w, r, "/memory", http.StatusTemporaryRedirect)
 		})
 		mux.HandleFunc("/_makeabug", func(w http.ResponseWriter, r *http.Request) {
 			bug.Report("bug here")
@@ -647,6 +647,7 @@
 <a href="/">Main</a>
 <a href="/info">Info</a>
 <a href="/memory">Memory</a>
+<a href="/debug/pprof">Profiling</a>
 <a href="/metrics">Metrics</a>
 <a href="/rpc">RPC</a>
 <a href="/trace">Trace</a>
@@ -716,9 +717,10 @@
 `))
 
 var MemoryTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
-{{define "title"}}GoPls memory usage{{end}}
+{{define "title"}}Gopls memory usage{{end}}
 {{define "head"}}<meta http-equiv="refresh" content="5">{{end}}
 {{define "body"}}
+<form action="/gc"><input type="submit" value="Run garbage collector"/></form>
 <h2>Stats</h2>
 <table>
 <tr><td class="label">Allocated bytes</td><td class="value">{{fuint64 .HeapAlloc}}</td></tr>