Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an incremental reporter that prints the latency
Browse files Browse the repository at this point in the history
mickey committed Feb 8, 2015
1 parent a20e73e commit 64412d7
Showing 2 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/reporters.go
Original file line number Diff line number Diff line change
@@ -106,6 +106,19 @@ var ReportText ReporterFunc = func(r Results) ([]byte, error) {
return out.Bytes(), nil
}

var ReportIncrementalLatency ReporterFunc = func(r Results) ([]byte, error) {
m := NewMetrics(r)
out := &bytes.Buffer{}

w := tabwriter.NewWriter(out, 0, 8, 2, '\t', tabwriter.StripEscape)
fmt.Fprintf(w, "%s\n", strings.TrimSuffix(m.Latencies.Mean.String(), "ms"))

if err := w.Flush(); err != nil {
return []byte{}, err
}
return out.Bytes(), nil
}

// ReportJSON writes a computed Metrics struct to as JSON
var ReportJSON ReporterFunc = func(r Results) ([]byte, error) {
return json.Marshal(NewMetrics(r))
30 changes: 24 additions & 6 deletions report.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (

func reportCmd() command {
fs := flag.NewFlagSet("vegeta report", flag.ExitOnError)
reporter := fs.String("reporter", "text", "Reporter [text, json, plot, hist[buckets]]")
reporter := fs.String("reporter", "text", "Reporter [text, json, plot, hist[buckets], incrementalLatency]")
inputs := fs.String("inputs", "stdin", "Input files (comma separated)")
output := fs.String("output", "stdout", "Output file")
return command{fs, func(args []string) error {
@@ -30,6 +30,7 @@ func report(reporter, inputs, output string) error {
return fmt.Errorf("bad reporter: %s", reporter)
}
var rep vegeta.Reporter
var incremental = false
switch reporter[:4] {
case "text":
rep = vegeta.ReportText
@@ -46,6 +47,9 @@ func report(reporter, inputs, output string) error {
return err
}
rep = hist
case "incr":
incremental = true
rep = vegeta.ReportIncrementalLatency
}

files := strings.Split(inputs, ",")
@@ -80,6 +84,17 @@ outer:
break outer
}
results = append(results, r)
if incremental == true {
data, err := rep.Report(results)
if err != nil {
return err
}
_, err = out.Write(data)
if err != nil {
return err
}
results = results[:0]
}
case err, ok := <-errs:
if !ok {
break outer
@@ -88,11 +103,14 @@ outer:
}
}

sort.Sort(results)
data, err := rep.Report(results)
if err != nil {
if incremental == false {
sort.Sort(results)
data, err := rep.Report(results)
if err != nil {
return err
}
_, err = out.Write(data)
return err
}
_, err = out.Write(data)
return err
return nil
}

0 comments on commit 64412d7

Please sign in to comment.