Explorar el Código

Add option to disable browser in HTTP mode (#462)

ahh hace 6 años
padre
commit
77426154d5
Se han modificado 5 ficheros con 33 adiciones y 20 borrados
  1. 1
    0
      CONTRIBUTORS
  2. 23
    15
      internal/driver/cli.go
  3. 1
    1
      internal/driver/driver.go
  4. 7
    3
      internal/driver/webui.go
  5. 1
    1
      internal/driver/webui_test.go

+ 1
- 0
CONTRIBUTORS Ver fichero

13
 Hyoun Kyu Cho <netforce@google.com>
13
 Hyoun Kyu Cho <netforce@google.com>
14
 Martin Spier <spiermar@gmail.com>
14
 Martin Spier <spiermar@gmail.com>
15
 Taco de Wolff <tacodewolff@gmail.com>
15
 Taco de Wolff <tacodewolff@gmail.com>
16
+Andrew Hunter <andrewhhunter@gmail.com>

+ 23
- 15
internal/driver/cli.go Ver fichero

32
 	DiffBase  bool
32
 	DiffBase  bool
33
 	Normalize bool
33
 	Normalize bool
34
 
34
 
35
-	Seconds      int
36
-	Timeout      int
37
-	Symbolize    string
38
-	HTTPHostport string
39
-	Comment      string
35
+	Seconds            int
36
+	Timeout            int
37
+	Symbolize          string
38
+	HTTPHostport       string
39
+	HTTPDisableBrowser bool
40
+	Comment            string
40
 }
41
 }
41
 
42
 
42
 // parseFlags parses the command lines through the specified flags package
43
 // parseFlags parses the command lines through the specified flags package
65
 	flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region")
66
 	flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region")
66
 	flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames")
67
 	flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames")
67
 
68
 
68
-	flagHTTP := flag.String("http", "", "Present interactive web based UI at the specified http host:port")
69
+	flagHTTP := flag.String("http", "", "Present interactive web UI at the specified http host:port")
70
+	flagNoBrowser := flag.Bool("no_browser", false, "Skip opening a browswer for the interactive web UI")
69
 
71
 
70
 	// Flags used during command processing
72
 	// Flags used during command processing
71
 	installedFlags := installFlags(flag)
73
 	installedFlags := installFlags(flag)
118
 		return nil, nil, errors.New("-http is not compatible with an output format on the command line")
120
 		return nil, nil, errors.New("-http is not compatible with an output format on the command line")
119
 	}
121
 	}
120
 
122
 
123
+	if *flagNoBrowser && *flagHTTP == "" {
124
+		return nil, nil, errors.New("-no_browser only makes sense with -http")
125
+	}
126
+
121
 	si := pprofVariables["sample_index"].value
127
 	si := pprofVariables["sample_index"].value
122
 	si = sampleIndex(flagTotalDelay, si, "delay", "-total_delay", o.UI)
128
 	si = sampleIndex(flagTotalDelay, si, "delay", "-total_delay", o.UI)
123
 	si = sampleIndex(flagMeanDelay, si, "delay", "-mean_delay", o.UI)
129
 	si = sampleIndex(flagMeanDelay, si, "delay", "-mean_delay", o.UI)
133
 	}
139
 	}
134
 
140
 
135
 	source := &source{
141
 	source := &source{
136
-		Sources:      args,
137
-		ExecName:     execName,
138
-		BuildID:      *flagBuildID,
139
-		Seconds:      *flagSeconds,
140
-		Timeout:      *flagTimeout,
141
-		Symbolize:    *flagSymbolize,
142
-		HTTPHostport: *flagHTTP,
143
-		Comment:      *flagAddComment,
142
+		Sources:            args,
143
+		ExecName:           execName,
144
+		BuildID:            *flagBuildID,
145
+		Seconds:            *flagSeconds,
146
+		Timeout:            *flagTimeout,
147
+		Symbolize:          *flagSymbolize,
148
+		HTTPHostport:       *flagHTTP,
149
+		HTTPDisableBrowser: *flagNoBrowser,
150
+		Comment:            *flagAddComment,
144
 	}
151
 	}
145
 
152
 
146
 	if err := source.addBaseProfiles(*flagBase, *flagDiffBase); err != nil {
153
 	if err := source.addBaseProfiles(*flagBase, *flagDiffBase); err != nil {
327
 
334
 
328
 var usageMsgVars = "\n\n" +
335
 var usageMsgVars = "\n\n" +
329
 	"  Misc options:\n" +
336
 	"  Misc options:\n" +
330
-	"   -http              Provide web based interface at host:port.\n" +
337
+	"   -http              Provide web interface at host:port.\n" +
331
 	"                      Host is optional and 'localhost' by default.\n" +
338
 	"                      Host is optional and 'localhost' by default.\n" +
332
 	"                      Port is optional and a randomly available port by default.\n" +
339
 	"                      Port is optional and a randomly available port by default.\n" +
340
+	"   -no_browser        Skip opening a browser for the interactive web UI.\n" +
333
 	"   -tools             Search path for object tools\n" +
341
 	"   -tools             Search path for object tools\n" +
334
 	"\n" +
342
 	"\n" +
335
 	"  Legacy convenience options:\n" +
343
 	"  Legacy convenience options:\n" +

+ 1
- 1
internal/driver/driver.go Ver fichero

54
 	}
54
 	}
55
 
55
 
56
 	if src.HTTPHostport != "" {
56
 	if src.HTTPHostport != "" {
57
-		return serveWebInterface(src.HTTPHostport, p, o)
57
+		return serveWebInterface(src.HTTPHostport, p, o, src.HTTPDisableBrowser)
58
 	}
58
 	}
59
 	return interactive(p, o)
59
 	return interactive(p, o)
60
 }
60
 }

+ 7
- 3
internal/driver/webui.go Ver fichero

82
 	FlameGraph  template.JS
82
 	FlameGraph  template.JS
83
 }
83
 }
84
 
84
 
85
-func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options) error {
85
+func serveWebInterface(hostport string, p *profile.Profile, o *plugin.Options, disableBrowser bool) error {
86
 	host, port, err := getHostAndPort(hostport)
86
 	host, port, err := getHostAndPort(hostport)
87
 	if err != nil {
87
 	if err != nil {
88
 		return err
88
 		return err
117
 		},
117
 		},
118
 	}
118
 	}
119
 
119
 
120
-	if o.UI.WantBrowser() {
121
-		go openBrowser("http://"+args.Hostport, o)
120
+	url := "http://" + args.Hostport
121
+
122
+	o.UI.Print("Serving web UI on ", url)
123
+
124
+	if o.UI.WantBrowser() && !disableBrowser {
125
+		go openBrowser(url, o)
122
 	}
126
 	}
123
 	return server(args)
127
 	return server(args)
124
 }
128
 }

+ 1
- 1
internal/driver/webui_test.go Ver fichero

58
 		Obj:        fakeObjTool{},
58
 		Obj:        fakeObjTool{},
59
 		UI:         &proftest.TestUI{},
59
 		UI:         &proftest.TestUI{},
60
 		HTTPServer: creator,
60
 		HTTPServer: creator,
61
-	})
61
+	}, false)
62
 	<-serverCreated
62
 	<-serverCreated
63
 	defer server.Close()
63
 	defer server.Close()
64
 
64