Repository navigation
Expand file tree
/
Copy pathoutput.go
More file actions
88 lines (80 loc) · 2.49 KB
/
Copy pathoutput.go
File metadata and controls
88 lines (80 loc) · 2.49 KB
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
package bench
import (
"encoding/csv"
"encoding/json"
"fmt"
"io"
"strconv"
"time"
)
// RunResults is the schema persisted at ~/.dfbench/runs/<id>/results.json
// and emitted by --output json. Adding fields is safe; renaming or removing
// them breaks downstream consumers such as dfbench compare.
type RunResults struct {
RunID string `json:"run_id"`
CreatedAt time.Time `json:"created_at"`
CompletedAt time.Time `json:"completed_at"`
Status string `json:"status"`
Region string `json:"region"`
AWSAccount string `json:"aws_account,omitempty"`
ServerInstance string `json:"server_instance"`
ClientInstance string `json:"client_instance"`
Memtier MemtierMetadata `json:"memtier"`
WarmupRequests int `json:"warmup_requests"`
Trials int `json:"trials"`
Engines []AggregateResult `json:"engines"`
}
type MemtierMetadata struct {
Threads int `json:"threads"`
Clients int `json:"clients"`
Requests int `json:"requests"`
Ratio string `json:"ratio"`
DataSize int `json:"data_size"`
Pipeline int `json:"pipeline"`
DistinctClientSeed bool `json:"distinct_client_seed"`
}
// WriteJSON writes run as indented JSON.
func WriteJSON(w io.Writer, run *RunResults) error {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
return enc.Encode(run)
}
// WriteCSV writes one row per trial plus a "median" summary row per engine.
func WriteCSV(w io.Writer, run *RunResults) error {
cw := csv.NewWriter(w)
defer cw.Flush()
header := []string{
"run_id", "engine", "version", "trial",
"throughput_ops_per_sec", "p50_ms", "p99_ms", "p999_ms", "avg_latency_ms",
}
if err := cw.Write(header); err != nil {
return err
}
for _, eng := range run.Engines {
for _, t := range eng.Trials {
row := []string{
run.RunID, eng.Engine, eng.Version,
strconv.Itoa(t.Trial),
ftoa(t.Throughput),
ftoa(t.P50), ftoa(t.P99), ftoa(t.P999), ftoa(t.AvgLatency),
}
if err := cw.Write(row); err != nil {
return err
}
}
row := []string{
run.RunID, eng.Engine, eng.Version,
"median",
ftoa(eng.Throughput.Median),
ftoa(eng.P50.Median), ftoa(eng.P99.Median),
ftoa(eng.P999.Median), ftoa(eng.AvgLatency.Median),
}
if err := cw.Write(row); err != nil {
return err
}
}
return nil
}
func ftoa(f float64) string {
return fmt.Sprintf("%.4f", f)
}