func writeResults(results vegeta.Results, output string) error { out, err := file(output, true) if err != nil { return fmt.Errorf(errOutputFilePrefix+"(%s): %s", output, err) } defer out.Close() log.Printf("Writing results to '%s'...", output) if err := results.Encode(out); err != nil { return err } return nil }
// report validates the report arguments, sets up the required resources // and writes the report func report(reporter, input, output string) error { var rep vegeta.Reporter switch reporter { case "text": rep = vegeta.ReportText case "json": rep = vegeta.ReportJSON case "plot": rep = vegeta.ReportPlot case "csv": rep = vegeta.ReportCSV default: log.Println("Reporter provided is not supported. Using text") rep = vegeta.ReportText } all := vegeta.Results{} for _, input := range strings.Split(input, ",") { in, err := file(input, false) if err != nil { return err } defer in.Close() results := vegeta.Results{} if err := results.Decode(in); err != nil { return err } else { log.Printf("Number of results: %d", len(results)) } all = append(all, results...) } all.Sort() out, err := file(output, true) if err != nil { return err } defer out.Close() if data, err := rep(all); err != nil { return err } else if _, err := out.Write(data); err != nil { return err } return nil }