-
Notifications
You must be signed in to change notification settings - Fork 4
/
fio_graphs.py
executable file
·324 lines (275 loc) · 11.2 KB
/
fio_graphs.py
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env python3
import argparse
import json
import pprint
import os
import re
import sys
import pandas
import numpy as np
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
plt.style.use('ggplot')
def get_arg_parser():
p = argparse.ArgumentParser(
description='Create graphs from various fio json outputs')
p.add_argument('path', help='Source path for fio output')
p.add_argument(
'-d',
'--dir', action="store_true",
help='Read output files from a directory and consider files to be of the same run')
p.add_argument('-o', '--output', help='output directory for graphs',
default='graphs')
return p
class FioResults(object):
def __init__(self, args):
# two parsing modes: single file, dir with files to aggregate
self.b_width = 0.15
self.args = args
self.data = {
'results': [],
'directory': self.args.dir
}
os.makedirs(self.args.output, exist_ok=True)
self.cache = {}
self.meta = {}
@property
def num_clients(self):
if self.meta is {}:
return 0
# TODO fix dirty hack
k = list(self.meta.keys())[0]
return len(self.meta[k]['clients'])
@property
def num_threads(self):
if self.meta is {}:
return 0
# TODO fix dirty hack
k = list(self.meta.keys())[0]
return self.meta[k]['count'] / len(self.meta[k]['clients'])
def parse_data(self):
if self.args.dir:
self._parse_dir()
else:
self._parse_file(self.args.path)
def _parse_dir(self):
for f in os.listdir(self.args.path):
path = '{}/{}'.format(self.args.path, f)
if os.path.isfile(path):
self._parse_file(path)
def _parse_file(self, path):
with open(path) as file_:
try:
d = json.load(file_)
self.data['results'].append(d)
except ValueError:
print('IGNORING file {}, contains no valid JSON'.format(path))
def _aggregate_data(self):
if not self.data['results']:
print('ERROR...no data found.')
sys.exit()
d = {}
for result in self.data['results']:
if 'jobs' in result:
result_key = 'jobs'
elif 'client_stats' in result:
result_key = 'client_stats'
for job in result[result_key]:
# Skip 'All clients' if present
if job['jobname'] == 'All clients':
continue
if job['error'] is not 0:
print('job {} reported an error...skipping'.format(
job['jobname']
))
continue
# Extract data from json
if job['jobname'] not in d:
d[job['jobname']] = {'read': 0,
'write': 0,
'r_iops': 0,
'w_iops': 0,
'lat_us': {},
'lat_ms': {},
'clients': [],
'options': {},
'count': 0}
d[job['jobname']]['options'] = job['job options']
d[job['jobname']]['count'] += 1
if job['hostname'] not in d[job['jobname']]['clients']:
d[job['jobname']]['clients'].append(job['hostname'])
d[job['jobname']]['read'] += job['read']['bw']
d[job['jobname']]['write'] += job['write']['bw']
d[job['jobname']]['r_iops'] += job['read']['iops']
d[job['jobname']]['w_iops'] += job['write']['iops']
for k, v in job['latency_us'].items():
if k in d[job['jobname']]['lat_us']:
d[job['jobname']]['lat_us'][k] += job['latency_us'][k]
else:
d[job['jobname']]['lat_us'][k] = job['latency_us'][k]
for k, v in job['latency_ms'].items():
if k in d[job['jobname']]['lat_ms']:
d[job['jobname']]['lat_ms'][k] += job['latency_ms'][k]
else:
d[job['jobname']]['lat_ms'][k] = job['latency_ms'][k]
# create data frames from extracted data
self.cache['bw'] = pandas.DataFrame(data={
'name': [k for k in d.keys()],
'read': [v['read'] for v in d.values()],
'write': [v['write'] for v in d.values()]})
self.cache['iops'] = pandas.DataFrame(data={
'name': [k for k in d.keys()],
'read': [v['r_iops'] for v in d.values()],
'write': [v['w_iops'] for v in d.values()]})
lat_data = {'lats': list(d[next(iter(d))]['lat_us'].keys())
+ [k + '000' for k in d[next(iter(d))]['lat_ms'].keys()]}
self.cache['meta_clients'] = {k: v['count'] for k, v in d.items()}
for name in d.keys():
c = []
for k in d[name]['lat_us'].keys():
c.append(d[name]['lat_us'][k] / d[name]['count'])
for k in d[name]['lat_ms'].keys():
c.append(d[name]['lat_ms'][k] / d[name]['count'])
lat_data[name] = c
self.cache['lat_dist'] = pandas.DataFrame(data=lat_data)
# collect some metadata about the jobs
for name in d.keys():
self.meta[name] = {
'count': d[name]['count'],
'clients': d[name]['clients'],
}
def get_aggregate_bw(self):
if 'bw' not in self.cache:
self._aggregate_data()
return self.cache['bw']
def get_aggregate_iops(self):
if 'iops' not in self.cache:
self._aggregate_data()
return self.cache['iops']
def get_aggregate_lat_dist(self):
if 'lat_dist' not in self.cache:
self._aggregate_data()
return self.cache['lat_dist']
def print_(self):
lats = self.get_aggregate_lat_dist()
print('aggregate latency distribution')
pprint.pprint(lats)
print('aggregate bandwidth')
pprint.pprint(self.get_aggregate_bw())
print('aggregate iops')
pprint.pprint(self.get_aggregate_iops())
def aggregate_bw_graph(self):
plt.clf()
dframe = self.get_aggregate_bw()
ind = np.arange(dframe.index.size)
if max(dframe.read) + max(dframe.write) > 1000000:
b1_data = dframe.read / 1024
b2_data = dframe.write / 1024
plt.ylabel('Bandwidth (MiB/s)')
else:
b1_data = dframe.read
b2_data = dframe.write
plt.ylabel('Bandwidth (KiB/s)')
dframe['sort1'] = dframe['name'].apply(get_workers)
dframe['sort2'] = dframe['name'].apply(get_op)
dframe['sort3'] = dframe['name'].apply(get_bs)
dframe = dframe.sort_values(by=['sort1', 'sort2', 'sort3'])
pprint.pprint(dframe)
bar1 = plt.bar(ind, b1_data, self.b_width)
bar2 = plt.bar(ind, b2_data, self.b_width, bottom=b1_data)
plt.title('Aggregated bandwidth over {} clients'.format(
self.num_clients))
# adjust xscale if stacked is > 1000000 or so
plt.xticks(ind, dframe.name, rotation=-45, ha='left',
rotation_mode='anchor')
plt.legend((bar2[0], bar1[0]),
('write', 'read')).get_frame().set_facecolor('#FFFFFF')
fig = plt.gcf()
fig.set_size_inches(24, 15)
plt.savefig('{}/bw_aggr.png'.format(self.args.output), bbox_inches='tight')
plt.savefig('{}/bw_aggr.svg'.format(self.args.output), bbox_inches='tight')
def aggregate_iops_graph(self):
plt.clf()
dframe = self.get_aggregate_iops()
ind = np.arange(dframe.index.size)
if max(dframe.read) + max(dframe.write) > 9900000:
b1_data = dframe.read / 1024
b2_data = dframe.write / 1024
else:
b1_data = dframe.read
b2_data = dframe.write
plt.ylabel('IOPS')
bar1 = plt.bar(ind, b1_data, self.b_width)
bar2 = plt.bar(ind, b2_data, self.b_width, bottom=b1_data)
plt.title('Aggregated IOPS over {} clients'.format(
self.num_clients))
plt.yscale('log')
# adjust xscale if stacked is > 1000000 or so
plt.xticks(ind, dframe.name, rotation=-45, ha='left',
rotation_mode='anchor')
plt.legend((bar2[0], bar1[0]),
('write', 'read')).get_frame().set_facecolor('#FFFFFF')
fig = plt.gcf()
fig.set_size_inches(16, 9)
plt.savefig('{}/iops_aggr.png'.format(self.args.output), bbox_inches='tight')
plt.savefig('{}/iops_aggr.svg'.format(self.args.output), bbox_inches='tight')
def aggregate_lat_dist_graph(self):
plt.clf()
dframe = self.get_aggregate_lat_dist()
ind = np.arange(dframe['lats'].size)
plt.ylabel('% of all IOPS')
plt.xlabel('Completion latency bucket [μs]')
plt.title('Aggregated latency distribution over {} clients'.format(
self.num_clients))
def strip_fct (e):
if not e[0].isdigit():
return int(e.lstrip('>=')) + 1
else:
return int(e)
dframe['sort'] = dframe['lats'].apply(strip_fct)
d = dframe.sort_values(by='sort')
pprint.pprint(d.iloc[:, :-2])
legend = []
for c in d.iloc[:, :-2]:
line = plt.plot(ind, d[c].cumsum())
legend.append((line[0], c))
plt.xticks(ind, d['lats'], rotation=45)
legend = sorted(legend, key=lambda tup: get_bs(tup[1]))
legend = sorted(legend, key=lambda tup: get_workers(tup[1]))
plt.legend([l[0] for l in legend],
[l[1] for l in legend]).get_frame().set_facecolor('#FFFFFF')
fig = plt.gcf()
fig.set_size_inches(16, 9)
plt.savefig('{}/lat_dist.png'.format(self.args.output), bbox_inches='tight')
plt.savefig('{}/lat_dist.svg'.format(self.args.output), bbox_inches='tight')
def get_workers(val):
return int(re.findall('^\d+', val)[0])
def get_bs(val):
bs = re.findall('\d+', val)[1]
u = re.findall('[k,m]', val)[0]
if u == 'm':
return int(bs) * 1024
return int(bs)
def get_op(val):
return val.split('_')[-1]
def get_fio(path):
return FioResults(argparse.Namespace(dir=True, path=path, output='graphs'))
def main():
a_parser = get_arg_parser()
args = a_parser.parse_args()
if args.dir:
if not os.path.isdir(args.path):
raise a_parser.ArgumentError(('-d was passed but path is not a ',
'directory'))
else:
if os.path.isdir(args.path):
raise a_parser.ArgumentError(('-d was not passed but path is a ',
'directory'))
results = FioResults(args)
results.parse_data()
results.print_()
results.aggregate_bw_graph()
results.aggregate_iops_graph()
results.aggregate_lat_dist_graph()
if __name__ == "__main__":
main()