1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package driver
16
17 import (
18 "encoding/json"
19 "html/template"
20 "net/http"
21
22 "github.com/google/pprof/internal/measurement"
23 "github.com/google/pprof/internal/report"
24 )
25
26
27 func (ui *webInterface) stackView(w http.ResponseWriter, req *http.Request) {
28
29 rpt, errList := ui.makeReport(w, req, []string{"svg"}, func(cfg *config) {
30 cfg.CallTree = true
31 cfg.Trim = false
32 cfg.Granularity = "filefunctions"
33 })
34 if rpt == nil {
35 return
36 }
37
38
39 stacks := rpt.Stacks()
40 b, err := json.Marshal(stacks)
41 if err != nil {
42 http.Error(w, "error serializing stacks for flame graph",
43 http.StatusInternalServerError)
44 ui.options.UI.PrintErr(err)
45 return
46 }
47
48 nodes := make([]string, len(stacks.Sources))
49 for i, src := range stacks.Sources {
50 nodes[i] = src.FullName
51 }
52 nodes[0] = ""
53
54 _, legend := report.TextItems(rpt)
55 ui.render(w, req, "stacks", rpt, errList, legend, webArgs{
56 Stacks: template.JS(b),
57 Nodes: nodes,
58 UnitDefs: measurement.UnitTypes,
59 })
60 }
61
View as plain text