-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
94 lines (82 loc) · 2.85 KB
/
printer.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
rua "github.com/taoxinyi/rua/framework"
"os"
"strings"
"time"
)
type Printer struct{}
var printer Printer
func (p *Printer) print(stats *rua.Stats, duration time.Duration) {
seconds := duration.Seconds()
var headers []string
var data [][]string
headers = []string{"", "Connection", "Timeout", "Status"}
data = [][]string{{
"Errors",
fmt.Sprintf("%d", stats.ConnectionErrors),
fmt.Sprintf("%d", stats.TimeoutErrors),
fmt.Sprintf("%d", stats.StatusErrors),
}}
printTable(headers, data)
headers = []string{"", "Avg", "Min", "Max", "Stdev", "+/- Stdev"}
data = [][]string{{
"Latency",
fmt.Sprintf("%.3fms", float64(stats.LatencyMean())/1000.0),
fmt.Sprintf("%.3fms", float64(stats.MinLatency)/1000.0),
fmt.Sprintf("%.3fms", float64(stats.MaxLatency)/1000.0),
fmt.Sprintf("%.3fms", stats.LatencyStdev()/1000.0),
fmt.Sprintf("%.3f%%", stats.LatencyPercentageWithinStdev(1)),
}}
printTable(headers, data)
headers = []string{"", "50%", "75%", "90%", "99%", "99.9%"}
data = [][]string{{
"Latency",
fmt.Sprintf("%.3fms", float64(stats.LatencyPercentile(50))/1000.0),
fmt.Sprintf("%.3fms", float64(stats.LatencyPercentile(75))/1000.0),
fmt.Sprintf("%.3fms", float64(stats.LatencyPercentile(90))/1000.0),
fmt.Sprintf("%.3fms", float64(stats.LatencyPercentile(99))/1000.0),
fmt.Sprintf("%.3fms", float64(stats.LatencyPercentile(99.9))/1000.0),
}}
printTable(headers, data)
headers = []string{"", "Count", "Count/s", "Size", "Throughput"}
data = [][]string{{
"Requests",
fmt.Sprintf("%d", stats.RequestsSent),
fmt.Sprintf("%.2f", float64(stats.RequestsSent)/seconds),
fmt.Sprintf("%s", humanize.IBytes(uint64(stats.BytesSent))),
fmt.Sprintf("%s/s", humanize.IBytes(uint64(float64(stats.BytesSent)/seconds))),
}, {
"Responses",
fmt.Sprintf("%d", stats.ResponsesRecv),
fmt.Sprintf("%.2f", float64(stats.ResponsesRecv)/seconds),
fmt.Sprintf("%s", humanize.IBytes(uint64(stats.BytesRecv))),
fmt.Sprintf("%s/s", humanize.IBytes(uint64(float64(stats.BytesRecv)/seconds))),
},
}
printTable(headers, data)
fmt.Printf("\n%d responses received in %s, %s read\n", stats.ResponsesRecv, duration, humanize.IBytes(uint64(stats.BytesRecv)))
}
func printTable(headers []string, data [][]string) {
fmt.Println(strings.Repeat("-", 72))
table := tablewriter.NewWriter(os.Stdout)
for i := 0; i < len(headers); i++ {
table.SetColMinWidth(i, 12)
}
table.SetHeader(headers)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(false)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetNoWhiteSpace(true)
table.AppendBulk(data) // Add Bulk Data
table.Render()
}