/
SummaryBuilder.go
65 lines (54 loc) · 2.29 KB
/
SummaryBuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"fmt"
"io"
"github.com/dustin/go-humanize"
"github.com/guzzlerio/corcel/core"
"github.com/nsf/termbox-go"
)
//ConsoleSummaryBuilder ...
type ConsoleSummaryBuilder struct {
writer io.Writer
width int
height int
}
//NewConsoleSummaryBuilder ...
func NewConsoleSummaryBuilder(writer io.Writer) *ConsoleSummaryBuilder {
if err := termbox.Init(); err != nil {
panic(err)
}
w, h := termbox.Size()
termbox.Close()
return &ConsoleSummaryBuilder{
writer: writer,
width: w,
height: h,
}
}
//Write ...
func (this *ConsoleSummaryBuilder) Write(summary core.ExecutionSummary) {
this.top()
this.line("Running Time", summary.RunningTime.String())
this.line("Throughput", fmt.Sprintf("%-.0f req/s", summary.Throughput))
this.line("Total Requests", fmt.Sprintf("%-.0f", summary.TotalRequests))
this.line("Number of Errors", fmt.Sprintf("%-.0f", summary.TotalErrors))
this.line("Availability", fmt.Sprintf("%-.4f%%", summary.Availability))
this.line("Bytes Sent", fmt.Sprintf("%v", humanize.Bytes(uint64(summary.Bytes.Sent.Total))))
this.line("Bytes Received", fmt.Sprintf("%v", humanize.Bytes(uint64(summary.Bytes.Received.Total))))
this.line("Mean Response Time", fmt.Sprintf("%.4f ms", summary.ResponseTime.Mean))
this.line("Min Response Time", fmt.Sprintf("%.4f ms", summary.ResponseTime.Min))
this.line("Max Response Time", fmt.Sprintf("%.4f ms", summary.ResponseTime.Max))
this.tail()
}
func (this *ConsoleSummaryBuilder) top() {
fmt.Fprintln(this.writer, "╔═════════════════════════════════════════════════╗")
fmt.Fprintln(this.writer, "║ Summary ║")
fmt.Fprintln(this.writer, "╠═════════════════════════════════════════════════╣")
}
func (this *ConsoleSummaryBuilder) tail() {
fmt.Fprintln(this.writer, "╚═════════════════════════════════════════════════╝")
}
func (this *ConsoleSummaryBuilder) line(label string, value string) {
data := fmt.Sprintf("%23s: %-22s", label, value)
fmt.Fprintf(this.writer, "║ %s ║\n", data)
}