Browse Source

Redirect binary outputs away from stdout on interactive mode

Raul Silvera 8 years ago
parent
commit
44f53e2755
2 changed files with 8 additions and 6 deletions
  1. 7
    5
      internal/driver/commands.go
  2. 1
    1
      internal/driver/interactive.go

+ 7
- 5
internal/driver/commands.go View File

79
 // PostProcessor is a function that applies post-processing to the report output
79
 // PostProcessor is a function that applies post-processing to the report output
80
 type PostProcessor func(input []byte, output io.Writer, ui plugin.UI) error
80
 type PostProcessor func(input []byte, output io.Writer, ui plugin.UI) error
81
 
81
 
82
-// WaitForVisualizer makes pprof wait for visualizers to complete
83
-// before continuing, returning any errors.
84
-var waitForVisualizer = true
82
+// interactiveMode is true if pprof is running on interactive mode, reading
83
+// commands from its shell.
84
+var interactiveMode = false
85
 
85
 
86
 // pprofCommands are the report generation commands recognized by pprof.
86
 // pprofCommands are the report generation commands recognized by pprof.
87
 var pprofCommands = commands{
87
 var pprofCommands = commands{
361
 // the screen.
361
 // the screen.
362
 func awayFromTTY(format string) PostProcessor {
362
 func awayFromTTY(format string) PostProcessor {
363
 	return func(input []byte, output io.Writer, ui plugin.UI) error {
363
 	return func(input []byte, output io.Writer, ui plugin.UI) error {
364
-		if output == os.Stdout && ui.IsTerminal() {
364
+		if output == os.Stdout && (ui.IsTerminal() || interactiveMode) {
365
 			tempFile, err := newTempFile("", "profile", "."+format)
365
 			tempFile, err := newTempFile("", "profile", "."+format)
366
 			if err != nil {
366
 			if err != nil {
367
 				return err
367
 				return err
443
 				defer func(t <-chan time.Time) {
443
 				defer func(t <-chan time.Time) {
444
 					<-t
444
 					<-t
445
 				}(time.After(time.Second))
445
 				}(time.After(time.Second))
446
-				if waitForVisualizer {
446
+				// On interactive mode, let the visualizer run on the background
447
+				// so other commands can be issued.
448
+				if !interactiveMode {
447
 					return viewer.Wait()
449
 					return viewer.Wait()
448
 				}
450
 				}
449
 				return nil
451
 				return nil

+ 1
- 1
internal/driver/interactive.go View File

39
 
39
 
40
 	// Do not wait for the visualizer to complete, to allow multiple
40
 	// Do not wait for the visualizer to complete, to allow multiple
41
 	// graphs to be visualized simultaneously.
41
 	// graphs to be visualized simultaneously.
42
-	waitForVisualizer = false
42
+	interactiveMode = true
43
 	shortcuts := profileShortcuts(p)
43
 	shortcuts := profileShortcuts(p)
44
 
44
 
45
 	greetings(p, o.UI)
45
 	greetings(p, o.UI)