modified results and metrics

This commit is contained in:
Senad Uka
2013-11-07 11:27:05 +00:00
parent 441a898718
commit 681a7f2d02
3 changed files with 85 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"text/tabwriter"
"encoding/csv"
)
// Reporter represents any function which takes a slice of Results and
@@ -88,3 +89,69 @@ var plotsTemplate = `<!doctype>
</script>
</body>
</html>`
type ResultGroup struct {
from uint64
to uint64
rate uint64
}
func ReportCSV(results []Result) ([]byte, error) {
out := &bytes.Buffer{}
m := NewMetrics(results)
// result := fnmt.Sprintf("%d req/s,%s,%s,%s,%s,%f,%f,%f",rate,
// m.Latencies.Mean.CsvString(), m.Latencies.P95.CsvString(), m.Latencies.P99.CsvString(), m.Latencies.Max.CsvString(),
// m.BytesIn.Mean, m.BytesOut.Mean, m.Success)
header := []string{ "rate" , "mean" , "p95", "p99" , "max", "bytesIn", "bytesOut", "success" }
w := csv.NewWriter(out)
w.Write(header)
resultGroups := slicesPerAttackRate(results)
for _,resultGroup := range resultGroups {
m := NewMetrics(results[resultGroup.from:resultGroup.to])
w.Write(m.Csv(resultGroup.rate))
}
w.Flush()
return out.Bytes(), nil
}
func slicesPerAttackRate(results []Result) ([]ResultGroup) {
resultGroups := []ResultGroup{}
if len(results) > 0 {
resultGroup := new(ResultGroup)
resultGroup.from = 0
resultGroup.to = 0
resultGroup.rate = results[0].rate
for i, result := range results {
if result.rate != resultGroup.rate {
resultGroup.to = i
append(resultGroups, resultGroup)
resultGroup = new(ResultGroup)
resultGroup.from = i
resultGroup.rate = result.rate
}
}
resultGroup.to = len(results)
append(resultGroups, resultGroup)
}
return resultGroups
}