This repository has been archived by the owner on Sep 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
141 lines (129 loc) · 3.22 KB
/
results.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/go-playground/log"
"github.com/pkg/errors"
)
func (r *Result) SetResult(row string) {
// Get row value
strValue := strings.Trim(strings.Split(row, ", ")[2], " ")
value, err := strconv.ParseFloat(strValue, 64)
if err != nil {
err = errors.Wrapf(err, "Can not convert to float, setting to 0.0 (row: '%s', value: '%s').", row, strValue)
log.Alertf("%+v", err)
value = 0
}
// Save value to result
switch {
case strings.HasPrefix(row, "[OVERALL], Throughput(ops/sec)"):
r.Throughput = value
case strings.HasPrefix(row, "[READ]"):
r.ReadResult.setOperationResult(row, value)
case strings.HasPrefix(row, "[UPDATE]"):
r.UpdateResult.setOperationResult(row, value)
case strings.HasPrefix(row, "[INSERT]"):
r.InsertResult.setOperationResult(row, value)
case strings.HasPrefix(row, "[SCAN]"):
r.ScanResult.setOperationResult(row, value)
case strings.HasPrefix(row, "[READ-MODIFY-WRITE]"):
r.RmwResult.setOperationResult(row, value)
}
}
func (or *OperationResult) setOperationResult(row string, value float64) {
switch {
case strings.Contains(row, "Operations"):
or.OperationCount = value
case strings.Contains(row, "AverageLatency(us)"):
or.AvgLatency = value
case strings.Contains(row, "MinLatency(us)"):
or.MinLatency = value
case strings.Contains(row, "MaxLatency(us)"):
or.MaxLatency = value
case strings.Contains(row, "95thPercentileLatency(us)"):
or.Per95Latency = value
case strings.Contains(row, "99thPercentileLatency(us)"):
or.Per99Latency = value
}
}
type OperationResult struct {
OperationCount float64
AvgLatency float64
MinLatency float64
MaxLatency float64
Per95Latency float64
Per99Latency float64
// TODO return OK|Error
}
func (or *OperationResult) ToCsvRow() string {
return fmt.Sprintf(
"%f,%f,%f,%f,%f,%f",
or.OperationCount,
or.AvgLatency,
or.MinLatency,
or.MaxLatency,
or.Per95Latency,
or.Per99Latency,
)
}
func buildCsvOperationHeader(prefix string) string {
return fmt.Sprintf(
"%s%s,%s%s,%s%s,%s%s,%s%s,%s%s",
prefix,
"OperationCount",
prefix,
"AvgLatency",
prefix,
"MinLatency",
prefix,
"MaxLatency",
prefix,
"Per95Latency",
prefix,
"Per99Latency",
)
}
type Result struct {
Time time.Time
Database string
Workload string
NodesCount int
ThreadsCount int
Duration float64
Throughput float64
ReadResult *OperationResult
UpdateResult *OperationResult
InsertResult *OperationResult
ScanResult *OperationResult
RmwResult *OperationResult
}
func (r *Result) ToCsvRow() string {
return fmt.Sprintf(
"%s,%s,%s,%d,%d,%f,%f,%s,%s,%s,%s,%s",
r.Time.Format("2006-01-02 15:04:05"),
r.Database,
r.Workload,
r.NodesCount,
r.ThreadsCount,
r.Duration,
r.Throughput,
r.ReadResult.ToCsvRow(),
r.InsertResult.ToCsvRow(),
r.UpdateResult.ToCsvRow(),
r.ScanResult.ToCsvRow(),
r.RmwResult.ToCsvRow(),
)
}
func BuildCsvHeader() string {
return fmt.Sprintf(
"%s,%s,%s,%s,%s,%s",
"timestamp,database,workload,nodes,threads,duration,throughput",
buildCsvOperationHeader("read"),
buildCsvOperationHeader("insert"),
buildCsvOperationHeader("update"),
buildCsvOperationHeader("scan"),
buildCsvOperationHeader("rmw"),
)
}