-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.go
81 lines (65 loc) · 2.11 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
package main
import (
"io"
"time"
)
import "fmt"
type PrinterHolder struct {
Printers []Printer
}
func (p PrinterHolder) Iterate(f func(p Printer)) {
for _, printer := range p.Printers {
f(printer)
}
}
type Printer interface {
PrintHeader()
PrintPreLine(conLevel uint)
PrintLine(conLevel uint, rps float64, avgDur time.Duration, succRate float64, cuEstimate uint64, dist map[string]int)
PrintEvent(event string)
PrintFooter(maxCU uint64)
}
type CsvPrinter struct {
Out io.Writer
}
func (p CsvPrinter) PrintHeader() {
_, err := fmt.Fprintf(p.Out, "concurrency, rps, avg, succRate, cuEstimate\n")
if err != nil {
panic(err)
}
}
func (p CsvPrinter) PrintPreLine(conLevel uint) {}
func (p CsvPrinter) PrintLine(conLevel uint, rps float64, avgDur time.Duration, succRate float64, cuEstimate uint64, dist map[string]int) {
_, err := fmt.Fprintf(p.Out, "%d, %f, %s, %f, %d\n", conLevel, rps, avgDur, succRate, cuEstimate)
if err != nil {
panic(err)
}
}
func (p CsvPrinter) PrintEvent(event string) {}
func (p CsvPrinter) PrintFooter(maxCU uint64) {}
type TextPrinter struct {
Out io.Writer
}
func (p TextPrinter) PrintHeader() {}
func (p TextPrinter) PrintPreLine(conLevel uint) {
fmt.Fprintf(p.Out, "-------------------------------------\n")
fmt.Fprintf(p.Out, "LOAD LEVEL: %d\n", conLevel)
fmt.Fprintf(p.Out, "-------------------------------------\n")
}
func (p TextPrinter) PrintLine(conLevel uint, rps float64, avgDur time.Duration, succRate float64, cuEstimate uint64, dist map[string]int) {
fmt.Fprintf(p.Out, "Concurrency level: %d\n", conLevel)
fmt.Fprintf(p.Out, "RPS: %f\n", rps)
fmt.Fprintf(p.Out, "Avg: %s\n", avgDur)
fmt.Fprintf(p.Out, "SuccRate: %f\n", succRate)
fmt.Fprintf(p.Out, "CU Estimate: %d\n", cuEstimate)
fmt.Fprintf(p.Out, "Error Distribution: %v\n", dist)
}
func (p TextPrinter) PrintEvent(event string) {
fmt.Fprintf(p.Out, "\n")
fmt.Fprintf(p.Out, "=====================================\n")
fmt.Fprintf(p.Out, event+"\n")
}
func (p TextPrinter) PrintFooter(maxCU uint64) {
fmt.Fprintf(p.Out, "=====================================\n")
fmt.Fprintf(p.Out, "MAX CU ESTIMATION: %d\n", maxCU)
}