Use tabwriter for TextReporter output

This commit is contained in:
Tomás Senart
2013-08-17 14:31:22 +02:00
parent 0db8538368
commit 33eecab9b3
2 changed files with 17 additions and 15 deletions

View File

@@ -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

View File

@@ -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()
} }