-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProcessYcsbLog.py
executable file
·1566 lines (1501 loc) · 77.5 KB
/
ProcessYcsbLog.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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import copy
import gzip
from dateutil import tz
import jinja2
import logging
import argparse
import magic
import os
import re
import datetime
import locale
import cPickle
import bokeh.charts
from itertools import islice
import pdfkit
import pytz
import Util
import webcolors
import threading
import signal
__author__ = 'Andreas Bader'
__version__ = "0.03"
# in 0.02 some dicts were replaced with lists.
# reason: when parsing large result files (100k buckets = 400k lines)
# <dict>.keys() is getting relatevly slow, but amound of keys stays the same
# which is kind of strange
# so replacing those dicts with lists helps a great deal
# also some other speed-affecting changes were made
# Threading, blockwise-reading etc.
# some variable names will a bit weird (like <something>Dict for a list) because of this
# Also since 0.02 we won't save the whole log file into ydc anymore, as this seem to be a bit overkill
# This should not affect older 0.01 logs, but could happen. However, "LatencyList" was renamed, so this version can't read 0.01 anymore.
# Also correct timezone awareness was added
# 0.03 calculates 99% and 95% also in us, old files cannot be read. This reflects the update to YCSB 0.4.0
# For reading 0.2.0 files, replace "99thPercentileLatency(us)" with "99thPercentileLatency(ms)" and for 95th accordingly
# in Line 74, 75, 156, 157, 1207, 1208, 1252, 1253, 1254, 1255, 1296, 1297, 1298, 1299
plotColorDict={"DEFAULT" : "blue",
"INSERT0" : "red",
"INSERT1" : "darkred",
"READ0" : "orange",
"READ1" : "darkorange",
"CLEAN0" : "green",
"CLEAN1" : "darkgreen",
"UPDATE0" : "purple",
"UPDATE1" : "darkpurple"
}
defaultPlotColor=plotColorDict["DEFAULT"]
maxTableColumnsSingle=6
maxTableColumnsMulti=10
templateFile="template.html" #Jinja2 Template, see http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh.embed.file_html
templateFileMulti="template_multi.html" #Jinja2 Template, see http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh.embed.file_html
pdfOptions = {
'page-size': 'A4',
'margin-top': '0.5cm',
'margin-right': '0.5cm',
'margin-bottom': '0.5cm',
'margin-left': '0.5cm',
'encoding': "UTF-8",
'no-outline': None,
'quiet': '',
'dpi' : 600,
'image-dpi' : 600,
'image-quality' : 94,
'title' : ""
}
ignoreParams = ["Operations", "Return", "LatencyList"] # parameters that should be ignored (LatencyList e.g.)
possibleMissingParams = ["99thPercentileLatency(us)","95thPercentileLatency(us)"] #Params that can be missing, replaced by -1
convertFromUsToMs = ["AverageLatency(us)", "MinLatency(us)", "MaxLatency(us)", "99thPercentileLatency(us)","95thPercentileLatency(us)" ] # Some special parameters need to be converted
def signal_handler(signal, frame):
os._exit(0)
signal.signal(signal.SIGINT, signal_handler)
def find_time(timeString,logger):
timeRegex="[A-Za-z]+\s+[A-Za-z]+\s+[0-9]+\s+[0-9]+:[0-9]+:[0-9]+\s+[A-Za-z]+\s+[0-9]+"
if re.search(timeRegex,timeString) != None:
act_loc=locale.getlocale()
try:
locale.setlocale(locale.LC_ALL,'en_US.UTF-8')
except Exception, e:
logger.error('Failed to set locale, do you have locale en_US.UTF-8 installed?', exc_info=True)
os._exit(-1)
try:
timeObj=datetime.datetime.strptime(re.search(timeRegex,timeString).group(), '%a %b %d %H:%M:%S %Z %Y')
timeObj=timeObj.replace(tzinfo=tz.gettz(re.search(timeRegex,timeString).group().split(" ")[4]))
locale.setlocale(locale.LC_ALL,act_loc)
return timeObj
except Exception, e:
logger.warning("Failed to parste timezone from '%s', got '%s'. Setting it to UTC, this may be wrong."
%(re.search(timeRegex,timeString).group(),
re.search(timeRegex,timeString).group().split(" ")[4]), exc_info=True)
timeObj=timeObj.replace(tzinfo=tz.gettz('UTC'))
locale.setlocale(locale.LC_ALL,act_loc)
return timeObj
else:
logger.error("Can't find time in '%s'." %(timeString))
os._exit(-1)
# converts timestring to timeobject
# checks if value is already set (should not happen that a value is found twice)
def process_time(line,key,dict,logger):
if key in dict.keys():
logger.error("Found two %s, this should not happen!" %(key))
os._exit(-1)
dict[key] = find_time(line,logger)
# converts spacestring
def process_space(line, dict,logger):
spaceSplitters = line.replace("SPACE: ","").split(" ")
if len(spaceSplitters) == 3:
dict["spaceBegin"] = spaceSplitters[0]
dict["spaceBetween"] = spaceSplitters[1]
dict["spaceEnd"] = spaceSplitters[2]
else:
logger.error("Error while processing space string '%s'" %(line))
os._exit(-1)
# converts float (throughput, runtime)
def process_float(line, dict, key, logger):
splitters = line.split(", ")
if len(splitters) == 3:
dict[key] = float(splitters[2])
else:
logger.error("Error while processing float string '%s'" %(line))
os._exit(-1)
# checks if we have a line according to one of the known blocks
def check_block(line, knownBlocktypes):
for type in knownBlocktypes:
if re.search("^\[%s\]" %(type),line) != None:
return True
return False
# parses one actual line (=value) into a existing block dict
# blockDict = dict which contains values of the actual block (block ex. READ)
# two typical ycsb lines as example:
# [READ], 99thPercentileLatency(us), 4
# [READ], 0, 397
# this translates as follows to the arguments:
# [blockName], name, value
# rewrote in 0.02 for using lists in some steps instead of dicts, brings some speedup!
def parse_block(blockDict, blockName, name, value, timeSeries, logger):
# save every known name + conversion method
knownValues={"Operations": int,
"AverageLatency(us)" : float,
"MinLatency(us)" : int,
"MaxLatency(us)" : int,
"95thPercentileLatency(us)": int,
"99thPercentileLatency(us)" : int}
if name in knownValues.keys():
# Check if value was already found in this block, should not happen!
if name not in blockDict.keys():
try:
blockDict[name] = knownValues[name](value)
except ValueError:
logger.error("Error while convertion in block '%s' with value '%s'." %(blockName, value))
os._exit(-1)
else:
logger.error("Found another '%s' value in block '%s' with value '%s'. Should not happen." %(name, blockName, value))
os._exit(-1)
elif "Return=" in name:
# Return Value looks like this name: Return=0, value: 123
if "Return" not in blockDict.keys():
blockDict["Return"] = []
try:
blockDict["Return"].append([int(name.replace("Return=","")),int(value)])
except ValueError:
logger.error("Error while convertion in block '%s' with value '%s'." %(blockName, value))
os._exit(-1)
else:
# here we should have only histogram or timeseries values
# ex. [READ], 0, 397
# ex. [READ], 1, 101
# the last value has propbably a ">" in its name, ignore that.
try:
if "LatencyList" not in blockDict.keys():
blockDict["LatencyList"] = []
if timeSeries:
blockDict["LatencyList"].append(float(value)/1000.0)
else:
blockDict["LatencyList"].append(int(value))
except ValueError:
logger.error("Error while convertion in block '%s' with value '%s' and name '%s'." %(blockName, value, name))
os._exit(-1)
except:
logger.error("Unknown error occured while convertion in block '%s' with value '%s' and name '%s'. Maybe unknwon block value?" %(blockName, value, name))
os._exit(-1)
# processes one actual known block
# look below at process_file(..) for more explanation (data structure,..)
# actBlock should be mutable, but Strings are immutable, so actBlock should be a list with a string in it.. ;)
# rewrote in 0.02 for using lists in some steps instead of dicts, brings some speedup!
def process_block(fileDict, line, blockIndices, actBlock, timeSeries, logger):
splitters = line.split(", ")
if len(splitters) == 3:
# check if it is the first block we ever encounter or if we are at a new block
blockName=splitters[0].replace("[","").replace("]","")
if actBlock[0] == "" or blockName != actBlock[0]:
# save that we are in a new block
actBlock[0] = blockName
# check if fileDict contains the blocks dict
if "blocks" not in fileDict.keys():
fileDict["blocks"] = {}
# check if dict already knews it
if blockName not in fileDict["blocks"].keys():
fileDict["blocks"][blockName] = []
# fileDict["blocks"][blockName] = {}
# search for new index if types of this block already exist
newIndex=0
if len(fileDict["blocks"][blockName]) > 0:
newIndex = len(fileDict["blocks"][blockName])
fileDict["blocks"][blockName].append({})
parse_block(fileDict["blocks"][blockName][newIndex], blockName, splitters[1], splitters[2], timeSeries, logger)
else:
# okay we just have to add some value to this already seen block
parse_block(fileDict["blocks"][blockName][-1], blockName, splitters[1], splitters[2], timeSeries, logger)
else:
logger.error("Error while processing line '%s'" %(line))
os._exit(-1)
def process_file(filename, timeSeries, fileDict, compressedFileName, logger):
if not Util.check_file_readable(filename):
logger.error("Can't open %s." % (filename))
return
file = open(filename,"r")
actBlock=[""] # saves in which type of block we are, must be mutable!
knownBlocktypes=["CLEANUP", "INSERT", "READ", "UPDATE", "SCAN", "AVG", "SUM", "COUNT"] # saves which types of blocks we know
# fileDict must be mutable!
# the following keys can exist
# dbName -> name of dbms (mysql e.q.)
# dbDesc -> description of dbms (mysql e.q.)
# description -> description of the workload
# errors -> [] (errors occured)
# warnings -> [] (warnings occured)
# exceptions -> [] (exceptions occured)
# workload -> name of workload (workloada e.g.)
# startTime -> overall start time
# endTime -> overall end time
# startRunTime -> RUN phase start time
# endRunTime -> RUN phase end time
# startLoadTime -> LOAD phase start time
# endLoadTime -> LOAD phase end time
# spaceBegin -> Space of DB folder before any workload (before LOAD phase)
# spaceBetween -> Space of DB folder between LOAD and RUN phase
# spaceEnd -> Space of DB folder after RUN phase
# runtimeLoad -> runtime (ycsb) of LOAD phase
# runtimeRun -> runtime (ycsb) of RUN phase
# throughputLoad -> throughput (ycsb) of RUN phase
# throughputRun -> throughput (ycsb) of RUN phase
# blocks -> dict of blocks (ycsb)
# filecontent -> content of original ycsb file (ycsb) -> Dropped with 0.02!
# timeseries -> true/false -> generate ts output (arguments can overwrite it)
# granularity -> integer for ts granularity
# bucket -> integer for histogram buckets
# (ycsb) means that this is measured by ycsb
# blocks itself looks like:
# {"CLEANUP": {}, "INSERT": {}, "READ": {}, "UPDATE": {}}
# the embedded dicts look like this (ex. for INSERT)
# {0 : {}, 1 : {}} # 0 = first encountered INSERT block, 1 = second encountered INSERT block ...
# {} contains the actual values of one block
# ex. one READ Block (latencies are truncated)
# [READ], Operations, 511
# [READ], AverageLatency(us), 860.4833659491194
# [READ], MinLatency(us), 404
# [READ], MaxLatency(us), 14309
# [READ], 95thPercentileLatency(us), 1
# [READ], 99thPercentileLatency(us), 4
# [READ], Return=0, 511
# [READ], 0, 397
# [READ], 1, 101
# ...
# the dict would be.: {"Operations" : 511, "AverageLatency(us)" : 860.4833659491194, "MinLatency(us)": 404, "MaxLatency(us)" : 14309 ,"95thPercentileLatency(us)" : 1, "99thPercentileLatency(us)" : 4, "Return" : [0,511] , "LatencyList" : {0 : 397, 1 : 101, ,...} }
# look at https://github.com/brianfrankcooper/YCSB/wiki/Running-a-Workload how to interpret the ycsb values
# in case timeseries instead of histogramm is used, there will be floats instead of integers as values (ex. [READ], 1, 101.11)
# split filename to get db & workload name
# e.g. ycsb_mysql_workloada_201507282238.log
fileNameSplitters=filename.split("_")
if len(fileNameSplitters) >= 4:
fileDict["dbName"]=fileNameSplitters[1]
for splitter in fileNameSplitters[2:len(fileNameSplitters)-2]:
fileDict["dbName"]+="_%s" %(splitter)
fileDict["workload"]=fileNameSplitters[len(fileNameSplitters)-2]
else:
logger.error("Can't parse filename '%s'." %(filename))
os._exit(-1)
fileDict["errors"] = [];
fileDict["warnings"] = [];
fileDict["exceptions"] = [];
fileDict["description"] = "";
# process lines
# Using the blockwise list(islice(..)) version, as it is a little bit faster than pure 'for line in file:'
while True:
lines = list(islice(file, 100))
if not lines:
break
for line in lines:
if re.search("Start Test$",line) != None:
# Starttime whole measurement
process_time(line,"startTime", fileDict, logger)
elif re.search("error",line.lower()) != None:
fileDict["errors"].append(line)
elif re.search("warn",line.lower()) != None:
fileDict["warnings"].append(line)
elif re.search("exception",line.lower()) != None:
fileDict["exceptions"].append(line)
elif re.search("^\[DESCRIPTION\]",line) != None:
fileDict["description"] = line.replace("[DESCRIPTION],","")
if fileDict["description"][0] == " ":
fileDict["description"] = fileDict["description"][1:]
continue
elif re.search("^DESCRIPTION",line) != None:
try:
fileDict["dbDesc"] = line.split("DESCRIPTION: ")[1]
except Exception, e:
logger.warning("Couldn't process DESCRIPTION line '%s', ignoring it." %(line), exc_info=True)
fileDict["dbDesc"] = ""
elif re.search("Start Load$",line) != None:
# Starttime LOAD phase
process_time(line,"startLoadTime", fileDict, logger)
elif re.search("End Load$",line) != None:
# Endtime LOAD phase
process_time(line,"endLoadTime", fileDict, logger)
elif re.search("Start Run$",line) != None:
# Starttime RUN phase
process_time(line,"startRunTime", fileDict, logger)
elif re.search("End Run$",line) != None:
# Endtime RUN phase
process_time(line,"endRunTime", fileDict, logger)
elif re.search("End Test$",line) != None:
# Endtime whole measurement
process_time(line,"endTime", fileDict, logger)
elif re.search("^SPACE:",line) != None:
# found line with space
process_space(line, fileDict, logger)
elif re.search("^TIMESERIES",line) != None:
# if Timeseries is set or unset
if re.search("1$",line) != None:
fileDict["timeseries"] = True
timeSeries = True
elif re.search("0$",line) != None:
fileDict["timeseries"] = False
else:
logger.warning("Couldn't process TIMESERIES line '%s', ignoring it." %(line))
elif re.search("^GRANULARITY",line) != None:
# Granularity for ts
try:
fileDict["granularity"] = int(line.split("GRANULARITY: ")[1])
except Exception, e:
logger.warning("Couldn't process GRANULARITY line '%s', ignoring it." %(line), exc_info=True)
elif re.search("^BUCKET",line) != None:
# histogram Buckets
try:
fileDict["bucket"] = int(line.split("BUCKET: ")[1])
except Exception, e:
logger.warning("Couldn't process BUCKET line '%s', ignoring it." %(line), exc_info=True)
elif re.search("^\[OVERALL\]",line) != None:
if "RunTime" in line:
if "runtimeLoad" in fileDict.keys():
# runtimeLoad was found, now it has to be Run
process_float(line, fileDict, "runtimeRun", logger)
elif "runtimeRun" in fileDict.keys():
# both already found, third one should not happen
logger.error("Found third runTime in '%s'." %(line))
os._exit(-1)
else:
# nothing set, must be Load phase
process_float(line, fileDict, "runtimeLoad", logger)
elif "Throughput" in line:
if "throughputLoad" in fileDict.keys():
# throughputLoad was found, now it has to be Run
process_float(line, fileDict, "throughputRun", logger)
elif "throughputRun" in fileDict.keys():
# both already found, third one should not happen
logger.error("Found third throughput in '%s'." %(line))
os._exit(-1)
else:
# nothing set, must be Load phase
process_float(line, fileDict, "throughputLoad", logger)
else:
logger.error("Did not found 'RunTime' nor 'Throughput' in '%s'." %(line))
os._exit(-1)
# found line with space
process_space(line, fileDict, logger)
elif check_block(line, knownBlocktypes):
# check if fileDict contains the blocks dict
process_block(fileDict, line, knownBlocktypes, actBlock, timeSeries, logger)
## AVG,SUM, usw.
for blockKey in fileDict["blocks"].keys():
## AVG0,SUM0, usw.
for listBlock in fileDict["blocks"][blockKey]:
if "LatencyList" not in listBlock.keys():
logger.error("The 'LatencyList' is missing Block %s in %s." %(blockKey,listBlock,filename))
os._exit(-1)
# "0"-"999" + ">1000" = 1001 Entrys for 1000 buckets for ex.
if len(listBlock["LatencyList"]) != int(fileDict["bucket"])+1:
logger.error("There are buckets missing for %s%s in %s. Available Buckets: %s, configured amount of buckets: %s(+1)." %(blockKey,listBlock,filename,len(listBlock["LatencyList"]),int(fileDict["bucket"])))
os._exit(-1)
try:
file = gzip.open(compressedFileName,"w")
cPickle.dump(fileDict,file)
file.flush()
file.close()
except Exception, e:
logger.error("Can't open '%s' to write. Is it writable?" %(compressedFileName), exc_info=True)
os._exit(-1)
return fileDict
# replaces bokeh.charts.Bar because it can't do logarithmic scale
def generate_bar_plot(dataDict, cat, legendPos, legendOri, title, ylabel, xlabel, width, height, logger):
maxValue=0
for dataKey in dataDict.keys():
for dataPoint in dataDict[dataKey]:
if dataPoint >= maxValue:
try:
dataPointStr = str(dataPoint)
if "." in dataPointStr:
dataPointStr = dataPointStr.split(".")[0]
maxValue = 10**len(dataPointStr)
except:
logger.error("Can't convert '%s' to string. Can't generate bar plot." %(dataPoint))
return None
if maxValue == 0:
logger.error("Maximum value is 0. Can't generate bar plot.")
return None
p = bokeh.plotting.figure(title=title, y_axis_type="log", x_range=cat, y_range=[0,maxValue], width=width, height=height)
dataLen = -1
for dataKey in dataDict.keys():
if dataLen == -1:
dataLen = len(dataDict[dataKey])
else:
if dataLen != len(dataDict[dataKey]):
logger.error("Some dataLists in dataDict have different lengths. Can't generate bar plot.")
return None
if dataLen == -1:
logger.error("Can't find list length. Can't generate bar plot.")
return None
keyLen = float(len(dataDict.keys()))
groupSep = min(max(0.0015,1.0/dataLen),0.1)
barSep = min(max(0.00015,1.0/keyLen),0.025)
barStart = (groupSep - (barSep*(keyLen/2.0)) + barSep)/2.0
barWidth = max((1.0-groupSep-(barSep*keyLen))/keyLen,0.005)
#groupSep = 0.2
defaultColors=[66,88,104,32,131,143,40,92,41,45]
# colors that are hard to see against white (see http://www.w3schools.com/cssref/css_colornames.asp)
chosenColors=[122,48,144,142,109,24,107,55,126,90,91,36,112,76,133,103,130,128,132,94,46,6,58,14,146,70,23,28,96,10,20,99,80,113,31,137]
for dataKey in sorted(dataDict.keys()):
left=[]
right=[]
top=[]
bottom=[]
color = Util.get_random_int_with_chosen_default(0, len(webcolors.css3_names_to_hex.keys())-1,chosenColors,defaultColors)
if color == None:
logger.error("Not enough colors. Can't generate bar plot.")
return None
chosenColors.append(color)
# for dataPoint in dataDict[dataKey][::-1]:
for dataPoint in dataDict[dataKey]:
if len(right) != len(left) != len(top):
logger.error("Some error occured. Can't generate bar plot.")
return None
counter=len(left)+1-((barWidth*keyLen)+groupSep+(barSep*(keyLen/2.0)))/2.0
left.append(counter+barStart)
right.append(counter+barStart+barWidth)
top.append(dataPoint)
bottom.append(0)
logger.info("%s %s %s %s %s %s %s %s %s" %(dataKey, barStart, barWidth, dataLen, counter, groupSep, barSep, left,right))
#p.quad(bottom=bottom, top=top, left=left, right=right, color=webcolors.css3_names_to_hex[webcolors.css3_names_to_hex.keys()[color]], legend="%s_%s"%(dataKey,counter2))
# There is an error on Bokeh in the line above: If any of the top values is zero, alle bars/quads will be drawn as zero. Drawing them non-grouped fixes this.
# This is independent from the set y-range (-1 or 0 does not effect this)
# See https://github.com/bokeh/bokeh/issues/3022
for i in range(0,len(top)):
p.quad(bottom=bottom[i], top=top[i], left=left[i], right=right[i], color=webcolors.css3_names_to_hex[webcolors.css3_names_to_hex.keys()[color]], legend=dataKey)
barStart+= barWidth + barSep
p.xaxis.axis_label_text_font_size = "10pt"
p.yaxis.axis_label_text_font_size = "10pt"
p.yaxis.axis_label = ylabel
p.xaxis.axis_label = xlabel
#p.y_range = (0, 10000)
p.legend.location = legendPos
p.legend.orientation = legendOri
return p
# generates plots for every block/index in dict
# Only for one measurement -> "single"
def generate_plot_single(dict, timeseries, logger, tick=1000):
dataDict = { "histogram" : {}, "general" : {} }
gridplotList = []
gridRowCount = 0
gridRowMax = 2
# Get Data for both plots
if args.debug:
Util.log_timestamp("Start Generating histogramm data",logger)
for block in dict["blocks"].keys():
counter=0
for blockList in dict["blocks"][block]:
dataDict["histogram"]["%s%s" %(block,counter)] = generate_histogram_data(blockList["LatencyList"], logger)
counter += 1
if args.debug:
Util.log_timestamp("Start Generating general data",logger)
dataDict["general"] = generate_general_data(dict["blocks"], True, False, logger)
if "TIMESERIES" in dataDict.keys() and dataDict["TIMESERIES"]:
timeseries = True
if "GRANULARITY" in dataDict.keys():
tick = dataDict["GRANULARITY"]
elif timeseries:
try:
tick = sorted(dataDict["histogram"][dataDict["histogram"].keys()[0]]["cat"])[1]-sorted(dataDict["histogram"][dataDict["histogram"].keys()[0]]["cat"])[0]
except Exception, e:
logger.warning("Couldn't process GRANULARITY on base of histogramm data. Default to 1000.", exc_info=True)
tick=1000
# generate General block plot
#p = bokeh.charts.Bar(dataDict["general"]["data"], cat=dataDict["general"]["cat"], legend="top_right", title="Block results:",
# ylabel='Latency in ms', xlabel = "Type of latency", width=650, height=350)
if args.debug:
Util.log_timestamp("Start Generating bar plot",logger)
p = generate_bar_plot(dataDict["general"]["data"], dataDict["general"]["cat"], "top_left", "horizontal", "Block results:",
"Latency in ms", "Type of latency", 650, 350, logger)
if args.debug:
Util.log_timestamp("End Generating bar plot",logger)
if p == None:
return None
if gridRowMax < 2:
gridplotList.append(p)
elif gridRowCount == gridRowMax-1:
gridplotList[-1].append(p)
gridRowCount=0
else:
gridplotList.append([p])
gridRowCount+=1
if args.debug:
Util.log_timestamp("Start Generating histograms",logger)
# Generate histograms
for key in dataDict["histogram"].keys():
if len(dataDict["histogram"][key]["data"]) < 2 and \
len(dataDict["histogram"][key]["data2"]) < 2 and \
len(dataDict["histogram"][key]["cat"]) < 2:
if "CLEANUP" in key and timeseries:
logger.info("Do not produce '%s' plots since timeseries is active and therefore only 1 value is given." %(key))
else:
logger.warning("Only 1 value for '%s', can't produce plots for this block." %(key))
continue
p = bokeh.plotting.figure(title="Query time for %s" %(key),
x_range=[0,max(dataDict["histogram"][key]["cat"])], y_range=[0, max(dataDict["histogram"][key]["data"])+max(dataDict["histogram"][key]["data"])/10.0],
plot_width=650, plot_height=350)
p.xaxis.axis_label_text_font_size = "10pt"
p.yaxis.axis_label_text_font_size = "10pt"
if timeseries:
p.yaxis.axis_label = "Avg. Latency since last tick (every %s ms) in ms" %(tick)
p.xaxis.axis_label = "Elapsed time in ms"
p.xaxis[0].ticker = bokeh.models.SingleIntervalTicker(interval=tick)
else:
p.xaxis.axis_label = "Time in ms"
p.yaxis.axis_label = "Amount of queries completed"
color = defaultPlotColor
if key in plotColorDict.keys():
color = plotColorDict[key]
if timeseries:
sortedCatList, sortedDataList = (list(t) for t in zip(*sorted(zip(dataDict["histogram"][key]["cat"], dataDict["histogram"][key]["data"]))))
p.line(sortedCatList, sortedDataList, line_width=2)
p.circle(dataDict["histogram"][key]["cat"], dataDict["histogram"][key]["data"], fill_color="white", size=8)
else:
p.rect(x=dataDict["histogram"][key]["cat"], y=dataDict["histogram"][key]["data2"], width=0.8,
height=dataDict["histogram"][key]["data"], color=color, alpha=1)
if gridRowMax < 2:
gridplotList.append(p)
continue
if gridRowCount == gridRowMax-1:
gridplotList[-1].append(p)
gridRowCount=0
else:
gridplotList.append([p])
gridRowCount+=1
if args.debug:
Util.log_timestamp("End Generating histograms",logger)
if args.debug:
Util.log_timestamp("Start adding plots to bokeh",logger)
p = bokeh.io.gridplot(gridplotList)
if args.debug:
Util.log_timestamp("End adding plots to bokeh",logger)
return p
# generates plots for every block/index and every dict in dicts
# Only for more than one measurement -> "multi"
# no histogram in combined plots
# only comparison plots/tables
def generate_plot_multi(dicts, timeseries, logger, tick=1000):
gridplotList = []
dataDictBlocks = {}
# structure of dataDictBlocks should look like this:
# <blocktype>
# -> "data"
# -> <dbName>
# -> [1,2,3]
# ...
# ...
# -> "cat"
# -> <paramName>
# -> ...
# <blockType> e.g. "INSERT0"
# <dbName> e.g. "MySQL"
# <paramName> e.g. "AvgLatency"
# getting blocktypes and data
generate_block_data(dataDictBlocks, dicts, True, False, logger)
# generating general graphs like avgLatency etcpp.
for blockKey in dataDictBlocks.keys():
#p = bokeh.charts.Bar(dataDictBlocks[blockKey]["data"], cat = dataDictBlocks[blockKey]["cat"], legend = "top_right",
# title = "Results for block %s:" % (blockKey), ylabel = 'Latency in ms', xlabel = "Type of latency", width=1300, height=700)
# dataDictBlocks[blockKey]["cat"]=['Avg.', '95Perc.', '99Perc.', 'Min', 'Max',]
# p = generate_bar_plot(dataDictBlocks[blockKey]["data"], dataDictBlocks[blockKey]["cat"][::-1],
p = generate_bar_plot(dataDictBlocks[blockKey]["data"], dataDictBlocks[blockKey]["cat"],
"top_left", "horizontal", "Results for block %s:" % (blockKey),
"Latency in ms", "Type of latency", 1300, 700, logger)
if p != None:
gridplotList.append([p])
else:
logger.error("An error occured while generting plot for %s." %(blockKey))
# generating graphs for runtimeRun/Load
runtimeDict = { "data" : {}, "cat" : [ "runtimeLoad", "runtimeRun" ] }
for key in dicts.keys():
if "runtimeLoad" in dicts[key].keys() and "runtimeRun" in dicts[key].keys():
runtimeDict["data"][key]=[dicts[key]["runtimeLoad"],dicts[key]["runtimeRun"]]
else:
logger.error("Can't find 'runtimeLoad' or/and 'runtimeRun' in %s dict. Can't go on." %(key))
os._exit(-1)
# p = bokeh.charts.Bar(runtimeDict["data"], cat = runtimeDict["cat"], legend = "top_right",
# title = "Results for runtime:", ylabel = 'Runtime in ms', xlabel = "Type of runtime", width=1300, height=700)
# gridplotList.append([p])
p = generate_bar_plot(runtimeDict["data"], runtimeDict["cat"],
"top_left", "horizontal", "Results for runtime:",
"Runtime in ms", "Type of runtime", 1300, 700, logger)
if p != None:
gridplotList.append([p])
else:
logger.error("An error occured while generting plot for runtimeDict.")
# generating graphs for throughputLoad/Run
runtimeDict = { "data" : {}, "cat" : [ "throughputLoad", "throughputRun" ] }
for key in dicts.keys():
if "throughputLoad" in dicts[key].keys() and "throughputRun" in dicts[key].keys():
runtimeDict["data"][key]=[dicts[key]["throughputLoad"],dicts[key]["throughputRun"]]
else:
logger.error("Can't find 'throughputLoad' or/and 'throughputRun' in %s dict. Can't go on." %(key))
os._exit(-1)
# p = bokeh.charts.Bar(runtimeDict["data"], cat = runtimeDict["cat"], legend = "top_right",
# title = "Results for throughput:", ylabel = 'Throughput in operations per sec.', xlabel = "Type of throughput", width=1300, height=700)
# gridplotList.append([p])
p = generate_bar_plot(runtimeDict["data"], runtimeDict["cat"],
"top_left", "horizontal", "Results for throughput:",
"Throughput in operations per sec.", "Type of throughput", 1300, 700, logger)
if p != None:
gridplotList.append([p])
else:
logger.error("An error occured while generting plot for throughput.")
# generating graphs for spaceLoad/spaceRun:
# spaceLoad = spaceBetween - spaceBegin
# spaceRun = spaceEnd - spaceBetween
runtimeDict = { "data" : {}, "cat" : [ "spaceLoad", "spaceRun" ] }
for key in dicts.keys():
if "spaceBegin" in dicts[key].keys() and "spaceEnd" in dicts[key].keys() and "spaceBetween" in dicts[key].keys():
try:
runtimeDict["data"][key]=[int(dicts[key]["spaceBetween"]) - int(dicts[key]["spaceBegin"]), int(dicts[key]["spaceEnd"]) - int(dicts[key]["spaceBetween"])]
except:
logger.error("Error while converting 'spaceBegin' '%s' or/and 'spaceBetween' '%s' or/and 'spaceEnd' '%s' in %s dict to int. Can't go on." %(dicts[key]["spaceBegin"], dicts[key]["spaceBetween"], dicts[key]["spaceEnd"], key))
os._exit(-1)
else:
logger.error("Can't find 'spaceBegin' or/and 'spaceBetween' or/and 'spaceEnd' in %s dict. Can't go on." %(key))
os._exit(-1)
# p = bokeh.charts.Bar(runtimeDict["data"], cat = runtimeDict["cat"], legend = "top_right",
# title = "Results for space consumption:", ylabel = 'Space consumption in Kilobyte (kB)', xlabel = "Type of space consumption", width=1300, height=700)
# gridplotList.append([p])
p = generate_bar_plot(runtimeDict["data"], runtimeDict["cat"],
"top_left", "horizontal", "Results for space consumption:",
"Space consumption in Kilobyte (kB)", "Type of space consumption", 1300, 700, logger)
if p != None:
gridplotList.append([p])
else:
logger.error("An error occured while generting plot for space consumption.")
p = bokeh.io.gridplot(gridplotList)
return p
# generates block data for multi dict block graphs
# in dataDictBlocks the following structure is found after returning:
# <blocktype>
# -> "data"
# -> <dbName>
# -> [1,2,3]
# ...
# ...
# -> "cat"
# -> <paramName>
# -> ...
# <blockType> e.g. "INSERT0"
# <dbName> e.g. "MySQL"
# <paramName> e.g. "AvgLatency"
def generate_block_data(dataDictBlocks, dicts, ignoreSomeParameters, ignoreLess, logger):
firstRound = True # check if everyone has same block types
for key in dicts.keys():
# generate_general_data deliveres the following structure:
# "data"
# -> <blockType>
# -> <parameters>
# "cat"
# -> <paramName>
# -> ...
# we have to move that a little bit...
data = generate_general_data(dicts[key]["blocks"], ignoreSomeParameters, ignoreLess, logger)
keyCopyTmp = list(dataDictBlocks.keys()) # True Copy # check if every block is in every dict
for block in dicts[key]["blocks"].keys():
for index in range(0,len(dicts[key]["blocks"][block])):
blockname = "%s%s" % (block, index)
if firstRound and blockname not in dataDictBlocks.keys():
dataDictBlocks[blockname] = {"data": {}, "cat": []}
if dataDictBlocks[blockname]["cat"] == []:
dataDictBlocks[blockname]["cat"] = data["cat"]
elif blockname not in dataDictBlocks.keys():
logger.error(
"Found blocktype '%s' (index '%s') that does only belong to dict '%s'. Can't move on." % (
block, index, key))
os._exit(-1)
else:
keyCopyTmp.remove(blockname)
if key not in dataDictBlocks[blockname]["data"].keys():
dataDictBlocks[blockname]["data"][key] = data["data"][blockname]
else:
logger.error("Found key '%s' more than once for block '%s', index '%s'. Can't move on." % (
key, block, index))
os._exit(-1)
# check if the right amount of parameters is there
if len(dataDictBlocks[blockname]["data"][key]) != len(dataDictBlocks[blockname]["cat"]) and not ignoreLess:
logger.error("Found more or less parameters than needed in key '%s'. Needed: %s, Found: %s." % (
key, len(dataDictBlocks[blockname]["cat"]), len(dataDictBlocks[blockname]["data"][key])))
os._exit(-1)
if not firstRound:
if len(keyCopyTmp) > 0:
logger.error("Found less keys than needed in '%s'. Needed: '%s'." % (key, keyCopyTmp))
os._exit(-1)
firstRound = False
# generates html file for given html text
def generate_html(p, templateFile, templateDict, outputFile, overwrite, logger):
if not Util.check_file_exists(templateFile):
logger.error("Template file does not exist: '%s'" %(templateFile))
os._exit(-1)
try:
template = jinja2.Environment(loader = jinja2.FileSystemLoader(searchpath=os.path.split(templateFile)[0])).get_template(os.path.split(templateFile)[1])
except Exception, e:
logger.error("Failed load template file '%s'" %(templateFile), exc_info=True)
os._exit(-1)
html = bokeh.embed.file_html(models=p, resources=bokeh.resources.INLINE, title=templateDict["title"] , template=template, template_variables=templateDict)
if Util.check_file_exists(outputFile) and not overwrite:
logger.error("Html file does exist: '%s'. Delete or use overwrite flag." %(outputFile))
os._exit(-1)
try:
file = open(outputFile,"w")
file.write(html)
file.close()
except Exception, e:
logger.error("Error while writing html file '%s'" %(outputFile), exc_info=True)
os._exit(-1)
# generates bokeh histogram_data
# gets data from every "LatencyList"
# data2 is just data/2.0
# commented out code is old and better to read but much slower due to "key not in" - if
def generate_histogram_data(list, logger):
if args.debug:
Util.log_timestamp("Start Generating histogram",logger)
dataDict = { "data" : [], "data2" : [], "cat" : []}
# consits of dicts: data and cat
# counter=0
dataDict["data"]=list
dataDict["data2"]=[i/2.0 for i in list]
dataDict["cat"]=range(0,len(list))
# for value in list:
# # factor 2 has to be divided as you set a "center point" for your rectangles, otherwise 0 won't be 0
# dataDict["data"].append(value)
# dataDict["data2"].append(value/2.0)
# if key not in dataDict["cat"]:
# Util.log_timestamp(counter,logger)
# dataDict["cat"].append(counter)
# counter += 1
if args.debug:
Util.log_timestamp("End Generating histogram",logger)
return dataDict
# generates bokeh general block data
# gets the "blocks" key of fileDict (see above method process_file(...))
# use data from every block in blocks, from every index in every block
# gets every "Throughput","AverageLatency",...
# if you set param you only get your chosen value like Throughput e.g.
def generate_general_data(dict, ignoreSomeParameters, ignoreLess, logger):
dataDict = { "data" : {}, "cat" : [] }
firstRun = True
for block in dict.keys():
for counter in range(0,len(dict[block])):
dataDict["data"]["%s%s" % (block,counter)] = []
parameterArrayCopy = list(dataDict["cat"]) # real copy, not just reference!
for parameter in possibleMissingParams:
if parameter not in dict[block][counter].keys():
logger.warning("Possible that all querys of %s run more than the maximum time measurement period? %s will be -1 for %s." %("%s%s" %(block,counter),parameter, "%s%s" %(block,counter)))
dict[block][counter][parameter]=-1
for parameter in dict[block][counter].keys():
parameterClean = parameter.replace("(ms)","").replace("(us)","").replace("Latency","").replace("thPercentile","Perc.").replace("Average","Avg.")
if parameter not in ignoreParams or (not ignoreSomeParameters and parameter != "LatencyList" ):
if not firstRun and parameterClean not in dataDict["cat"]:
logger.error("There were more parameter in '%s' than in other blocks, that does not work. Parameter %s is too much." %("%s%s" % (block,counter),parameter))
os._exit(-1)
if parameter in convertFromUsToMs:
dataDict["data"]["%s%s" % (block,counter)].append(dict[block][counter][parameter]/1000.0)
else:
dataDict["data"]["%s%s" % (block,counter)].append(dict[block][counter][parameter])
if firstRun:
dataDict["cat"].append(parameterClean)
else:
parameterArrayCopy.remove(parameterClean)
if not firstRun:
if len(parameterArrayCopy) > 0:
if not ignoreLess:
logger.error("There were less parameter in '%s' than in other blocks, that does not work. Parameter left (cleaned -> without (us) or (ms)!): %s." %("%s%s" % (block,counter),parameterArrayCopy))
os._exit(-1)
else:
for param in parameterArrayCopy:
dataDict["data"]["%s%s" % (block,counter)].insert(list(dataDict["cat"]).index(param),"-")
firstRun = False
return dataDict
# Generate resulting html table for single measurement page
def generate_results_table_single(dict, logger):
templateDict={}
templateDict["results_table_name"] = "General results:"
templateDict["block_results_table_name"] = "Block results:"
if dict["dbDesc"] != "":
templateDict["dbdesc_name"] = "Database Description:"
templateDict["dbdesc"] = dict["dbDesc"]
if dict["description"] != "":
templateDict["description_name"] = "Description:"
templateDict["description"] = dict["description"]
if dict["errors"] != []:
templateDict["errors_name"] = "Erros:"
templateDict["errors"] = ""
for error in dict["errors"]:
templateDict["errors"] += "%s<br>" %(error)
if dict["warnings"] != []:
templateDict["warnings_name"] = "Warnings:"
templateDict["warnings"] = ""
for warning in dict["warnings"]:
templateDict["warnings"] += "%s<br>" %(warning)
if dict["exceptions"] != []:
templateDict["exceptions_name"] = "Exceptions:"
templateDict["exceptions"] = ""
for exception in dict["exceptions"]:
templateDict["exceptions"] += "%s<br>" %(exception)
templateDict["title"] = "%s_%s_%s" %(dict["dbName"], dict["workload"], dict["startTime"].strftime("%Y%m%d%H%M"))
# Generate 'General' Results Table
tableHtml="<thead><tr><th>Parametername:</th><th>Value:</th></tr></thead>"
tableHtml+="<tbody>"
for key in dict.keys():
if key != "blocks":
tableHtml+="<tr><th scope=\"row\">%s</th><td>%s</td></tr>" % (key,dict[key])
tableHtml+="</tbody>"
templateDict["results_table"] = tableHtml
# Generate 'Block' Results Table
# which means results of every block
# no histogram/timeseries data ('LatencyList'), only more general values like throughput,etc.
paramDict={} # dict of parameterName : [value1,value2..] -> represents table rows!
firstRun=True # check if all blocks have all parameters (same parameter set)
# creates dict for html table, every key has an array of one row
for block in dict["blocks"]:
for index in range(0,len(dict["blocks"][block])):
tmpparamDict = paramDict.copy() #check if all entries were there, if not use "-"
for param in dict["blocks"][block][index]:
if param == "LatencyList":
continue
if param not in paramDict.keys():
if not firstRun:
logger.error("Found '%s' in '%s%s' which other blocks do not have." %(param,block,index))
os._exit(-1)
paramDict[param]=[dict["blocks"][block][index][param]]
else:
paramDict[param].append(dict["blocks"][block][index][param])
if dict["blocks"][block][index][param] == -1 and param in possibleMissingParams :
if dict["warnings"] == []:
templateDict["warnings_name"] = "Warnings:"
templateDict["warnings"] = ""
paramStr = ""
for possibleMissingParam in possibleMissingParams:
paramStr += ", %s" %(possibleMissingParam)
paramStr = paramStr[2:]
templateDict["warnings"] += "%s<br>" %("Values of -1 for %s means that these values were not calculated by ycsb, mostly due to query times longer than the given bucketsize." %(paramStr))
if not firstRun:
tmpparamDict.pop(param)
# Fix missing parameters for this row
if not firstRun:
for key in tmpparamDict:
paramDict[key].append("-")
firstRun = False
# counting amount of columns needed
tableColumnsCounter = 1 # 1 because left column is already there
indexSaver = 0 # Saves next index in case of row break
indexMax = 0
tableHtml=""
for block in dict["blocks"]:
for index in dict["blocks"][block]:
indexMax += 1
while indexSaver < indexMax:
if indexSaver+tableColumnsCounter > indexMax:
break
if tableColumnsCounter >= maxTableColumnsSingle:
indexSaver+=tableColumnsCounter-1
if indexSaver >= indexMax:
break
tableColumnsCounter = 1
tableHtml+="<tr>"
for k in range(0,maxTableColumnsSingle+1):
tableHtml+="<td></td>"
tableHtml+="</tr></tbody>"
continue
tableHtml+="<thead><tr><th>Parametername:</th>"
indexCounter=0 # to find the right index again
for block in dict["blocks"]:
for index in range(0,len(dict["blocks"][block])):
if indexCounter >= indexSaver:
if tableColumnsCounter >= maxTableColumnsSingle:
break
else:
tableHtml+="<th>%s%s:</th>" % (block,index)
tableColumnsCounter += 1
indexCounter+=1
tableHtml+="</tr></thead>"
tableHtml+="<tbody>"
for key in paramDict.keys():
tableHtml+="<tr><th scope=\"row\">%s</th>" % (key)
tableColumnsCounter2 = 1
indexCounter2=0 # to find the right index again
for number in paramDict[key]:
if indexCounter2 >= indexSaver:
if tableColumnsCounter2 >= maxTableColumnsSingle:
break
else:
tableHtml+="<td>%s</td>" % (number)
tableColumnsCounter2+=1
indexCounter2+=1
tableHtml+="</tr>"
tableHtml+="</tbody>"
templateDict["block_results_table"] = tableHtml
return templateDict
# Generate resulting html table for multi measurement page
def generate_results_table_multi(dicts, fileName, logger):
dataDictBlocks = {}
# structure of dataDictBlocks should look like this:
# <blocktype>
# -> "data"
# -> <dbName>
# -> [1,2,3]
# ...
# ...
# -> "cat"
# -> <paramName>
# -> ...
# <blockType> e.g. "INSERT0"
# <dbName> e.g. "MySQL"
# <paramName> e.g. "AvgLatency"
# we do the same here as for multi dict block plots
generate_block_data(dataDictBlocks, dicts, False, True, logger)
templateDict={}
templateDict["results_table_name"] = "General results:"
templateDict["block_results_table_name"] = "Block results:"
templateDict["title"] = fileName
if len(dicts.keys()) > 0:
if dicts[dicts.keys()[0]]["description"] != "":
templateDict["description_name"] = "Description:"
templateDict["description"] = dicts[dicts.keys()[0]]["description"]