Skip to content

Commit 7105216

Browse files
committed
cmd/trace/v2: add support for task and region endpoints
This change fills out the last of cmd/trace's subpages for v2 traces by adding support for task and region endpoints. For #60773. For #63960. Change-Id: Ifc4c660514b3904788785a1b20e3abc3bb9e55f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/542077 Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7e32d8d commit 7105216

File tree

6 files changed

+1023
-93
lines changed

6 files changed

+1023
-93
lines changed

src/cmd/trace/v2/goroutines.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var templGoroutines = template.Must(template.New("").Parse(`
6767
<html>
6868
<style>` + traceviewer.CommonStyle + `
6969
table {
70-
border-collapse: collapse;
70+
border-collapse: collapse;
7171
}
7272
td,
7373
th {
@@ -259,7 +259,7 @@ var templGoroutine = template.Must(template.New("").Funcs(template.FuncMap{
259259
},
260260
}).Parse(`
261261
<!DOCTYPE html>
262-
<title>Goroutine {{.Name}}</title>
262+
<title>Goroutines: {{.Name}}</title>
263263
<style>` + traceviewer.CommonStyle + `
264264
th {
265265
background-color: #050505;
@@ -313,7 +313,7 @@ function reloadTable(key, value) {
313313
}
314314
</script>
315315
316-
<h1>Goroutine breakdown</h1>
316+
<h1>Goroutines</h1>
317317
318318
Table of contents
319319
<ul>

src/cmd/trace/v2/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
9393
mux.HandleFunc("/regionsyscall", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofSyscall(), parsed)))
9494
mux.HandleFunc("/regionsched", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofSched(), parsed)))
9595

96+
// Region endpoints.
97+
mux.HandleFunc("/userregions", UserRegionsHandlerFunc(parsed))
98+
mux.HandleFunc("/userregion", UserRegionHandlerFunc(parsed))
99+
100+
// Task endpoints.
101+
mux.HandleFunc("/usertasks", UserTasksHandlerFunc(parsed))
102+
mux.HandleFunc("/usertask", UserTaskHandlerFunc(parsed))
103+
96104
err = http.Serve(ln, mux)
97105
return fmt.Errorf("failed to start http server: %w", err)
98106
}

src/cmd/trace/v2/pprof.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"internal/trace/traceviewer"
1414
tracev2 "internal/trace/v2"
1515
"net/http"
16-
"net/url"
1716
"slices"
1817
"strconv"
1918
"strings"
@@ -344,92 +343,3 @@ func pcsForStack(stack tracev2.Stack, pcs *[pprofMaxStack]uint64) {
344343
return i < len(pcs)
345344
})
346345
}
347-
348-
func regionInterval(t *parsedTrace, s *trace.UserRegionSummary) interval {
349-
var i interval
350-
if s.Start != nil {
351-
i.start = s.Start.Time()
352-
} else {
353-
i.start = t.startTime()
354-
}
355-
if s.End != nil {
356-
i.end = s.End.Time()
357-
} else {
358-
i.end = t.endTime()
359-
}
360-
return i
361-
}
362-
363-
// regionFilter represents a region filter specified by a user of cmd/trace.
364-
type regionFilter struct {
365-
name string
366-
params url.Values
367-
cond []func(*parsedTrace, *trace.UserRegionSummary) bool
368-
}
369-
370-
// match returns true if a region, described by its ID and summary, matches
371-
// the filter.
372-
func (f *regionFilter) match(t *parsedTrace, s *trace.UserRegionSummary) bool {
373-
for _, c := range f.cond {
374-
if !c(t, s) {
375-
return false
376-
}
377-
}
378-
return true
379-
}
380-
381-
// newRegionFilter creates a new region filter from URL query variables.
382-
func newRegionFilter(r *http.Request) (*regionFilter, error) {
383-
if err := r.ParseForm(); err != nil {
384-
return nil, err
385-
}
386-
387-
var name []string
388-
var conditions []func(*parsedTrace, *trace.UserRegionSummary) bool
389-
filterParams := make(url.Values)
390-
391-
param := r.Form
392-
if typ, ok := param["type"]; ok && len(typ) > 0 {
393-
name = append(name, "type="+typ[0])
394-
conditions = append(conditions, func(_ *parsedTrace, r *trace.UserRegionSummary) bool {
395-
return r.Name == typ[0]
396-
})
397-
filterParams.Add("type", typ[0])
398-
}
399-
if pc, err := strconv.ParseUint(r.FormValue("pc"), 16, 64); err == nil {
400-
encPC := fmt.Sprintf("%x", pc)
401-
name = append(name, "pc="+encPC)
402-
conditions = append(conditions, func(_ *parsedTrace, r *trace.UserRegionSummary) bool {
403-
var regionPC uint64
404-
if r.Start != nil && r.Start.Stack() != tracev2.NoStack {
405-
r.Start.Stack().Frames(func(f tracev2.StackFrame) bool {
406-
regionPC = f.PC
407-
return false
408-
})
409-
}
410-
return regionPC == pc
411-
})
412-
filterParams.Add("pc", encPC)
413-
}
414-
415-
if lat, err := time.ParseDuration(r.FormValue("latmin")); err == nil {
416-
name = append(name, fmt.Sprintf("latency >= %s", lat))
417-
conditions = append(conditions, func(t *parsedTrace, r *trace.UserRegionSummary) bool {
418-
return regionInterval(t, r).duration() >= lat
419-
})
420-
filterParams.Add("latmin", lat.String())
421-
}
422-
if lat, err := time.ParseDuration(r.FormValue("latmax")); err == nil {
423-
name = append(name, fmt.Sprintf("latency <= %s", lat))
424-
conditions = append(conditions, func(t *parsedTrace, r *trace.UserRegionSummary) bool {
425-
return regionInterval(t, r).duration() <= lat
426-
})
427-
filterParams.Add("latmax", lat.String())
428-
}
429-
430-
return &regionFilter{
431-
name: strings.Join(name, ","),
432-
cond: conditions,
433-
params: filterParams,
434-
}, nil
435-
}

0 commit comments

Comments
 (0)