-
Notifications
You must be signed in to change notification settings - Fork 0
/
organize.rb
executable file
·136 lines (103 loc) · 2.97 KB
/
organize.rb
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
#!/usr/bin/env ruby
require 'csv'
RESULTS_DIR = File.expand_path("../../results", __FILE__)
PROCESSED = File.join(RESULTS_DIR, "processed.csv")
PREFIX = "bench_results_"
def get_server_label(file_name)
parts = File.basename(file_name, ".csv").sub(PREFIX, "").split("_")
case parts[0]
when "unicorn" then parts.join(" x")
when "puma" then "#{parts[0]} x#{parts[1]}:#{parts[2]}"
else raise "unrecognized file name: #{file_name}"
end
end
# ---------------------------------------------------------
# Setup the data
# [endpoints]
# [metrics]
# [servers]
# [concurrency levels]
@data = Hash.new do |root, endpoint|
root[endpoint] = Hash.new do |ep, metric|
ep[metric] = Hash.new do |mt, server|
mt[server] = []
end
end
end
def store(endpoint:, metric:, server:, data:)
@data[endpoint][metric][server] = data
end
raw_results_files = Dir.glob(RESULTS_DIR + "/" + PREFIX + "*")
concurrency_levels = %w(1 10 20 30 40 50)
raw_results_files.each do |file_path|
server = get_server_label(file_path)
CSV.foreach(file_path, headers: true) do |row|
store(
endpoint: row["path"],
metric: row["metric"],
server: server,
data: concurrency_levels.map { |c| row.send(:[], c) }
)
end
end
# ---------------------------------------------------------
# Setup more data
endpoints = @data.keys
metrics = @data.values.first.keys
servers = @data.values.first.values.first.keys
@rotated = Hash.new do |root, concurrency_level|
root[concurrency_level] = Hash.new do |cl, metric|
cl[metric] = Hash.new do |mt, endpoint|
mt[endpoint] = []
end
end
end
def rotated_store(concurrency:, metric:, endpoint:, data:)
@rotated[concurrency][metric][endpoint] = data
end
concurrency_levels.each_with_index do |cl, cl_index|
metrics.each do |metric|
endpoints.each do |endpoint|
data = servers.map do |server|
@data[endpoint][metric][server][cl_index]
end
rotated_store(
concurrency: cl,
metric: metric,
endpoint: endpoint,
data: data
)
end
end
end
# ---------------------------------------------------------
# Write the new CSV
out = File.open(PROCESSED, "w")
# Y:metric, X:concurrency, data:server
@data.each_pair do |endpoint, metrics|
out.puts endpoint
out.puts ""
metrics.each_pair do |metric, servers|
out.puts metric
out.puts CSV.generate_line(["concurrent requests", *concurrency_levels])
servers.each_pair do |server, data|
out.puts CSV.generate_line([server, *data])
end
out.puts "\n\n"
end
end
out.puts "----------------------------------"
# Y:metric, X:server, data:endpoint
@rotated.each_pair do |concurrency_level, metrics|
out.puts concurrency_level
out.puts ""
metrics.each_pair do |metric, endpoints|
out.puts metric
out.puts CSV.generate_line(["server", *servers])
endpoints.each_pair do |endpoint, data|
out.puts CSV.generate_line([endpoint, *data])
end
out.puts "\n\n"
end
end
out.close