Skip to content

Commit

Permalink
Remove old d3 flamegraph code and d3 dependency. (#825)
Browse files Browse the repository at this point in the history
Fixes #777.
  • Loading branch information
aalexand authored Dec 29, 2023
1 parent ec68065 commit 5aaadb5
Show file tree
Hide file tree
Showing 17 changed files with 14 additions and 1,759 deletions.
106 changes: 0 additions & 106 deletions internal/driver/flamegraph.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/driver/html/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ function viewer(baseUrl, nodes, options) {
}

const ids = ['topbtn', 'graphbtn',
'flamegraph', 'flamegraph2', 'flamegraphold',
'flamegraph',
'peek', 'list',
'disasm', 'focus', 'ignore', 'hide', 'show', 'show-from'];
ids.forEach(makeSearchLinkDynamic);
Expand Down
103 changes: 0 additions & 103 deletions internal/driver/html/flamegraph.html

This file was deleted.

1 change: 0 additions & 1 deletion internal/driver/html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ <h1><a href="./">pprof</a></h1>
<a title="{{.Help.top}}" href="./top" id="topbtn">Top</a>
<a title="{{.Help.graph}}" href="./" id="graphbtn">Graph</a>
<a title="{{.Help.flamegraph}}" href="./flamegraph" id="flamegraph">Flame Graph</a>
<a title="{{.Help.flamegraphold}}" href="./flamegraphold" id="flamegraphold">Flame Graph (old)</a>
<a title="{{.Help.peek}}" href="./peek" id="peek">Peek</a>
<a title="{{.Help.list}}" href="./source" id="list">Source</a>
<a title="{{.Help.disasm}}" href="./disasm" id="disasm">Disassemble</a>
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/google/pprof/internal/report"
)

// stackView generates the new flamegraph view.
// stackView generates the flamegraph view.
func (ui *webInterface) stackView(w http.ResponseWriter, req *http.Request) {
// Get all data in a report.
rpt, errList := ui.makeReport(w, req, []string{"svg"}, func(cfg *config) {
Expand Down
8 changes: 1 addition & 7 deletions internal/driver/webhtml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"fmt"
"html/template"
"os"

"github.com/google/pprof/third_party/d3flamegraph"
)

//go:embed html
Expand Down Expand Up @@ -52,10 +50,6 @@ func addTemplates(templates *template.Template) {
template.Must(templates.AddParseTree(name, sub.Tree))
}

// Pre-packaged third-party files.
def("d3flamegraphscript", d3flamegraph.JSSource)
def("d3flamegraphcss", d3flamegraph.CSSSource)

// Embedded files.
def("css", loadCSS("html/common.css"))
def("header", loadFile("html/header.html"))
Expand All @@ -64,7 +58,7 @@ func addTemplates(templates *template.Template) {
def("top", loadFile("html/top.html"))
def("sourcelisting", loadFile("html/source.html"))
def("plaintext", loadFile("html/plaintext.html"))
def("flamegraph", loadFile("html/flamegraph.html"))
// TODO: Rename "stacks" to "flamegraph" to seal moving off d3 flamegraph.
def("stacks", loadFile("html/stacks.html"))
def("stacks_css", loadCSS("html/stacks.css"))
def("stacks_js", loadJS("html/stacks.js"))
Expand Down
16 changes: 10 additions & 6 deletions internal/driver/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, d
ui.help["details"] = "Show information about the profile and this view"
ui.help["graph"] = "Display profile as a directed graph"
ui.help["flamegraph"] = "Display profile as a flame graph"
ui.help["flamegraphold"] = "Display profile as a flame graph (old version; slated for removal)"
ui.help["reset"] = "Show the entire profile"
ui.help["save_config"] = "Save current settings"

Expand All @@ -130,9 +129,9 @@ func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, d
"/disasm": http.HandlerFunc(ui.disasm),
"/source": http.HandlerFunc(ui.source),
"/peek": http.HandlerFunc(ui.peek),
"/flamegraphold": http.HandlerFunc(ui.flamegraph),
"/flamegraph": http.HandlerFunc(ui.stackView),
"/flamegraph2": http.HandlerFunc(ui.stackView), // Support older URL
"/flamegraph2": redirectWithQuery("flamegraph", http.StatusMovedPermanently), // Keep legacy URL working.
"/flamegraphold": redirectWithQuery("flamegraph", http.StatusMovedPermanently), // Keep legacy URL working.
"/saveconfig": http.HandlerFunc(ui.saveConfig),
"/deleteconfig": http.HandlerFunc(ui.deleteConfig),
"/download": http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -209,15 +208,20 @@ func defaultWebServer(args *plugin.HTTPServerArgs) error {
// https://github.com/google/pprof/pull/348
mux := http.NewServeMux()
mux.Handle("/ui/", http.StripPrefix("/ui", handler))
mux.Handle("/", redirectWithQuery("/ui"))
mux.Handle("/", redirectWithQuery("/ui", http.StatusTemporaryRedirect))
s := &http.Server{Handler: mux}
return s.Serve(ln)
}

func redirectWithQuery(path string) http.HandlerFunc {
// redirectWithQuery responds with a given redirect code, preserving query
// parameters in the redirect URL. It does not convert relative paths to
// absolute paths like http.Redirect does, so that HTTPServerArgs.Handlers can
// generate relative redirects that work with the external prefixing.
func redirectWithQuery(path string, code int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
pathWithQuery := &gourl.URL{Path: path, RawQuery: r.URL.RawQuery}
http.Redirect(w, r, pathWithQuery.String(), http.StatusTemporaryRedirect)
w.Header().Set("Location", pathWithQuery.String())
w.WriteHeader(code)
}
}

Expand Down
12 changes: 1 addition & 11 deletions internal/driver/webui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ func TestWebInterface(t *testing.T) {
[]string{"300ms.*F1", "200ms.*300ms.*F2"}, false},
{"/disasm?f=" + url.QueryEscape("F[12]"),
[]string{"f1:asm", "f2:asm"}, false},
{"/flamegraphold", []string{
"File: testbin",
// Check profile frame JSON is included.
`\\u0022n\\u0022:\\u0022root\\u0022`,
`\\u0022n\\u0022:\\u0022F1\\u0022`,
// Check d3-flame-graph JS is included.
`flamegraph:\(\)=>|flamegraph.*function|function.*flamegraph`,
// Check d3-flame-graph CSS is included.
".d3-flame-graph rect {",
}, false},
{"/flamegraph", []string{
"File: testbin",
// Check that interesting frames are included.
Expand Down Expand Up @@ -313,7 +303,7 @@ func TestIsLocalHost(t *testing.T) {
}

func BenchmarkTop(b *testing.B) { benchmarkURL(b, "/top", false) }
func BenchmarkFlame(b *testing.B) { benchmarkURL(b, "/flamegraph2", false) }
func BenchmarkFlame(b *testing.B) { benchmarkURL(b, "/flamegraph", false) }
func BenchmarkDot(b *testing.B) { benchmarkURL(b, "/", true) }

func benchmarkURL(b *testing.B, path string, needDot bool) {
Expand Down
Loading

0 comments on commit 5aaadb5

Please sign in to comment.