MCPcopy Create free account
hub / github.com/google/pprof / dot

Method dot

internal/driver/webui.go:313–345  ·  view source on GitHub ↗

dot generates a web page containing an svg diagram.

(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

311
312// dot generates a web page containing an svg diagram.
313func (ui *webInterface) dot(w http.ResponseWriter, req *http.Request) {
314 rpt, errList := ui.makeReport(w, req, []string{"svg"}, nil)
315 if rpt == nil {
316 return // error already reported
317 }
318
319 // Generate dot graph.
320 g, config := report.GetDOT(rpt)
321 legend := config.Labels
322 config.Labels = nil
323 dot := &bytes.Buffer{}
324 graph.ComposeDot(dot, g, &graph.DotAttributes{}, config)
325
326 // Convert to svg.
327 svg, err := dotToSvg(dot.Bytes())
328 if err != nil {
329 http.Error(w, "Could not execute dot; may need to install graphviz.",
330 http.StatusNotImplemented)
331 ui.options.UI.PrintErr("Failed to execute dot. Is Graphviz installed?\n", err)
332 return
333 }
334
335 // Get all node names into an array.
336 nodes := []string{""} // dot starts with node numbered 1
337 for _, n := range g.Nodes {
338 nodes = append(nodes, n.Info.Name)
339 }
340
341 ui.render(w, req, "graph", rpt, errList, legend, webArgs{
342 HTMLBody: template.HTML(string(svg)),
343 Nodes: nodes,
344 })
345}
346
347func dotToSvg(dot []byte) ([]byte, error) {
348 cmd := exec.Command("dot", "-Tsvg")

Callers

nothing calls this directly

Calls 6

makeReportMethod · 0.95
renderMethod · 0.95
GetDOTFunction · 0.92
ComposeDotFunction · 0.92
dotToSvgFunction · 0.85
PrintErrMethod · 0.65

Tested by

no test coverage detected