Esempio n. 1
0
// greetings prints a brief welcome and some overall profile
// information before accepting interactive commands.
func greetings(p *profile.Profile, ui plugin.UI) {
	ropt, err := reportOptions(p, pprofVariables)
	if err == nil {
		ui.Print(strings.Join(report.ProfileLabels(report.New(p, ropt)), "\n"))
	}
	ui.Print("Entering interactive mode (type \"help\" for commands, \"o\" for options)")
}
Esempio n. 2
0
func generateReport(p *profile.Profile, cmd []string, vars variables, o *plugin.Options) error {
	p = p.Copy() // Prevent modification to the incoming profile.

	var w io.Writer
	switch output := vars["output"].value; output {
	case "":
		w = os.Stdout
	default:
		o.UI.PrintErr("Generating report in ", output)
		outputFile, err := o.Writer.Open(output)
		if err != nil {
			return err
		}
		defer outputFile.Close()
		w = outputFile
	}

	vars = applyCommandOverrides(cmd, vars)

	// Delay focus after configuring report to get percentages on all samples.
	relative := vars["relative_percentages"].boolValue()
	if relative {
		if err := applyFocus(p, vars, o.UI); err != nil {
			return err
		}
	}
	ropt, err := reportOptions(p, vars)
	if err != nil {
		return err
	}
	c := pprofCommands[cmd[0]]
	if c == nil {
		panic("unexpected nil command")
	}
	ropt.OutputFormat = c.format
	post := c.postProcess
	if len(cmd) == 2 {
		s, err := regexp.Compile(cmd[1])
		if err != nil {
			return fmt.Errorf("parsing argument regexp %s: %v", cmd[1], err)
		}
		ropt.Symbol = s
	}

	rpt := report.New(p, ropt)
	if !relative {
		if err := applyFocus(p, vars, o.UI); err != nil {
			return err
		}
	}

	if err := aggregate(p, vars); err != nil {
		return err
	}

	if post == nil {
		return report.Generate(w, rpt, o.Obj)
	}

	// Capture output into buffer and send to postprocessing command.
	buf := &bytes.Buffer{}
	if err := report.Generate(buf, rpt, o.Obj); err != nil {
		return err
	}
	return post(buf.Bytes(), w, o.UI)
}