Skip to content

Commit

Permalink
XML summary output (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffest authored and bengadbois committed Oct 12, 2017
1 parent 7081d93 commit b5428a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func init() {
RootCmd.PersistentFlags().Bool("enforce-ssl", false, "Enfore SSL certificate correctness.")
RootCmd.PersistentFlags().String("output-json", "", "Path to file to write full data as JSON")
RootCmd.PersistentFlags().String("output-csv", "", "Path to file to write full data as CSV")
RootCmd.PersistentFlags().String("output-xml", "", "Path to file to write full data as XML")
RootCmd.PersistentFlags().BoolP("quiet", "q", false, "Do not print while requests are running.")
RootCmd.PersistentFlags().BoolP("verbose", "v", false, "Print extra troubleshooting info.")
RootCmd.PersistentFlags().Int("cpu", runtime.GOMAXPROCS(0), "Number of CPUs to use.")
Expand Down
22 changes: 17 additions & 5 deletions cmd/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"encoding/csv"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -146,8 +147,7 @@ var stressCmd = &cobra.Command{
reqStats := pewpew.CreateRequestsStats(globalStats)
fmt.Println(pewpew.CreateTextStressSummary(reqStats))

//write out json
if viper.GetString("ResultFilenameJSON") != "" {
if viper.GetString("output-json") != "" {
filename := viper.GetString("output-json")
fmt.Print("Writing full result data to: " + filename + " ...")
json, _ := json.MarshalIndent(globalStats, "", " ")
Expand All @@ -159,8 +159,8 @@ var stressCmd = &cobra.Command{
fmt.Println("finished!")
}
//write out csv
if viper.GetString("ResultFilenameCSV") != "" {
filename := viper.GetString("ResultFilenameCSV")
if viper.GetString("output-csv") != "" {
filename := viper.GetString("output-csv")
fmt.Print("Writing full result data to: " + filename + " ...")
file, err := os.Create(filename)
if err != nil {
Expand All @@ -181,12 +181,24 @@ var stressCmd = &cobra.Command{
err := writer.Write(line)
if err != nil {
return errors.New("failed to write full result data to " +
viper.GetString("ResultFilenameCSV") + ": " + err.Error())
filename + ": " + err.Error())
}
}
defer writer.Flush()
fmt.Println("finished!")
}
//write out xml
if viper.GetString("output-xml") != "" {
filename := viper.GetString("output-xml")
fmt.Print("Writing full result data to: " + filename + " ...")
xml, _ := xml.MarshalIndent(globalStats, "", " ")
err = ioutil.WriteFile(viper.GetString("output-xml"), xml, 0644)
if err != nil {
return errors.New("failed to write full result data to " +
filename + ": " + err.Error())
}
fmt.Println("finished!")
}
return nil
},
}
Expand Down

0 comments on commit b5428a4

Please sign in to comment.