Selaa lähdekoodia

Redirect binary outputs away from stdout on interactive mode

Raul Silvera 8 vuotta sitten
vanhempi
commit
44f53e2755
2 muutettua tiedostoa jossa 8 lisäystä ja 6 poistoa
  1. 7
    5
      internal/driver/commands.go
  2. 1
    1
      internal/driver/interactive.go

+ 7
- 5
internal/driver/commands.go Näytä tiedosto

@@ -79,9 +79,9 @@ func SetVariableDefault(variable, value string) {
79 79
 // PostProcessor is a function that applies post-processing to the report output
80 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 86
 // pprofCommands are the report generation commands recognized by pprof.
87 87
 var pprofCommands = commands{
@@ -361,7 +361,7 @@ var kcachegrind = []string{"kcachegrind"}
361 361
 // the screen.
362 362
 func awayFromTTY(format string) PostProcessor {
363 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 365
 			tempFile, err := newTempFile("", "profile", "."+format)
366 366
 			if err != nil {
367 367
 				return err
@@ -443,7 +443,9 @@ func invokeVisualizer(format PostProcessor, suffix string, visualizers []string)
443 443
 				defer func(t <-chan time.Time) {
444 444
 					<-t
445 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 449
 					return viewer.Wait()
448 450
 				}
449 451
 				return nil

+ 1
- 1
internal/driver/interactive.go Näytä tiedosto

@@ -39,7 +39,7 @@ func interactive(p *profile.Profile, o *plugin.Options) error {
39 39
 
40 40
 	// Do not wait for the visualizer to complete, to allow multiple
41 41
 	// graphs to be visualized simultaneously.
42
-	waitForVisualizer = false
42
+	interactiveMode = true
43 43
 	shortcuts := profileShortcuts(p)
44 44
 
45 45
 	greetings(p, o.UI)