Use tabwriter for TextReporter output
This commit is contained in:
@@ -77,7 +77,6 @@ Just pass a new number as the argument to change it.
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
* Add timeout options to the requests
|
* Add timeout options to the requests
|
||||||
* Use TabWriter in TextReporter
|
|
||||||
* Graphical reporters
|
* Graphical reporters
|
||||||
* Cluster mode (to overcome single machine limits)
|
* Cluster mode (to overcome single machine limits)
|
||||||
* More tests
|
* More tests
|
||||||
|
|||||||
31
reporters.go
31
reporters.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,21 +57,23 @@ func (r *TextReporter) Report(out io.Writer) error {
|
|||||||
avgBytesIn := float64(totalBytesIn) / float64(totalRequests)
|
avgBytesIn := float64(totalBytesIn) / float64(totalRequests)
|
||||||
avgSuccess := float64(totalSuccess) / float64(totalRequests)
|
avgSuccess := float64(totalSuccess) / float64(totalRequests)
|
||||||
|
|
||||||
buf := ""
|
w := tabwriter.NewWriter(out, 0, 8, 2, '\t', tabwriter.StripEscape)
|
||||||
buf += fmt.Sprintln("Results: ")
|
fmt.Fprintf(w, "Time(avg)\tRequests\tSuccess\tBytes(rx/tx)\n")
|
||||||
buf += fmt.Sprintf("Time (avg): %s\n", avgTime)
|
fmt.Fprintf(w, "%s\t%d\t%.2f%%\t%.2f/%.2f\n", avgTime, totalRequests, avgSuccess*100, avgBytesOut, avgBytesIn)
|
||||||
buf += fmt.Sprintf("Bytes out (avg): %f\n", avgBytesOut)
|
|
||||||
buf += fmt.Sprintf("Bytes in (avg): %f\n", avgBytesIn)
|
fmt.Fprintf(w, "\nCount:\t")
|
||||||
buf += fmt.Sprintf("Success ratio: %f\n", avgSuccess)
|
for _, count := range histogram {
|
||||||
buf += fmt.Sprintf("Requests: %d\n", totalRequests)
|
fmt.Fprintf(w, "%d\t", count)
|
||||||
buf += fmt.Sprintln("\nStatus codes histogram:")
|
|
||||||
for code, count := range histogram {
|
|
||||||
buf += fmt.Sprintf("%3d\t%d\n", code, count)
|
|
||||||
}
|
}
|
||||||
buf += fmt.Sprintln("\nError set:")
|
fmt.Fprintf(w, "\nStatus:\t")
|
||||||
|
for code, _ := range histogram {
|
||||||
|
fmt.Fprintf(w, "%d\t", code)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "\n\nError Set:")
|
||||||
for err, _ := range errors {
|
for err, _ := range errors {
|
||||||
buf += fmt.Sprintln(err)
|
fmt.Fprintln(w, err)
|
||||||
}
|
}
|
||||||
_, err := out.Write([]byte(buf))
|
|
||||||
return err
|
return w.Flush()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user