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 } if prof.Empty() { return fmt.Errorf("profile is empty") } 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) }