func invokeVisualizer(interactive **bool, format PostProcessor, suffix string, visualizers []string) PostProcessor { return func(input *bytes.Buffer, output io.Writer, ui plugin.UI) error { if err := makeVizTmpDir(); err != nil { return err } tempFile, err := tempfile.New(vizTmpDir, "pprof", "."+suffix) if err != nil { return err } tempfile.DeferDelete(tempFile.Name()) if err = format(input, tempFile, ui); err != nil { return err } tempFile.Close() // on windows, if the file is Open, start cannot access it. // Try visualizers until one is successful for _, v := range visualizers { // Separate command and arguments for exec.Command. args := strings.Split(v, " ") if len(args) == 0 { continue } viewer := exec.Command(args[0], append(args[1:], tempFile.Name())...) viewer.Stderr = os.Stderr if err = viewer.Start(); err == nil { if !**interactive { // In command-line mode, wait for the viewer to be closed // before proceeding return viewer.Wait() } return nil } } return err } }
func makeVizTmpDir() error { if vizTmpDir != "" { return nil } name, err := ioutil.TempDir("", "pprof-") if err != nil { return err } tempfile.DeferDelete(name) vizTmpDir = name return nil }