aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go
diff options
context:
space:
mode:
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.go32
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,
})
}