diff options
| author | Emmanuel T Odeke <emmanuel@orijtech.com> | 2024-05-27 21:07:22 -0600 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-05-31 19:48:28 +0000 |
| commit | 9b43bfbc51c469ec13fca24960834a75b2bf66eb (patch) | |
| tree | cafe177d5e024ae1a903f9c69824ed99ee673082 /src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go | |
| parent | 00b8071a12e298303b2f4bd0e9f641ef3e54772a (diff) | |
| download | go-9b43bfbc51c469ec13fca24960834a75b2bf66eb.tar.xz | |
cmd/vendor: update github.com/google/pprof
Brings in the latest github.com/google/pprof.
Fixes #67626
Change-Id: Id8faef20f0a9bf81dd117110bf540aca852db6be
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/588655
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go')
| -rw-r--r-- | src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go index 476e1d2cdf..2a2d7fb1d2 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" "html/template" + "io" "net" "net/http" gourl "net/url" @@ -28,6 +29,7 @@ import ( "time" "github.com/google/pprof/internal/graph" + "github.com/google/pprof/internal/measurement" "github.com/google/pprof/internal/plugin" "github.com/google/pprof/internal/report" "github.com/google/pprof/profile" @@ -39,7 +41,6 @@ type webInterface struct { copier profileCopier options *plugin.Options help map[string]string - templates *template.Template settingsFile string } @@ -48,15 +49,11 @@ func makeWebInterface(p *profile.Profile, copier profileCopier, opt *plugin.Opti if err != nil { return nil, err } - templates := template.New("templategroup") - addTemplates(templates) - report.AddSourceTemplates(templates) return &webInterface{ prof: p, copier: copier, options: opt, help: make(map[string]string), - templates: templates, settingsFile: settingsFile, }, nil } @@ -82,14 +79,17 @@ type webArgs struct { Total int64 SampleTypes []string Legend []string + Standalone bool // True for command-line generation of HTML Help map[string]string Nodes []string HTMLBody template.HTML TextBody string Top []report.TextItem + Listing report.WebListData FlameGraph template.JS Stacks template.JS Configs []configMenuEntry + UnitDefs []measurement.UnitType } func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, disableBrowser bool) error { @@ -283,21 +283,25 @@ func (ui *webInterface) makeReport(w http.ResponseWriter, req *http.Request, return rpt, catcher.errors } -// render generates html using the named template based on the contents of data. -func (ui *webInterface) render(w http.ResponseWriter, req *http.Request, tmpl string, - rpt *report.Report, errList, legend []string, data webArgs) { +// renderHTML generates html using the named template based on the contents of data. +func renderHTML(dst io.Writer, tmpl string, rpt *report.Report, errList, legend []string, data webArgs) error { file := getFromLegend(legend, "File: ", "unknown") profile := getFromLegend(legend, "Type: ", "unknown") data.Title = file + " " + profile data.Errors = errList data.Total = rpt.Total() - data.SampleTypes = sampleTypes(ui.prof) data.Legend = legend + return getHTMLTemplates().ExecuteTemplate(dst, tmpl, data) +} + +// render responds with html generated by passing data to the named template. +func (ui *webInterface) render(w http.ResponseWriter, req *http.Request, tmpl string, + rpt *report.Report, errList, legend []string, data webArgs) { + data.SampleTypes = sampleTypes(ui.prof) data.Help = ui.help data.Configs = configMenu(ui.settingsFile, *req.URL) - html := &bytes.Buffer{} - if err := ui.templates.ExecuteTemplate(html, tmpl, data); err != nil { + if err := renderHTML(html, tmpl, rpt, errList, legend, data); err != nil { http.Error(w, "internal template error", http.StatusInternalServerError) ui.options.UI.PrintErr(err) return @@ -410,8 +414,8 @@ func (ui *webInterface) source(w http.ResponseWriter, req *http.Request) { } // Generate source listing. - var body bytes.Buffer - if err := report.PrintWebList(&body, rpt, ui.options.Obj, maxEntries); err != nil { + listing, err := report.MakeWebList(rpt, ui.options.Obj, maxEntries) + if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) ui.options.UI.PrintErr(err) return @@ -419,7 +423,7 @@ func (ui *webInterface) source(w http.ResponseWriter, req *http.Request) { legend := report.ProfileLabels(rpt) ui.render(w, req, "sourcelisting", rpt, errList, legend, webArgs{ - HTMLBody: template.HTML(body.String()), + Listing: listing, }) } |
