...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package driver
16
17 import (
18 "embed"
19 "fmt"
20 "html/template"
21 "os"
22
23 "github.com/google/pprof/third_party/d3flamegraph"
24 )
25
26
27 var embeddedFiles embed.FS
28
29
30 func addTemplates(templates *template.Template) {
31
32 loadFile := func(fname string) string {
33 data, err := embeddedFiles.ReadFile(fname)
34 if err != nil {
35 fmt.Fprintf(os.Stderr, "internal/driver: embedded file %q not found\n",
36 fname)
37 os.Exit(1)
38 }
39 return string(data)
40 }
41 loadCSS := func(fname string) string {
42 return `<style type="text/css">` + "\n" + loadFile(fname) + `</style>` + "\n"
43 }
44 loadJS := func(fname string) string {
45 return `<script>` + "\n" + loadFile(fname) + `</script>` + "\n"
46 }
47
48
49 def := func(name, contents string) {
50 sub := template.New(name)
51 template.Must(sub.Parse(contents))
52 template.Must(templates.AddParseTree(name, sub.Tree))
53 }
54
55
56 def("d3flamegraphscript", d3flamegraph.JSSource)
57 def("d3flamegraphcss", d3flamegraph.CSSSource)
58
59
60 def("css", loadCSS("html/common.css"))
61 def("header", loadFile("html/header.html"))
62 def("graph", loadFile("html/graph.html"))
63 def("script", loadJS("html/common.js"))
64 def("top", loadFile("html/top.html"))
65 def("sourcelisting", loadFile("html/source.html"))
66 def("plaintext", loadFile("html/plaintext.html"))
67 def("flamegraph", loadFile("html/flamegraph.html"))
68 def("stacks", loadFile("html/stacks.html"))
69 def("stacks_css", loadCSS("html/stacks.css"))
70 def("stacks_js", loadJS("html/stacks.js"))
71 }
72
View as plain text