| 1 | // Copyright 2017 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/ |
| 16 | |
| 17 | import ( |
| 18 | "embedscip-go gomod github.com/golang/go/src go1.24.0 embed/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 20 | "html/templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/" |
| 21 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 22 | "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/" |
| 23 | |
| 24 | "github.com/google/pprof/internal/reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/" |
| 25 | ) |
| 26 | |
| 27 | var ( |
| 28 | htmlTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplates. *templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template# // Lazily loaded templates |
| 29 | htmlTemplateInitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplateInit. syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.Oncescip-go gomod github.com/golang/go/src go1.24.0 sync/Once# |
| 30 | ) |
| 31 | |
| 32 | // getHTMLTemplates returns the set of HTML templates used by pprof, |
| 33 | // initializing them if necessary. |
| 34 | func getHTMLTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getHTMLTemplates().() *templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template# { |
| 35 | htmlTemplateInitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplateInit..Doscip-go gomod github.com/golang/go/src go1.24.0 sync/Once#Do().(func() { |
| 36 | htmlTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplates. = templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Newscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/New().("templategroup") |
| 37 | addTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addTemplates().(htmlTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplates.) |
| 38 | reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.AddSourceTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/AddSourceTemplates().(htmlTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplates.) |
| 39 | }) |
| 40 | return htmlTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/htmlTemplates. |
| 41 | } |
| 42 | |
| 43 | //go:embed html |
| 44 | var embeddedFilesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/embeddedFiles. embedscip-go gomod github.com/golang/go/src go1.24.0 embed/.FSscip-go gomod github.com/golang/go/src go1.24.0 embed/FS# |
| 45 | |
| 46 | // addTemplates adds a set of template definitions to templates. |
| 47 | func addTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addTemplates().(templates *templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template#) { |
| 48 | // Load specified file. |
| 49 | loadFile := func(fname string) string { |
| 50 | data, err := embeddedFilesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/embeddedFiles..ReadFilescip-go gomod github.com/golang/go/src go1.24.0 embed/FS#ReadFile().(fname) |
| 51 | if err != nil { |
| 52 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr., "internal/driver: embedded file %q not found\n", |
| 53 | fname) |
| 54 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Exitscip-go gomod github.com/golang/go/src go1.24.0 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 := templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Newscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/New().(name) |
| 68 | templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Mustscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Must().(sub.Parsescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template#Parse().(contents)) |
| 69 | templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.Mustscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Must().(templates.AddParseTreescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template#AddParseTree().(name, sub.Treescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template#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 | } |