mirror of https://github.com/google/pprof.git
Add option to disable browser in HTTP mode (#462)
parent
2ef8d84b2e
commit
77426154d5
|
@ -13,3 +13,4 @@ Tipp Moseley <tipp@google.com>
|
|||
Hyoun Kyu Cho <netforce@google.com>
|
||||
Martin Spier <spiermar@gmail.com>
|
||||
Taco de Wolff <tacodewolff@gmail.com>
|
||||
Andrew Hunter <andrewhhunter@gmail.com>
|
||||
|
|
|
@ -32,11 +32,12 @@ type source struct {
|
|||
DiffBase bool
|
||||
Normalize bool
|
||||
|
||||
Seconds int
|
||||
Timeout int
|
||||
Symbolize string
|
||||
HTTPHostport string
|
||||
Comment string
|
||||
Seconds int
|
||||
Timeout int
|
||||
Symbolize string
|
||||
HTTPHostport string
|
||||
HTTPDisableBrowser bool
|
||||
Comment string
|
||||
}
|
||||
|
||||
// parseFlags parses the command lines through the specified flags package
|
||||
|
@ -65,7 +66,8 @@ func parseFlags(o *plugin.Options) (*source, []string, error) {
|
|||
flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region")
|
||||
flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames")
|
||||
|
||||
flagHTTP := flag.String("http", "", "Present interactive web based UI at the specified http host:port")
|
||||
flagHTTP := flag.String("http", "", "Present interactive web UI at the specified http host:port")
|
||||
flagNoBrowser := flag.Bool("no_browser", false, "Skip opening a browswer for the interactive web UI")
|
||||
|
||||
// Flags used during command processing
|
||||
installedFlags := installFlags(flag)
|
||||
|
@ -118,6 +120,10 @@ func parseFlags(o *plugin.Options) (*source, []string, error) {
|
|||
return nil, nil, errors.New("-http is not compatible with an output format on the command line")
|
||||
}
|
||||
|
||||
if *flagNoBrowser && *flagHTTP == "" {
|
||||
return nil, nil, errors.New("-no_browser only makes sense with -http")
|
||||
}
|
||||
|
||||
si := pprofVariables["sample_index"].value
|
||||
si = sampleIndex(flagTotalDelay, si, "delay", "-total_delay", o.UI)
|
||||
si = sampleIndex(flagMeanDelay, si, "delay", "-mean_delay", o.UI)
|
||||
|
@ -133,14 +139,15 @@ func parseFlags(o *plugin.Options) (*source, []string, error) {
|
|||
}
|
||||
|
||||
source := &source{
|
||||
Sources: args,
|
||||
ExecName: execName,
|
||||
BuildID: *flagBuildID,
|
||||
Seconds: *flagSeconds,
|
||||
Timeout: *flagTimeout,
|
||||
Symbolize: *flagSymbolize,
|
||||
HTTPHostport: *flagHTTP,
|
||||
Comment: *flagAddComment,
|
||||
Sources: args,
|
||||
ExecName: execName,
|
||||
BuildID: *flagBuildID,
|
||||
Seconds: *flagSeconds,
|
||||
Timeout: *flagTimeout,
|
||||
Symbolize: *flagSymbolize,
|
||||
HTTPHostport: *flagHTTP,
|
||||
HTTPDisableBrowser: *flagNoBrowser,
|
||||
Comment: *flagAddComment,
|
||||
}
|
||||
|
||||
if err := source.addBaseProfiles(*flagBase, *flagDiffBase); err != nil {
|
||||
|
@ -327,9 +334,10 @@ var usageMsgSrc = "\n\n" +
|
|||
|
||||
var usageMsgVars = "\n\n" +
|
||||
" Misc options:\n" +
|
||||
" -http Provide web based interface at host:port.\n" +
|
||||
" -http Provide web interface at host:port.\n" +
|
||||
" Host is optional and 'localhost' by default.\n" +
|
||||
" Port is optional and a randomly available port by default.\n" +
|
||||
" -no_browser Skip opening a browser for the interactive web UI.\n" +
|
||||
" -tools Search path for object tools\n" +
|
||||
"\n" +
|
||||
" Legacy convenience options:\n" +
|
||||
|
|
|
@ -54,7 +54,7 @@ func PProf(eo *plugin.Options) error {
|
|||
}
|
||||
|
||||
if src.HTTPHostport != "" {
|
||||
return serveWebInterface(src.HTTPHostport, p, o)
|
||||
return serveWebInterface(src.HTTPHostport, p, o, src.HTTPDisableBrowser)
|
||||
}
|
||||
return interactive(p, o)
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ type webArgs struct {
|
|||
FlameGraph template.JS
|
||||
}
|
||||
|
||||
func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options) error {
|
||||
func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, disableBrowser bool) error {
|
||||
host, port, err := getHostAndPort(hostport)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -117,8 +117,12 @@ func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options) e
|
|||
},
|
||||
}
|
||||
|
||||
if o.UI.WantBrowser() {
|
||||
go openBrowser("http://"+args.Hostport, o)
|
||||
url := "http://" + args.Hostport
|
||||
|
||||
o.UI.Print("Serving web UI on ", url)
|
||||
|
||||
if o.UI.WantBrowser() && !disableBrowser {
|
||||
go openBrowser(url, o)
|
||||
}
|
||||
return server(args)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestWebInterface(t *testing.T) {
|
|||
Obj: fakeObjTool{},
|
||||
UI: &proftest.TestUI{},
|
||||
HTTPServer: creator,
|
||||
})
|
||||
}, false)
|
||||
<-serverCreated
|
||||
defer server.Close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue