From: Rohith Ravi Date: Sun, 19 Apr 2020 02:21:15 +0000 (+0000) Subject: cmd/trace: fix the broken link in region pages and improve UX X-Git-Tag: go1.15beta1~466 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=af55060b39d2f6f39711abc95a23bd8f47968e8e;p=gostls13.git cmd/trace: fix the broken link in region pages and improve UX The trace tool had a broken link due to a parameter encoding error, which has been corrected. In addition: - the user regions page has been enhanced to include links to pprof style profiles for region specific io, block, syscall and schedwait profiles. - sortable table headers have a pointer cursor to indicate they're clickable. Fixes #38518 Change-Id: I26cd5157bd9753750f5f53ea03aac5d2d41b021c Reviewed-on: https://go-review.googlesource.com/c/go/+/228899 Reviewed-by: Hyang-Ah Hana Kim --- diff --git a/src/cmd/trace/annotations.go b/src/cmd/trace/annotations.go index 817ed0d4a2..9b45457436 100644 --- a/src/cmd/trace/annotations.go +++ b/src/cmd/trace/annotations.go @@ -12,6 +12,7 @@ import ( "log" "math" "net/http" + "net/url" "reflect" "sort" "strconv" @@ -146,10 +147,12 @@ func httpUserRegion(w http.ResponseWriter, r *http.Request) { MaxTotal int64 Data []regionDesc Name string + Filter *regionFilter }{ MaxTotal: maxTotal, Data: data, Name: filter.name, + Filter: filter, }) if err != nil { http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError) @@ -748,8 +751,9 @@ func taskMatches(t *taskDesc, text string) bool { } type regionFilter struct { - name string - cond []func(regionTypeID, regionDesc) bool + name string + params url.Values + cond []func(regionTypeID, regionDesc) bool } func (f *regionFilter) match(id regionTypeID, s regionDesc) bool { @@ -768,6 +772,7 @@ func newRegionFilter(r *http.Request) (*regionFilter, error) { var name []string var conditions []func(regionTypeID, regionDesc) bool + filterParams := make(url.Values) param := r.Form if typ, ok := param["type"]; ok && len(typ) > 0 { @@ -775,12 +780,15 @@ func newRegionFilter(r *http.Request) (*regionFilter, error) { conditions = append(conditions, func(id regionTypeID, s regionDesc) bool { return id.Type == typ[0] }) + filterParams.Add("type", typ[0]) } if pc, err := strconv.ParseUint(r.FormValue("pc"), 16, 64); err == nil { - name = append(name, fmt.Sprintf("pc=%x", pc)) + encPC := fmt.Sprintf("%x", pc) + name = append(name, "pc="+encPC) conditions = append(conditions, func(id regionTypeID, s regionDesc) bool { return id.Frame.PC == pc }) + filterParams.Add("pc", encPC) } if lat, err := time.ParseDuration(r.FormValue("latmin")); err == nil { @@ -788,15 +796,21 @@ func newRegionFilter(r *http.Request) (*regionFilter, error) { conditions = append(conditions, func(_ regionTypeID, s regionDesc) bool { return s.duration() >= lat }) + filterParams.Add("latmin", lat.String()) } if lat, err := time.ParseDuration(r.FormValue("latmax")); err == nil { name = append(name, fmt.Sprintf("latency <= %s", lat)) conditions = append(conditions, func(_ regionTypeID, s regionDesc) bool { return s.duration() <= lat }) + filterParams.Add("latmax", lat.String()) } - return ®ionFilter{name: strings.Join(name, ","), cond: conditions}, nil + return ®ionFilter{ + name: strings.Join(name, ","), + cond: conditions, + params: filterParams, + }, nil } type durationHistogram struct { @@ -946,7 +960,7 @@ var templUserRegionTypes = template.Must(template.New("").Parse(` {{range $}} {{.Type}}
{{.Frame.Fn}}
{{.Frame.File}}:{{.Frame.Line}} - {{.Histogram.Count}} + {{.Histogram.Count}} {{.Histogram.ToHTML (.UserRegionURL)}} {{end}} @@ -1181,14 +1195,27 @@ var templUserRegionType = template.Must(template.New("").Funcs(template.FuncMap{ } return 0 }, + "filterParams": func(f *regionFilter) template.URL { + return template.URL(f.params.Encode()) + }, }).Parse(` -Goroutine {{.Name}} +User Region {{.Name}}