Skip to content

Commit

Permalink
internal/debug: show new View information in the debug page
Browse files Browse the repository at this point in the history
Add View Type, EnvOverlay, and Root to the view debug page. Also inline
the View debug page into the Session debug page, to save a click.

For golang/go#57979

Change-Id: Id6fbf86a55329078adcada049e34607ee918da11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/555197
Auto-Submit: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Jan 12, 2024
1 parent b37fde9 commit 54cf5bc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
39 changes: 25 additions & 14 deletions gopls/internal/debug/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ func (i *Instance) Serve(ctx context.Context, addr string) (string, error) {
mux.HandleFunc("/analysis/", render(AnalysisTmpl, i.getAnalysis))
mux.HandleFunc("/cache/", render(CacheTmpl, i.getCache))
mux.HandleFunc("/session/", render(SessionTmpl, i.getSession))
mux.HandleFunc("/view/", render(ViewTmpl, i.getView))
mux.HandleFunc("/client/", render(ClientTmpl, i.getClient))
mux.HandleFunc("/server/", render(ServerTmpl, i.getServer))
mux.HandleFunc("/file/", render(FileTmpl, i.getFile))
Expand Down Expand Up @@ -644,12 +643,17 @@ var BaseTemplate = template.Must(template.New("").Parse(`
width:6rem;
}
td.value {
text-align: right;
text-align: right;
}
ul.spans {
font-family: monospace;
font-size: 85%;
}
body {
font-family: sans-serif;
font-size: 1rem;
line-height: normal;
}
</style>
{{block "head" .}}{{end}}
</head>
Expand All @@ -674,7 +678,6 @@ Unknown page
{{define "clientlink"}}<a href="/client/{{.}}">Client {{.}}</a>{{end}}
{{define "serverlink"}}<a href="/server/{{.}}">Server {{.}}</a>{{end}}
{{define "sessionlink"}}<a href="/session/{{.}}">Session {{.}}</a>{{end}}
{{define "viewlink"}}<a href="/view/{{.}}">View {{.}}</a>{{end}}
`)).Funcs(template.FuncMap{
"fuint64": fuint64,
"fuint32": fuint32,
Expand Down Expand Up @@ -706,7 +709,7 @@ Unknown page
})

var MainTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
{{define "title"}}GoPls server information{{end}}
{{define "title"}}Gopls server information{{end}}
{{define "body"}}
<h2>Caches</h2>
<ul>{{range .State.Caches}}<li>{{template "cachelink" .ID}}</li>{{end}}</ul>
Expand All @@ -722,7 +725,7 @@ var MainTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
`))

var InfoTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
{{define "title"}}GoPls version information{{end}}
{{define "title"}}Gopls version information{{end}}
{{define "body"}}
{{.}}
{{end}}
Expand Down Expand Up @@ -771,6 +774,13 @@ var CacheTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
{{define "body"}}
<h2>memoize.Store entries</h2>
<ul>{{range $k,$v := .MemStats}}<li>{{$k}} - {{$v}}</li>{{end}}</ul>
<h2>File stats</h2>
<p>
{{- $stats := .FileStats -}}
Total: <b>{{$stats.Total}}</b><br>
Largest: <b>{{$stats.Largest}}</b><br>
Errors: <b>{{$stats.Errs}}</b><br>
</p>
{{end}}
`))

Expand Down Expand Up @@ -806,7 +816,16 @@ var SessionTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
{{define "body"}}
From: <b>{{template "cachelink" .Cache.ID}}</b><br>
<h2>Views</h2>
<ul>{{range .Views}}<li>{{.Folder.Name}} is {{template "viewlink" .ID}} in {{.Folder.Dir}}</li>{{end}}</ul>
<ul>{{range .Views}}
{{- $envOverlay := .EnvOverlay -}}
<li>ID: <b>{{.ID}}</b><br>
Type: <b>{{.Type}}</b><br>
Root: <b>{{.Root}}</b><br>
{{- if $envOverlay}}
Env overlay: <b>{{$envOverlay}})</b><br>
{{end -}}
Folder: <b>{{.Folder.Name}}:{{.Folder.Dir}}</b></li>
{{end}}</ul>
<h2>Overlays</h2>
{{$session := .}}
<ul>{{range .Overlays}}
Expand All @@ -816,14 +835,6 @@ From: <b>{{template "cachelink" .Cache.ID}}</b><br>
{{end}}
`))

var ViewTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
{{define "title"}}View {{.ID}}{{end}}
{{define "body"}}
Name: <b>{{.Folder.Name}}</b><br>
Folder: <b>{{.Folder.Dir}}</b><br>
{{end}}
`))

var FileTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
{{define "title"}}Overlay {{.Identity.Hash}}{{end}}
{{define "body"}}
Expand Down
1 change: 0 additions & 1 deletion gopls/internal/debug/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var templates = map[string]struct {
"TraceTmpl": {debug.TraceTmpl, debug.TraceResults{}},
"CacheTmpl": {debug.CacheTmpl, &cache.Cache{}},
"SessionTmpl": {debug.SessionTmpl, &cache.Session{}},
"ViewTmpl": {debug.ViewTmpl, &cache.View{}},
"ClientTmpl": {debug.ClientTmpl, &debug.Client{}},
"ServerTmpl": {debug.ServerTmpl, &debug.Server{}},
"FileTmpl": {debug.FileTmpl, &cache.Overlay{}},
Expand Down
6 changes: 4 additions & 2 deletions gopls/internal/lsp/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"

"golang.org/x/tools/gopls/internal/lsp/command"
"golang.org/x/tools/gopls/internal/lsp/protocol"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/gocommand"
Expand Down Expand Up @@ -76,6 +77,7 @@ func (c *Cache) MemStats() map[reflect.Type]int { return c.store.Stats() }

// FileStats returns information about the set of files stored in the cache.
// It is intended for debugging only.
func (c *Cache) FileStats() (files, largest, errs int) {
return c.fileStats()
func (c *Cache) FileStats() (stats command.FileStats) {
stats.Total, stats.Largest, stats.Errs = c.fileStats()
return
}
2 changes: 1 addition & 1 deletion gopls/internal/server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ func (c *commandHandler) MemStats(ctx context.Context) (command.MemStatsResult,
// about the current state of the loaded workspace for the current session.
func (c *commandHandler) WorkspaceStats(ctx context.Context) (command.WorkspaceStatsResult, error) {
var res command.WorkspaceStatsResult
res.Files.Total, res.Files.Largest, res.Files.Errs = c.s.session.Cache().FileStats()
res.Files = c.s.session.Cache().FileStats()

for _, view := range c.s.session.Views() {
vs, err := collectViewStats(ctx, view)
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/test/integration/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestStartDebugging(t *testing.T) {
if err != nil {
t.Fatalf("reading HTTP response body: %v", err)
}
const want = "<title>GoPls"
const want = "<title>Gopls"
if !strings.Contains(string(data), want) {
t.Errorf("GET %s response does not contain %q: <<%s>>", debugURL, want, data)
}
Expand Down

0 comments on commit 54cf5bc

Please sign in to comment.