aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2018-02-12 16:34:48 +0000
committerDaniel Martí <mvdan@mvdan.cc>2018-02-15 16:25:43 +0000
commite7cbbbe9bb878b6ca4ce04fde645df1c8f1845bd (patch)
treef84255198234eb4870c48228cdb4828de1f4f8c5 /src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go
parentafb9fc1de922a4ead9d2d787613255a7ba3490f7 (diff)
downloadgo-e7cbbbe9bb878b6ca4ce04fde645df1c8f1845bd.tar.xz
cmd/vendor/github.com/google/pprof: refresh from upstream
Updating to commit 0e0e5b7254e076a62326ab7305ba49e8515f0c91 from github.com/google/pprof Recent modifications to the vendored pprof, such as skipping TestWebInterface to avoid starting a web browser, have all been fixed upstream. Change-Id: I72e11108c438e1573bf2f9216e76d157378e8d45 Reviewed-on: https://go-review.googlesource.com/93375 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go')
-rw-r--r--src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go79
1 files changed, 51 insertions, 28 deletions
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go
index 67ae262882..20d4e025f4 100644
--- a/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go
+++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/webui.go
@@ -69,31 +69,24 @@ func (ec *errorCatcher) PrintErr(args ...interface{}) {
// webArgs contains arguments passed to templates in webhtml.go.
type webArgs struct {
- BaseURL string
- Title string
- Errors []string
- Total int64
- Legend []string
- Help map[string]string
- Nodes []string
- HTMLBody template.HTML
- TextBody string
- Top []report.TextItem
+ BaseURL string
+ Title string
+ Errors []string
+ Total int64
+ Legend []string
+ Help map[string]string
+ Nodes []string
+ HTMLBody template.HTML
+ TextBody string
+ Top []report.TextItem
+ FlameGraph template.JS
}
-func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options) error {
- host, portStr, err := net.SplitHostPort(hostport)
- if err != nil {
- return fmt.Errorf("could not split http address: %v", err)
- }
- port, err := strconv.Atoi(portStr)
+func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, wantBrowser bool) error {
+ host, port, err := getHostAndPort(hostport)
if err != nil {
- return fmt.Errorf("invalid port number: %v", err)
- }
- if host == "" {
- host = "localhost"
+ return err
}
-
interactiveMode = true
ui := makeWebInterface(p, o)
for n, c := range pprofCommands {
@@ -111,22 +104,52 @@ func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options) e
server = defaultWebServer
}
args := &plugin.HTTPServerArgs{
- Hostport: net.JoinHostPort(host, portStr),
+ Hostport: net.JoinHostPort(host, strconv.Itoa(port)),
Host: host,
Port: port,
Handlers: map[string]http.Handler{
- "/": http.HandlerFunc(ui.dot),
- "/top": http.HandlerFunc(ui.top),
- "/disasm": http.HandlerFunc(ui.disasm),
- "/source": http.HandlerFunc(ui.source),
- "/peek": http.HandlerFunc(ui.peek),
+ "/": http.HandlerFunc(ui.dot),
+ "/top": http.HandlerFunc(ui.top),
+ "/disasm": http.HandlerFunc(ui.disasm),
+ "/source": http.HandlerFunc(ui.source),
+ "/peek": http.HandlerFunc(ui.peek),
+ "/flamegraph": http.HandlerFunc(ui.flamegraph),
},
}
- go openBrowser("http://"+args.Hostport, o)
+ if wantBrowser {
+ go openBrowser("http://"+args.Hostport, o)
+ }
return server(args)
}
+func getHostAndPort(hostport string) (string, int, error) {
+ host, portStr, err := net.SplitHostPort(hostport)
+ if err != nil {
+ return "", 0, fmt.Errorf("could not split http address: %v", err)
+ }
+ if host == "" {
+ host = "localhost"
+ }
+ var port int
+ if portStr == "" {
+ ln, err := net.Listen("tcp", net.JoinHostPort(host, "0"))
+ if err != nil {
+ return "", 0, fmt.Errorf("could not generate random port: %v", err)
+ }
+ port = ln.Addr().(*net.TCPAddr).Port
+ err = ln.Close()
+ if err != nil {
+ return "", 0, fmt.Errorf("could not generate random port: %v", err)
+ }
+ } else {
+ port, err = strconv.Atoi(portStr)
+ if err != nil {
+ return "", 0, fmt.Errorf("invalid port number: %v", err)
+ }
+ }
+ return host, port, nil
+}
func defaultWebServer(args *plugin.HTTPServerArgs) error {
ln, err := net.Listen("tcp", args.Hostport)
if err != nil {