-
Notifications
You must be signed in to change notification settings - Fork 41
/
plot_log_data.py
executable file
·610 lines (566 loc) · 17 KB
/
plot_log_data.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
#!/bin/python3
# Author : Alberto M. Esmoris Pena
# Script to plot performance data from logs
# See : logs_to_plots.sh
# --- IMPORTS --- #
# ----------------- #
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sys
import os
# --- CONFIGURATION CONSTANTS --- #
# --------------------------------- #
markOptimumTime = False # If True, plots will mark optimum time point
# --- PREPARE OUTPUT DIRECTORY --- #
# ---------------------------------- #
if len(sys.argv) < 2:
print(
'\nPlot from logs data cannot be generated.\n'
'It is necessary to specify 2 input arguments:\n'
'\t1: Path to input data CSV\n'
'\t2: Path to output directory where plots will be exported\n'
)
sys.exit(2)
if not os.path.isdir(sys.argv[2]):
if os.path.exists(sys.argv[2]):
print(
'"{path}" exists but it is not a directory'
.format(path=sys.argv[2])
)
sys.exit(2)
else:
os.mkdir(sys.argv[2], 0o755)
outdir = '{path}{sep}'.format(path=sys.argv[2], sep=os.path.sep)
# --- LOAD DATA --- #
# ------------------- #
BASE_GROUP_LIST = [
'KDTreeType', 'SAHNodes',
'ParallelizationStrategy', 'ChunkSize', 'WarehouseFactor'
]
DF = pd.read_csv(sys.argv[1], header=0)
GDF = DF.groupby([
'KDTreeType', 'SAHNodes',
'ParallelizationStrategy', 'ChunkSize', 'WarehouseFactor',
'SimulationCores', 'KDTBuildingCores'
]).mean()
GDF = DF.groupby(BASE_GROUP_LIST, as_index=True)
DFS = [GDF.get_group(g) for g in GDF.groups]
# --- PLOT n SUMMARY --- #
# ----------------------- #
def key_from_index(index):
kdtNum = index[0]
if kdtNum == 1:
return "KDT_SIMPLE"
elif kdtNum == 2:
return "KDT_SAH"
elif kdtNum == 3:
return "KDT_AXIS_SAH"
elif kdtNum == 4:
return "KDT_FAST_SAH"
else:
return "KDT_UNKNOWN"
def type_from_index(index):
parallelNum = index[2]
chunkSize = index[3]
if parallelNum == 0:
if chunkSize < 0:
return "DYNAMIC"
return "STATIC"
elif parallelNum == 1:
return "WAREHOUSE"
else:
return "UNKNOWN"
def title_from_index(index):
# Extract subindices
kdtNum = index[0]
sahNodes = index[1]
parallelNum = index[2]
chunkSize = index[3]
whFactor = index[4]
# Text from subindices
kdtType = 'UNKNOWN'
parallelType = 'UNKNOWN'
if kdtNum == 1:
kdtType = 'Simple'
elif kdtNum == 2:
kdtType = 'SAH'
elif kdtNum == 3:
kdtType = 'AxisSAH'
elif kdtNum == 4:
kdtType = 'FastSAH'
if parallelNum == 0:
parallelType = 'Static scheduling with chunk size {chunkSize}'\
.format(chunkSize=chunkSize)
if chunkSize < 0:
parallelType = 'Dynamic scheduling with chunk size {chunkSize}'\
.format(chunkSize=chunkSize)
elif parallelNum == 1:
parallelType = 'Warehouse x{whFactor} with chunk size {chunkSize}'\
.format(whFactor=whFactor, chunkSize=chunkSize)
# Return title
return \
'Helios with {kdtType} KDTree of {sahNodes} nodes\n'\
'{parallelType} parallelization'\
.format(
kdtType=kdtType,
sahNodes=sahNodes,
parallelType=parallelType
)
def name_from_index(index):
# Extract subindices
kdtNum = index[0]
sahNodes = index[1]
parallelNum = index[2]
chunkSize = index[3]
whFactor = index[4]
return 'KDT{kdt}_SAH{sah}_PS{ps}_CS_{cs}_WF{wf}'\
.format(
kdt=kdtNum,
sah=sahNodes,
ps=parallelNum,
cs=chunkSize,
wf=whFactor
)
# Function to handle summary of performance measurements
def handle_summary(
summary, summaryKey, summaryType,
chunkSize, warehouseFactor, cores,
kdtTime, simTime, fullTime,
kdtSpeedup, simSpeedup, fullSpeedup
):
minTimeArg = np.argmin(fullTime)
minTime = fullTime[minTimeArg]
sk = summary.get(summaryKey, None)
# If summary key does not exist in summary
if sk is None:
summary[summaryKey] = {
summaryType: {
'chunkSize': chunkSize,
'warehouseFactor': warehouseFactor,
'cores': cores[minTimeArg],
'coresSpace': cores,
'kdtTime': kdtTime[minTimeArg],
'simTime': simTime[minTimeArg],
'fullTime': fullTime[minTimeArg],
'fullTimes': fullTime,
'kdtSpeedup': kdtSpeedup[minTimeArg],
'simSpeedup': simSpeedup[minTimeArg],
'fullSpeedup': fullSpeedup[minTimeArg],
'fullSpeedups': fullSpeedup
}
}
else:
skt = sk.get(summaryType, None)
# If summary key does exist in summary but summary type does not
# Or if given summary key-type has a smaller full computation time
if skt is None or skt['fullTime'] > minTime:
sk[summaryType] = {
'chunkSize': chunkSize,
'warehouseFactor': warehouseFactor,
'cores': cores[minTimeArg],
'coresSpace': cores,
'kdtTime': kdtTime[minTimeArg],
'simTime': simTime[minTimeArg],
'fullTime': fullTime[minTimeArg],
'fullTimes': fullTime,
'kdtSpeedup': kdtSpeedup[minTimeArg],
'simSpeedup': simSpeedup[minTimeArg],
'fullSpeedup': fullSpeedup[minTimeArg],
'fullSpeedups': fullSpeedup
}
# Function to find best (KDT, parallelization) pair for given summary entry
def find_summary_best_parallelization(summary_entry):
stat = summary_entry.get('STATIC', None)
dyna = summary_entry.get('DYNAMIC', None)
ware = summary_entry.get('WAREHOUSE', None)
if stat is None and dyna is None and ware is None:
raise Exception(
'find_summary_best_parallelization received None parallelizations'
)
entries = [(stat, 'Static'), (dyna, 'Dynamic'), (ware, 'Warehouse')]
bestEntry = None
bestTime = sys.float_info.max
bestType = 'Unknown'
for entry_pair in entries:
entry = entry_pair[0]
if entry is None:
continue
time = entry['fullTime']
if time < bestTime:
bestEntry = entry
bestTime = time
bestType = entry_pair[1]
if bestType == 'Static':
bestType = 'Static {cs}'.format(cs=bestEntry['chunkSize'])
elif bestType == 'Dynamic':
bestType = 'Dynamic. {cs}'.format(cs=-bestEntry['chunkSize'])
elif bestType == 'Warehouse':
bestType = 'Ware. {cs}x{wf}'.format(
cs=bestEntry['chunkSize'],
wf=bestEntry['warehouseFactor']
)
return bestEntry, bestType
# Function to print summary after it has been built
def print_summary(summary):
print('\n\n\t\tSUMMARY\n\t=======================\n\n')
for skey in summary.keys():
print('{skey}:'.format(skey=skey))
sk = summary[skey]
for stype in sk.keys():
print('\t{stype}:'.format(stype=stype))
skt = sk[stype]
print(
'\t\tchunkSize: {chunkSize}\n'
'\t\twarehouseFactor: {warehouseFactor}\n'
'\t\tcores: {cores}\n'
'\t\tkdtTime: {kdtTime}\n'
'\t\tsimTime: {simTime}\n'
'\t\tfullTime: {fullTime}\n'
'\t\tkdtSpeedup: {kdtSpeedup}\n'
'\t\tsimSpeedup: {simSpeedup}\n'
'\t\tfullSpeedup: {fullSpeedup}\n'
'\n'
.format(
chunkSize=skt['chunkSize'],
warehouseFactor=skt['warehouseFactor'],
cores=skt['cores'],
kdtTime=skt['kdtTime'],
simTime=skt['simTime'],
fullTime=skt['fullTime'],
kdtSpeedup=skt['kdtSpeedup'],
simSpeedup=skt['simSpeedup'],
fullSpeedup=skt['fullSpeedup']
)
)
# Function to generate plot of bests (KDT,Parallelization) cases
def plot_summary(summary):
# Prepare plot
fig = plt.figure(figsize=(16, 12))
# plt.suptitle('Summary plot') # Paper subfigure, better no suptitle
ax = fig.add_subplot(1, 1, 1)
axx = ax.twinx()
plots = []
timeColors = {
'KDT_SIMPLE': 'dodgerblue',
'KDT_SAH': 'orange',
'KDT_AXIS_SAH': 'firebrick',
'KDT_FAST_SAH': 'green'
}
speedupColors = {
'KDT_SIMPLE': 'steelblue',
'KDT_SAH': 'darkorange',
'KDT_AXIS_SAH': 'maroon',
'KDT_FAST_SAH': 'darkgreen'
}
# Plot each summary entry
for kdtType in summary.keys():
if kdtType == 'KDT_AXIS_SAH': # Skip AxisSAH, not interesting atm
continue
kdtTypeStr = 'Unknown'
if kdtType == 'KDT_SIMPLE':
kdtTypeStr = 'Simple'
elif kdtType == 'KDT_SAH':
kdtTypeStr = 'SAH'
elif kdtType == 'KDT_AXIS_SAH':
kdtTypeStr = 'ASAH'
elif kdtType == 'KDT_FAST_SAH':
kdtTypeStr = 'FSAH'
entry, paralleliz = find_summary_best_parallelization(summary[kdtType])
plots.append(ax.plot(
entry['coresSpace'],
entry['fullTimes'],
lw=3,
ls='-',
color=timeColors[kdtType],
zorder=3,
label='{kdtType} {paralleliz} time'.format(
kdtType=kdtTypeStr,
paralleliz=paralleliz
)
)[0])
plots.append(axx.plot(
entry['coresSpace'],
entry['fullSpeedups'],
lw=2,
ls='--',
color=speedupColors[kdtType],
zorder=2,
label='{kdtType} {paralleliz} speedup'.format(
kdtType=kdtTypeStr,
paralleliz=paralleliz
)
)[0])
# Configure plot
labelFontSize = 32
tickFontSize = 28
legendFontSize = 24
ax.set_xlabel('Cores', fontsize=labelFontSize)
ax.set_ylabel('Execution time (s)', fontsize=labelFontSize)
ax.tick_params(axis='both', which='major', labelsize=tickFontSize)
ax.autoscale(enable=True, axis='both', tight=True)
ax.grid(True)
ax.set_axisbelow(True)
# All legends in the same block
# labels = [plot.get_label() for plot in plots]
# ax.legend(plots, labels, loc='upper center', fontsize=legendFontSize)
# Time legend to the left, speedup legend to the right
ax.legend(loc='upper left', fontsize=legendFontSize)
axx.legend(loc='upper right', fontsize=legendFontSize)
axx.set_ylabel('Speedup', fontsize=labelFontSize)
axx.tick_params(axis='y', which='major', labelsize=tickFontSize)
# axx.autoscale(enable=True, axis='both', tight=True) # Autoscale speedup
axx_xticks = ax.get_xticks() # Scale speedup to cores
axx_xticks[-1] -= 1 # Scale speedup to cores
axx.set_yticks(axx_xticks) # Scale speedup to cores
plt.tight_layout()
# Export plot
plt.savefig(
fname='{outpath}'.format(outpath='{outdir}summary_plot'
.format(
outdir=outdir,
plotname=name_from_index(KDT.index[0])
))
)
plt.close()
plt.cla()
plt.clf()
# Function to configure plots
def configure_plot(
ax, xlabel='Cores', ylabel='Seconds',
axx=None, yxlabel='Speed-up'
):
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.autoscale(enable=True, axis='both', tight=True)
ax.grid('both')
ax.set_axisbelow(True)
ax.legend(loc='center left')
if axx is not None:
axx.legend(loc='center right')
axx.set_ylabel(yxlabel)
axx.autoscale(enable=True, axis='both', tight=True)
summary = {}
for DF in DFS:
# Extract data for the plot
KDT = DF.drop('SimulationCores', axis=1).groupby(
BASE_GROUP_LIST+['KDTBuildingCores']
).mean()
SIM = DF.drop('KDTBuildingCores', axis=1).groupby(
BASE_GROUP_LIST+['SimulationCores']
).mean()
kdtCores = [x[5] for x in KDT.index]
kdtTime = [x for x in KDT['KDTBuildTime']]
kdtTime1 = KDT['KDTBuildTime'].iloc[0]
kdtSpeedup = [kdtTime1/x for x in KDT['KDTBuildTime']]
kdtTimeOptIdx = np.argmin(kdtTime)
simCores = [x[5] for x in SIM.index]
simTime = [x for x in SIM['SimulationTime']]
simTime1 = SIM['SimulationTime'].iloc[0]
simSpeedup = [simTime1/x for x in SIM['SimulationTime']]
simTimeOptIdx = np.argmin(simTime)
fullTime = np.add(kdtTime, simTime)
fullTime1 = fullTime[0]
fullSpeedup = [fullTime1/x for x in fullTime]
fullTimeOptIdx = np.argmin(fullTime)
# Fill summary
summaryKey = key_from_index(KDT.index[0])
summaryType = type_from_index(KDT.index[0])
handle_summary(
summary, summaryKey, summaryType,
KDT.index[0][3], KDT.index[0][4], simCores,
kdtTime, simTime, fullTime,
kdtSpeedup, simSpeedup, fullSpeedup
)
# Debug section BEGIN ---
# print('DF:\n', DF)
# print('\nKDT:\n', KDT)
# print('\nSIM:\n', SIM)
# --- Debug section END
# Prepare plot
fig = plt.figure(figsize=(16, 9))
plt.suptitle(title_from_index(KDT.index[0]))
# Subplot 1
ax = plt.subplot(2, 2, 1)
ax.plot(
kdtCores,
kdtTime,
lw=2,
ls='-',
color='blue',
label='KDT building time'
)
if markOptimumTime:
ax.scatter(
kdtCores[kdtTimeOptIdx],
kdtTime[kdtTimeOptIdx],
s=64,
c='blue',
marker='o',
edgecolors='black',
zorder=4
)
axx = ax.twinx()
axx.plot(
kdtCores,
kdtCores,
color='black',
lw=1,
ls='--',
label='Ideal speed-up'
)
axx.plot(
kdtCores,
kdtSpeedup,
lw=1,
ls='-',
color='black',
label='KDT building speed-up'
)
configure_plot(ax, xlabel='KDT Building cores', axx=axx)
# Subplot 2
ax = plt.subplot(2, 2, 2)
ax.plot(
simCores,
simTime,
lw=2,
ls='-',
color='green',
label='Simulation time'
)
if markOptimumTime:
ax.scatter(
simCores[simTimeOptIdx],
simTime[simTimeOptIdx],
s=64,
c='green',
marker='o',
edgecolors='black',
zorder=4
)
axx = ax.twinx()
axx.plot(
simCores,
simCores,
color='black',
lw=1,
ls='--',
label='Ideal speed-up'
)
axx.plot(
simCores,
simSpeedup,
color='black',
lw=1,
ls='-',
label='Simulation speed-up'
)
configure_plot(ax, xlabel='Simulation cores', axx=axx)
# Subplot 3
ax = plt.subplot(2, 2, 3)
ax.plot(
simCores,
fullTime,
lw=2,
ls='-',
color='red',
label='Total time'
)
if markOptimumTime:
ax.scatter(
simCores[fullTimeOptIdx],
fullTime[fullTimeOptIdx],
s=64,
c='red',
marker='o',
edgecolors='black',
zorder=4
)
axx = ax.twinx()
axx.plot(
simCores,
simCores,
color='black',
lw=1,
ls='--',
label='Ideal speed-up'
)
axx.plot(
simCores,
fullSpeedup,
color='black',
lw=1,
ls='-',
label='Total speed-up'
)
configure_plot(ax, axx=axx)
# Subplot 4
ax = plt.subplot(2, 2, 4)
ax.plot(
kdtCores,
kdtTime,
lw=2,
ls='--',
color='blue',
label='KDT building time'
)
ax.plot(
simCores,
simTime,
lw=2,
ls='--',
color='green',
label='Simulation time'
)
ax.plot(
simCores,
fullTime,
lw=2,
ls='-',
color='red',
label='Total time'
)
if markOptimumTime:
ax.scatter(
simCores[fullTimeOptIdx],
fullTime[fullTimeOptIdx],
s=64,
c='red',
marker='o',
edgecolors='black',
zorder=4
)
axx = ax.twinx()
axx.plot(
simCores,
simCores,
color='black',
lw=1,
ls='--',
label='Ideal speed-up'
)
axx.plot(
simCores,
fullSpeedup,
color='black',
lw=1,
ls='-',
label='Total speed-up'
)
configure_plot(ax, axx=axx)
# Post-process plot
plt.tight_layout()
# Export plot
# plt.show()
plt.savefig(
fname='{outpath}'.format(outpath='{outdir}{plotname}'
.format(
outdir=outdir,
plotname=name_from_index(KDT.index[0])
))
)
plt.close()
plt.cla()
plt.clf()
print_summary(summary)
plot_summary(summary)