modified results and metrics
This commit is contained in:
@@ -3,8 +3,9 @@ package vegeta
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bmizerany/perks/quantile"
|
"github.com/bmizerany/perks/quantile"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Metrics holds the stats computed out of a slice of Results
|
// Metrics holds the stats computed out of a slice of Results
|
||||||
@@ -76,3 +77,17 @@ func NewMetrics(results []Result) *Metrics {
|
|||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func csvString(d time.Duration) string {
|
||||||
|
var result float64 = float64(d.Nanoseconds() / 1000.0 / 1000.0) // in miliseconds
|
||||||
|
return strconv.FormatFloat(result, 'f', -1, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m *Metrics) Csv(rate uint64) []string {
|
||||||
|
result := fmt.Sprintf("%d req/s,%s,%s,%s,%s,%f,%f,%f",rate,
|
||||||
|
csvString(m.Latencies.Mean), csvString(m.Latencies.P95), csvString(m.Latencies.P99), csvString(m.Latencies.Max),
|
||||||
|
m.BytesIn.Mean, m.BytesOut.Mean, m.Success)
|
||||||
|
return strings.Split(result, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
"encoding/csv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reporter represents any function which takes a slice of Results and
|
// Reporter represents any function which takes a slice of Results and
|
||||||
@@ -88,3 +89,69 @@ var plotsTemplate = `<!doctype>
|
|||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</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
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ func report(reporter, input, output string) error {
|
|||||||
rep = vegeta.ReportJSON
|
rep = vegeta.ReportJSON
|
||||||
case "plot":
|
case "plot":
|
||||||
rep = vegeta.ReportPlot
|
rep = vegeta.ReportPlot
|
||||||
|
case "csv":
|
||||||
|
rep = vegeta.ReportCSV
|
||||||
default:
|
default:
|
||||||
log.Println("Reporter provided is not supported. Using text")
|
log.Println("Reporter provided is not supported. Using text")
|
||||||
rep = vegeta.ReportText
|
rep = vegeta.ReportText
|
||||||
|
|||||||
Reference in New Issue
Block a user