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

Function serveWebInterface

internal/driver/webui.go:98–156  ·  view source on GitHub ↗
(hostport string, p *profile.Profile, o *plugin.Options, disableBrowser bool)

Source from the content-addressed store, hash-verified

96}
97
98func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, disableBrowser bool) error {
99 host, port, err := getHostAndPort(hostport)
100 if err != nil {
101 return err
102 }
103 interactiveMode = true
104 copier := makeProfileCopier(p)
105 ui, err := makeWebInterface(p, copier, o)
106 if err != nil {
107 return err
108 }
109 for n, c := range pprofCommands {
110 ui.help[n] = c.description
111 }
112 maps.Copy(ui.help, configHelp)
113 ui.help["details"] = "Show information about the profile and this view"
114 ui.help["graph"] = "Display profile as a directed graph"
115 ui.help["flamegraph"] = "Display profile as a flame graph"
116 ui.help["reset"] = "Show the entire profile"
117 ui.help["save_config"] = "Save current settings"
118
119 server := o.HTTPServer
120 if server == nil {
121 server = defaultWebServer
122 }
123 args := &plugin.HTTPServerArgs{
124 Hostport: net.JoinHostPort(host, strconv.Itoa(port)),
125 Host: host,
126 Port: port,
127 Handlers: map[string]http.Handler{
128 "/": redirectWithQuery("flamegraph", http.StatusMovedPermanently),
129 "/graph": http.HandlerFunc(ui.dot),
130 "/top": http.HandlerFunc(ui.top),
131 "/disasm": http.HandlerFunc(ui.disasm),
132 "/source": http.HandlerFunc(ui.source),
133 "/peek": http.HandlerFunc(ui.peek),
134 "/flamegraph": http.HandlerFunc(ui.stackView),
135 "/saveconfig": http.HandlerFunc(ui.saveConfig),
136 "/deleteconfig": http.HandlerFunc(ui.deleteConfig),
137 "/download": http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
138 w.Header().Set("Content-Type", "application/vnd.google.protobuf+gzip")
139 w.Header().Set("Content-Disposition", "attachment;filename=profile.pb.gz")
140 p.Write(w)
141 }),
142 // Keep legacy URLs working.
143 "/flamegraph2": redirectWithQuery("flamegraph", http.StatusMovedPermanently),
144 "/flamegraphold": redirectWithQuery("flamegraph", http.StatusMovedPermanently),
145 },
146 }
147
148 url := "http://" + args.Hostport
149
150 o.UI.Print("Serving web UI on ", url)
151
152 if o.UI.WantBrowser() && !disableBrowser {
153 go openBrowser(url, o)
154 }
155 return server(args)

Callers 2

PProfFunction · 0.85
makeTestServerFunction · 0.85

Calls 9

getHostAndPortFunction · 0.85
makeProfileCopierFunction · 0.85
makeWebInterfaceFunction · 0.85
redirectWithQueryFunction · 0.85
openBrowserFunction · 0.85
CopyMethod · 0.80
WriteMethod · 0.80
PrintMethod · 0.65
WantBrowserMethod · 0.65

Tested by 1

makeTestServerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…