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

Function addTemplates

internal/driver/webhtml.go:47–85  ·  view source on GitHub ↗

addTemplates adds a set of template definitions to templates.

(templates *template.Template)

Source from the content-addressed store, hash-verified

45
46// addTemplates adds a set of template definitions to templates.
47func addTemplates(templates *template.Template) {
48 // Load specified file.
49 loadFile := func(fname string) string {
50 data, err := embeddedFiles.ReadFile(fname)
51 if err != nil {
52 fmt.Fprintf(os.Stderr, "internal/driver: embedded file %q not found\n",
53 fname)
54 os.Exit(1)
55 }
56 return string(data)
57 }
58 loadCSS := func(fname string) string {
59 return `<style type="text/css">` + "\n" + loadFile(fname) + `</style>` + "\n"
60 }
61 loadJS := func(fname string) string {
62 return `<script>` + "\n" + loadFile(fname) + `</script>` + "\n"
63 }
64
65 // Define a named template with specified contents.
66 def := func(name, contents string) {
67 sub := template.New(name)
68 template.Must(sub.Parse(contents))
69 template.Must(templates.AddParseTree(name, sub.Tree))
70 }
71
72 // Embedded files.
73 def("css", loadCSS("html/common.css"))
74 def("header", loadFile("html/header.html"))
75 def("graph", loadFile("html/graph.html"))
76 def("graph_css", loadCSS("html/graph.css"))
77 def("script", loadJS("html/common.js"))
78 def("top", loadFile("html/top.html"))
79 def("sourcelisting", loadFile("html/source.html"))
80 def("plaintext", loadFile("html/plaintext.html"))
81 // TODO: Rename "stacks" to "flamegraph" to seal moving off d3 flamegraph.
82 def("stacks", loadFile("html/stacks.html"))
83 def("stacks_css", loadCSS("html/stacks.css"))
84 def("stacks_js", loadJS("html/stacks.js"))
85}

Callers 1

getHTMLTemplatesFunction · 0.85

Calls 1

ParseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…