Skip to content

Commit 5f74ec7

Browse files
committed
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 <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent ed90c6d commit 5f74ec7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

gopls/internal/lsp/debug/serve.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@ func (i *Instance) Serve(ctx context.Context, addr string) (string, error) {
460460
mux.HandleFunc("/memory", render(MemoryTmpl, getMemory))
461461

462462
// Internal debugging helpers.
463-
mux.HandleFunc("/_dogc", func(w http.ResponseWriter, r *http.Request) {
463+
mux.HandleFunc("/gc", func(w http.ResponseWriter, r *http.Request) {
464464
runtime.GC()
465465
runtime.GC()
466466
runtime.GC()
467-
http.Error(w, "OK", 200)
467+
http.Redirect(w, r, "/memory", http.StatusTemporaryRedirect)
468468
})
469469
mux.HandleFunc("/_makeabug", func(w http.ResponseWriter, r *http.Request) {
470470
bug.Report("bug here")
@@ -647,6 +647,7 @@ ul.spans {
647647
<a href="/">Main</a>
648648
<a href="/info">Info</a>
649649
<a href="/memory">Memory</a>
650+
<a href="/debug/pprof">Profiling</a>
650651
<a href="/metrics">Metrics</a>
651652
<a href="/rpc">RPC</a>
652653
<a href="/trace">Trace</a>
@@ -716,9 +717,10 @@ var InfoTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
716717
`))
717718

718719
var MemoryTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
719-
{{define "title"}}GoPls memory usage{{end}}
720+
{{define "title"}}Gopls memory usage{{end}}
720721
{{define "head"}}<meta http-equiv="refresh" content="5">{{end}}
721722
{{define "body"}}
723+
<form action="/gc"><input type="submit" value="Run garbage collector"/></form>
722724
<h2>Stats</h2>
723725
<table>
724726
<tr><td class="label">Allocated bytes</td><td class="value">{{fuint64 .HeapAlloc}}</td></tr>

0 commit comments

Comments
 (0)