Exemplo n.º 1
0
Arquivo: driver.go Projeto: lewgun/gom
func generate(interactive bool, prof *profile.Profile, obj plugin.ObjTool, ui plugin.UI, f *flags) error {
	o, postProcess, err := parseOptions(f)
	if err != nil {
		return err
	}

	var w io.Writer
	if *f.flagOutput == "" {
		w = os.Stdout
	} else {
		ui.PrintErr("Generating report in ", *f.flagOutput)
		outputFile, err := os.Create(*f.flagOutput)
		if err != nil {
			return err
		}
		defer outputFile.Close()
		w = outputFile
	}

	value, stype, unit := sampleFormat(prof, f)
	o.SampleType = stype
	rpt := report.New(prof, *o, value, unit)

	// Do not apply filters if we're just generating a proto, so we
	// still have all the data.
	if o.OutputFormat != report.Proto {
		// Delay applying focus/ignore until after creating the report so
		// the report reflects the total number of samples.
		if err := preprocess(prof, ui, f); err != nil {
			return err
		}
	}

	if postProcess == nil {
		return report.Generate(w, rpt, obj)
	}

	var dot bytes.Buffer
	if err = report.Generate(&dot, rpt, obj); err != nil {
		return err
	}

	return postProcess(&dot, w, ui)
}
Exemplo n.º 2
0
Arquivo: gom.go Projeto: lewgun/gom
// Filter filters the report with a focus regex. If no focus is provided,
// it reports back with the entire set of calls.
// Focus regex works on the package, type and function names. Filtered
// results will include parent samples from the call graph.
func (r *Report) Filter(w io.Writer, cum bool, focus *regexp.Regexp) {
	// TODO(jbd): Support ignore and hide regex parameters.
	if r.p == nil {
		return
	}
	c := r.p.Copy()
	c.FilterSamplesByName(focus, nil, nil)
	rpt := report.NewDefault(c, report.Options{
		OutputFormat:   report.JSON,
		CumSort:        cum,
		PrintAddresses: true,
	})
	report.Generate(w, rpt, nil)
}
Exemplo n.º 3
0
Arquivo: gom.go Projeto: lewgun/gom
func (r *Report) Draw(w io.Writer, cum bool, focus *regexp.Regexp) error {
	// TODO(jbd): Support ignore and hide regex parameters.
	if r.p == nil {
		return errors.New("no such profile")
	}
	c := r.p.Copy()
	c.FilterSamplesByName(focus, nil, nil)
	rpt := report.NewDefault(c, report.Options{
		OutputFormat: report.Dot,
		CumSort:      cum,
	})
	data := bytes.NewBuffer(nil)
	report.Generate(data, rpt, nil)
	cmd := exec.Command("dot", "-Tsvg")
	in, _ := cmd.StdinPipe()
	_, err := io.Copy(in, data)
	if err != nil {
		return err
	}
	in.Close()
	out, err := cmd.Output()
	_, err = w.Write(out)
	return err
}