Skip to content

Commit

Permalink
internal/lsp/debug: add links to profiles and GC
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
adonovan committed May 26, 2023
1 parent ed90c6d commit 5f74ec7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gopls/internal/lsp/debug/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ func (i *Instance) Serve(ctx context.Context, addr string) (string, error) {
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")
Expand Down Expand Up @@ -647,6 +647,7 @@ ul.spans {
<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>
Expand Down Expand Up @@ -716,9 +717,10 @@ var InfoTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
`))

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>
Expand Down

0 comments on commit 5f74ec7

Please sign in to comment.