-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprocessJmhResults.sh
1330 lines (1185 loc) · 42.3 KB
/
processJmhResults.sh
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
#!/bin/bash
# processJmhResults.sh
# Copyright 2013-2016 headissue GmbH, Jens Wilke
# This script processes the benchmark results into svg graphics.
#
# Needed tools: asciidoctor gnuplot jq pandoc
#
# Run it with the following subcommands:
#
# process paint nice diagrams
# stop on error
set -e
# print commands
# set -x
RESULT="target/jmh-result";
SITE="../cache2k/src/site/resources/benchmark-result";
# replace class names by short name of each cache implementation for graph labeling
cacheShortNames() {
local script=`cat << EOF
s/org.cache2k.benchmark.ConcurrentHashMapFactory/CHM/
s/org.cache2k.benchmark.SynchronizedLinkedHashMapFactory/SLHM/
s/org.cache2k.benchmark.PartitionedLinkedHashMapFactory/PLHM/
s/org.cache2k.benchmark.cache.EhCache2Factory/EhCache2/
s/org.cache2k.benchmark.cache.EhCache3Factory/EhCache3/
s/org.cache2k.benchmark.cache.CaffeineCacheFactory/Caffeine/
s/org.cache2k.benchmark.cache.GuavaCacheFactory/Guava/
s/org.cache2k.benchmark.cache.Cache2kFactory/cache2k/
s/org.cache2k.benchmark.cache.TCache1Factory/tCache/
s/org.cache2k.benchmark.ConcurrentHashMapFactory0/CHM~/
s/org.cache2k.benchmark.SynchronizedLinkedHashMapFactory0/SLHM~/
s/org.cache2k.benchmark.thirdparty.EhCache2Factory0/EhCache2~/
s/org.cache2k.benchmark.thirdparty.EhCache3Factory0/EhCache3~/
s/org.cache2k.benchmark.thirdparty.CaffeineCacheFactory0/Caffeine~/
s/org.cache2k.benchmark.thirdparty.GuavaCacheFactory0/Guava~/
s/org.cache2k.benchmark.Cache2kFactory0/cache2k~/
s/org.cache2k.benchmark.thirdparty.TCache1Factory0/tCache~/
EOF
`
sed "$script";
}
CACHE_FACTORY_LIST="org.cache2k.benchmark.cache.Cache2kFactory \
org.cache2k.benchmark.cache.CaffeineCacheFactory \
org.cache2k.benchmark.cache.EhCache3Factory";
CACHE_FACTORY_LIST_BASE="org.cache2k.cache.Cache2kFactory0 \
org.cache2k.benchmark.cache.CaffeineCacheFactory0 \
org.cache2k.benchmark.cache.EhCache3Factory0";
# "org.cache2k.benchmark.thirdparty.EhCache3Factory";
# for TCache we need to add:
# "org.cache2k.benchmark.thirdparty.TCache1Factory";
# CACHE_FACTORY_LIST=org.cache2k.benchmark.thirdparty.CaffeineCacheFactory
CACHE_LABEL_LIST=`echo $CACHE_FACTORY_LIST | cacheShortNames`;
withBase() {
CACHE_FACTORY_LIST="$CACHE_FACTORY_LIST $CACHE_FACTORY_LIST_BASE";
CACHE_LABEL_LIST=`echo $CACHE_FACTORY_LIST | cacheShortNames`;
}
processCommandLine() {
pars="$#";
while true; do
case "$1" in
--dir) RESULT="$2"; shift 1;;
--debug) set -x;;
--interactive) set +e;;
-*) echo "unknown option: $1"; exit 1;;
*) break;;
esac
shift 1;
done
if test -z "$1"; then
echo "Run with: processJmhResults.sh process";
else
"$@";
fi
}
json() {
if test -f $RESULT/data.json.gz; then
cat $RESULT/data.json.gz;
else
cat $RESULT/data.json
fi
}
# scaleToMegaBytes
#
# Scale the score down to megabytes with 2 digit precision.
#
scaleBytesToMegaBytes() {
awk -F, 'BEGIN { scale=1000*1000; } { printf ("%s,%s,%.2f\n", $1, $2, $3/scale); }'
}
scaleBytesToMegaBytes4MemAlloc() {
awk -F, 'BEGIN { scale=1000*1000; } { printf ("%s,%s,%.2f,%.2f,%.2f,%.2f,%s\n", $1, $2, $3/scale,$4/scale,$5/scale,$6/scale,$7); }'
}
# pivot "<impl>,<impl2>,..."
#
# Input format:
#
# 1000000,org.cache2k.benchmark.Cache2kFactory,0.26509106983333336
# 2000000,org.cache2k.benchmark.Cache2kFactory,0.51293869775
# 4000000,org.cache2k.benchmark.Cache2kFactory,1.5091185168999999
# 8000000,org.cache2k.benchmark.Cache2kFactory,5.391231625266667
# 1000000,org.cache2k.benchmark.Cache2kWithExpiryFactory,0.39409388270000006
# 2000000,org.cache2k.benchmark.Cache2kWithExpiryFactory,0.9784698428333333
# . . .
# Output format:
#
# benchmarkAllMiss_6E 0.207 0.403
# benchmarkEffective90_6E 0.047 0.074
# benchmarkEffective95_6E 0.04 0.059
#
pivot() {
local cols="$1";
shift;
while [ "$1" != "" ]; do
cols="${cols},$1";
shift;
done
awk -v cols="$cols" "$pivot_awk";
}
pivot_awk=`cat <<"EOF"
BEGIN { FS=",";
keysCnt = split(cols, colKeys, ",");
}
row!=$1 { flushRow(); row=$1; for (i in data) delete data[i]; }
{ data[$2]=$3; }
END { flushRow(); }
function flushRow() {
if (row == "") return;
printf ("%s ", row);
for (k = 1; k <= keysCnt; k++) {
key=colKeys[k];
v=data[key];
# missing data points need to have a ?
if (v=="") {
printf ("? ");
} else {
printf ("%s ", v);
}
}
printf "\n";
}
EOF
`
# pivot4
# Instead of pivoting only one score, this pivots 4 values. The score, error, lower and upper confidence.
# Input format:
# Params, Impl, Score, Error, Lower Confidence, Upper Confidence
# "2-80","org.cache2k.benchmark.thirdparty.GuavaCacheFactory",1602500.3473090807,322572.59684567206,1279927.7504634087,1925072.9441547527
# "3-10","org.cache2k.benchmark.thirdparty.GuavaCacheFactory",1934111.3466509539,11853.390790690266,1922257.9558602637,1945964.737441644
# "3-20","org.cache2k.benchmark.thirdparty.GuavaCacheFactory",1632899.76591479,9903.399664738625,1622996.3662500514,1642803.1655795288
pivot4() {
local cols="$1";
shift;
while [ "$1" != "" ]; do
cols="${cols},$1";
shift;
done
awk -v cols="$cols" "$pivot_With_Confidence_awk";
}
pivot_With_Confidence_awk=`cat <<"EOF"
BEGIN { FS=",";
keysCnt = split(cols, colKeys, ",");
}
row!=$1 { flushRow(); row=$1; for (i in data) delete data[i]; }
{ data[$2]=$3;
error[$2]=$4;
lower[$2]=$5;
upper[$2]=$6;
}
END { flushRow(); }
function flushRow() {
if (row == "") return;
printf ("%s ", row);
for (k = 1; k <= keysCnt; k++) {
key=colKeys[k];
v=data[key];
# missing data points need to have a ?
if (v=="") {
printf ("0 0 0 0 ");
} else {
printf ("%s %s %s %s ", data[key], error[key], lower[key], upper[key]);
}
}
printf "\n";
}
EOF
`
# renameBenchmarks
#
# Strip benchmark from the name.
#
cleanName() {
awk '{ sub(/benchmark/, "", $1); print; }';
}
stripEmpty() {
awk 'NF > 1 { print; }';
}
maxYRange_awk=`cat <<"EOF"
NR==1 { next; }
{ for (i=2; i<=NF;i++) if ($i>range) range=$i; }
END {
range=range*1.1;
# if (range > 100) { print 100; } else { print range; }
}
EOF
`
maxYRange() {
awk "$maxYRange_awk";
}
plotHistogramHeader() {
local in="$1";
local out="`dirname "$in"`/`basename "$in" .dat`.svg";
local title="$2";
local yTitle="$3";
local xTitle="$4";
local maxYRange=`maxYRange < "$in"`;
echo "set terminal svg size 800,600"
echo "set boxwidth 0.9 absolute";
echo "set style fill solid 1.00 border -1";
echo "set key outside right top vertical Right noreverse noenhanced autotitles nobox";
echo "set datafile missing '-'";
echo "set style data histograms";
echo "set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify";
echo 'set xtics norangelimit font "1"';
echo "set xtics ()"
test -z "$xTitle" || echo "set xlabel '${xTitle}'";
test -z "$yTitle" || echo "set ylabel '${yTitle}'";
echo "set yrange [ 0.0 : $maxYRange ] noreverse nowriteback";
echo "set format y '%.1s%c'"
cat - << "EOF"
# nomirror means do not put tics on the opposite side of the plot
set xtics nomirror
set ytics nomirror
# On the Y axis put a major tick every 5
# set ytics 1000000
# Split in 5 for minor tics
set mytics 5
# Line style for axes
# Define a line style (we're calling it 80) and set
# lt = linetype to 0 (dashed line)
# lc = linecolor to a gray defined by that number
# set style line 80 lt 0 lc rgb "#111111"
set style line 80 lt 1 lc rgbcolor "black"
# Set the border using the linestyle 80 that we defined
# 3 = 1 + 2 (1 = plot the bottom line and 2 = plot the left line)
# back means the border should be behind anything else drawn
set border 3 back ls 80
# Line style for grid
# Define a new linestyle (81)
# linetype = 0 (dashed line)
# linecolor = gray
# lw = lineweight, make it half as wide as the axes lines
set style line 82 lt 0 lc rgb "#808080" lw 0.5
set style line 81 lt 19 lc rgb "#404040" lw 0.5
# Draw the grid lines for both the major and minor tics
# set grid xtics
set grid ytics mytics ls 81, ls 82
# Put the grid behind anything drawn and use the linestyle 81
# set grid back ls 81
EOF
}
colorScheme() {
local cnt=1;
local colors="$@";
for I in $colors; do
echo "set style line $cnt lt rgb \"$I\"";
cnt=$(( $cnt + 1 ));
done
cnt=0;
echo "set palette defined ( \\";
for I in $colors; do
if [ $cnt -gt 0 ]; then echo ", \\"; fi
echo -n " $cnt '$I'"
cnt=$(( $cnt + 1 ));
done
echo ")";
echo "set palette maxcolors $cnt";
}
highContrast() {
# http://colorbrewer2.org/....
colorScheme "#d7191c #ffffbf #fdae61 #abdda4 #2b83ba #1b7837"
# colors="aaaabf fdae61 abdda4 2b83ba 1b7837"
}
memoryColors() {
colorScheme "#a6cee3 #1f78b4 #b2df8a #33a02c #fb9a99 #e31a1c #fdbf6f #ff7f00"
}
printColors() {
colorScheme "#1b9e77 #d95f02 #7570b3 #e7298a #66661e #e6ab02 #a6761d #666666";
}
printColorsDark() {
colorScheme "#1b9e77 #d95f02 #7570b3 #444444 #e7298a #66a61e #e6ab02 #666666"
}
plotData() {
echo "set style histogram clustered gap 2 title offset character 0, 0, 0";
local in="$1";
local idx="$2";
idx=$(( $idx + 1 ));
local endIndex=$(( $3 + 1 ));
echo -n "plot '$in' using $idx:xtic(1) ti col ls $(( $idx - 1 ))";
cols=$(( `head -n 1 "$in" | wc -w` ));
idx=$(( $idx + 1 ));
while [ $idx -le $cols ] && [ $idx -le $endIndex ]; do
echo -n ", '' u $idx ti col ls $(( $idx - 1 ))";
idx=$(( $idx + 1 ));
done
}
plotDataWithConfidence() {
echo "set style histogram errorbars gap 2 lw 0.5 title offset character 0, 0, 0";
local in="$1";
local idx="$2";
local endIndex=$(( ( $3 - 1 ) * 4 + 2 ));
local ls=$idx;
idx=$(( ($idx - 1) * 4 + 2 ));
echo -n "plot '$in' using $idx:$(( idx + 2)):$(( idx + 3)):xtic(1) ti col($idx) ls ${ls}";
cols=$(( `head -n 1 "$in" | wc -w` ));
# TODO: replace with plot for ....
ls=$(( $ls + 1 ));
idx=$(( $idx + 4 ));
while [ $idx -lt $cols ] && [ $idx -le $endIndex ]; do
echo -n ", '' u $idx:$(( idx + 2)):$(( idx + 3)) ti col($idx) ls ${ls}";
ls=$(( $ls + 1 ));
idx=$(( $idx + 4 ));
done
}
plot() {
local plot="plotData";
local colorScheme="highContrast";
local startIndex=1;
local endIndex=100;
while true; do
case "$1" in
--withColors) colorScheme="$2"; shift 1;;
--startIndex) startIndex="$2"; shift 1;;
--endIndex) endIndex="$2"; shift 1;;
--withConfidence) plot="plotDataWithConfidence";;
# --dir) RESULT="$2"; shift 1;;
-*) echo "unknown option: $1"; return 1;;
*) break;;
esac
shift 1;
done
local in="$1";
local out="`dirname "$in"`/`basename "$in" .dat`.svg";
local title="$2";
local yTitle="$3";
local xTitle="$4";
local maxYRange=`maxYRange < "$in"`;
if [ "`cat $in | wc -l`" -eq 1 ]; then
unset graphName;
echo "No data, skipping: $in";
return;
fi
graphName=`basename $in .dat`;
if false; then
echo "$out ....";
(
plotHistogramHeader "$in" "$title" "$yTitle" "$xTitle";
echo "set output '$out'"
# http://stackoverflow.com/questions/15549830/how-to-get-gnuplot-to-use-a-centered-multi-line-title-with-left-aligned-lines
# the title is always centered over the graph, excluding the legend!
# echo "set title '$title'";
echo "set title \"$title\"";
$colorScheme;
$plot "$in" $startIndex $endIndex;
) > "$in".plot
gnuplot "$in".plot;
fi
# just a copy of above but leaving out the title for texts/blogs providing an image title
local out="`dirname "$in"`/`basename "$in" .dat`-notitle.svg";
echo "$out ....";
(
plotHistogramHeader "$in" "$title" "$xTitle" "$yTitle";
echo "set output '$out'"
$colorScheme;
$plot "$in" $startIndex $endIndex;
) > "${in}-notitle.plot"
gnuplot "${in}-notitle.plot";
# just a copy of above but leaving out the title for texts/blogs providing an image title
local out="`dirname "$in"`/`basename "$in" .dat`-notitle-print.svg";
echo "$out ....";
(
plotHistogramHeader "$in" "$title" "$yTitle" "$xTitle";
echo "set output '$out'"
echo "set style fill pattern border"
# printColors;
# highContrast;
# echo "set colorsequence podo"
# printColorsDark;
$plot "$in" $startIndex $endIndex;
) > "${in}-notitle-print.plot"
gnuplot "${in}-notitle-print.plot";
}
# TODO: fix normed allocation rate
memoryMetricsHeader() {
echo -n "product";
for I in maxCommitted.afterGc VmHWM maxUsed.afterGc VmRSS.fin liveObjects "allocRate(byte/s)" "allocRate(byte/op)"; do
echo -n " $I error lower upper";
done
echo;
}
#
# Input is a benchmark name like Xy or Xy-variant
# Prints jq select statement
#
benchmarkSelector() {
if [[ "$1" = *"-"* ]]; then
local variant="${1#*-}";
local benchmark="${1%-*}";
echo "select ((.benchmark | contains (\"$benchmark\")) and (.params.variant == \"${variant}\"))";
else
echo "select ((.benchmark | contains (\"$1\")) and (.params.variant | . == null or . == \"\"))";
fi
}
#
# Extract benchmark name from Xy-variant
#
benchmarkName() {
if [[ "$1" = *"-"* ]]; then
echo "${1%-*}";
else
echo "$1"
fi
}
# Extract memory metrics for a particular benchmark
#
# Usage: extractMemoryMetrics <benchmark> <paramName>
#
# example output:
# 1-20,org.cache2k.benchmark.Cache2kFactory,0.00,65.72,993.08,614.8539540861144
# 1-20,org.cache2k.benchmark.thirdparty.CaffeineCacheFactory,0.00,71.27,1000.42,852.382233323991
# 1-20,org.cache2k.benchmark.thirdparty.EhCache2Factory,0.00,58.28,606.75,204.83546236165807
extractMemoryMetrics() {
local selector="`benchmarkSelector "$1"`";
# .[] | select (.benchmark | contains (".$1") ) |
local query=`cat << EOF
.[] | $selector |
[ (.threads | tostring) + "-" + .params.entryCount + "-" + .params.$2, .params.cacheFactory,
.["secondaryMetrics"]["+c2k.gc.maximumCommittedAfterGc"].score,
.["secondaryMetrics"]["+c2k.gc.maximumCommittedAfterGc"].scoreError,
.["secondaryMetrics"]["+c2k.gc.maximumCommittedAfterGc"].scoreConfidence[0],
.["secondaryMetrics"]["+c2k.gc.maximumCommittedAfterGc"].scoreConfidence[1],
.["secondaryMetrics"]["+linux.proc.status.VmHWM"].score * 1000,
.["secondaryMetrics"]["+linux.proc.status.VmHWM"].scoreError * 1000,
.["secondaryMetrics"]["+linux.proc.status.VmHWM"].scoreConfidence[0] * 1000,
.["secondaryMetrics"]["+linux.proc.status.VmHWM"].scoreConfidence[1] * 1000,
.["secondaryMetrics"]["+c2k.gc.maximumUsedAfterGc"].score,
.["secondaryMetrics"]["+c2k.gc.maximumUsedAfterGc"].scoreError,
.["secondaryMetrics"]["+c2k.gc.maximumUsedAfterGc"].scoreConfidence[0],
.["secondaryMetrics"]["+c2k.gc.maximumUsedAfterGc"].scoreConfidence[1],
.["secondaryMetrics"]["+linux.proc.status.VmRSS"].score * 1000,
.["secondaryMetrics"]["+linux.proc.status.VmRSS"].scoreError * 1000,
.["secondaryMetrics"]["+linux.proc.status.VmRSS"].scoreConfidence[0] * 1000,
.["secondaryMetrics"]["+linux.proc.status.VmRSS"].scoreConfidence[1] * 1000,
.["secondaryMetrics"]["+liveObjects"].score,
.["secondaryMetrics"]["+liveObjects"].scoreError,
.["secondaryMetrics"]["+liveObjects"].scoreConfidence[0],
.["secondaryMetrics"]["+liveObjects"].scoreConfidence[1],
.["secondaryMetrics"]["·gc.alloc.rate"].score * 1000 * 1000,
.["secondaryMetrics"]["·gc.alloc.rate"].scoreError * 1000 * 1000,
.["secondaryMetrics"]["·gc.alloc.rate"].scoreConfidence[0] * 1000 * 1000,
.["secondaryMetrics"]["·gc.alloc.rate"].scoreConfidence[1] * 1000 * 1000,
.["secondaryMetrics"]["·gc.alloc.rate.norm"].score,
.["secondaryMetrics"]["·gc.alloc.rate.norm"].scoreError,
.["secondaryMetrics"]["·gc.alloc.rate.norm"].scoreConfidence[0],
.["secondaryMetrics"]["·gc.alloc.rate.norm"].scoreConfidence[1]
] | @csv
EOF
`
json | \
jq -r "$query" | \
sort | tr -d '"'
# | scaleBytesToMegaBytes4x4MemAlloc
}
stripFirstColumn() {
sed 's/^[^ ]* \(.*\)/\1/'
}
memoryMetrics() {
local benchmark="$1";
local param="$2";
local tmp="$RESULT/tmp-memoryMetrics-$benchmark-$param.data"
test -f "$tmp" || extractMemoryMetrics $benchmark $param | tr , " " | shortenParamValues > "$tmp"
cat "$tmp"
}
# everything except alloc rate
plotMemoryGraphs() {
read param;
read title;
read benchmark;
while read key description; do
f=$RESULT/${benchmark}Memory$key.dat
(
memoryMetrics "$benchmark" "$param" | grep "^$key" | stripFirstColumn | cacheShortNames
) > $f
plot --withConfidence --withColors memoryColors $f "$title\n$description" "cache" "Bytes"
done
}
plotMem() {
local title="";
local description="";
local variant="";
local filter="";
local startIndex=1;
local endIndex=100;
local sort="";
while true; do
case "$1" in
--title) title="$2"; shift 1;;
--description) description="$2"; shift 1;;
--variant) variant="$2"; shift 1;;
--filter) filter="$2"; shift 1;;
--startIndex) startIndex="$2"; shift 1;;
--endIndex) endIndex="$2"; shift 1;;
--sort) sort="1";;
-*) echo "unknown option: $1"; return 1;;
*) break;;
esac
shift 1;
done
local benchmark="$1";
local param="$2";
local key="$3";
f=$RESULT/${benchmark}-Memory-$key$variant.dat
(
memoryMetricsHeader
memoryMetrics "$benchmark" "$param" | grep "^$key" | stripFirstColumn | cacheShortNames \
| { if test -n "$sort"; then sort -k$(( ( $startIndex - 1) * 4 + 2 )) -g; else cat -; fi } \
| grep "$filter" || true
) > $f
plot --withConfidence --withColors memoryColors --startIndex "$startIndex" --endIndex "$endIndex" $f "$title\n$description" "cache" "Bytes"
}
plotEffectiveHitrate() {
name="$1";
param="$2";
suffix="$3";
filter="$4";
local prods="$CACHE_FACTORY_LIST";
if test -n "$suffix"; then
f=$RESULT/${name}-EffectiveHitrate-${suffix}.dat
else
f=$RESULT/${name}-EffectiveHitrate.dat
fi
(
header4 "$prods";
# echo "threads $CACHE_LABEL_LIST";
# TODO: we cannot calculate with confidences
# previous version: 100 - .["secondaryMetrics"]["+misc.missCount"].score * 100 / .["secondaryMetrics"]["+misc.opCount"]["score"],
# new: .["secondaryMetrics"]["+misc.hitrate"].score,
local selector="`benchmarkSelector "$name"`";
# .[] | select (.benchmark | contains (".${name}") ) |
local query=`cat << EOF
.[] | $selector |
[ (.threads | tostring) + "-" + .params.entryCount + "-" + .params.$param,
.params.cacheFactory,
.["secondaryMetrics"]["+misc.hitrate"].score,
.["secondaryMetrics"]["+misc.hitrate"].scoreError,
.["secondaryMetrics"]["+misc.hitrate"].scoreConfidence[0],
.["secondaryMetrics"]["+misc.hitrate"].scoreConfidence[1]
] | @csv
EOF
`
local tmp="$RESULT/tmp-plotEffectiveHitrate-$name-$param.data"
test -f "$tmp" || json | \
jq -r "$query" | sort | tr -d '"' | pivot4 $prods | sort -n -t- -k1,1 -k2,2 -k3,3 | shortenParamValues > "$tmp"
cat "$tmp" | grep "$filter" | stripEmpty
) > $f
plot --withConfidence $f "${name} / Effective Hit Rate" "threads - size - $param" "effective hitrate"
}
plotScanCount() {
name="$1";
param="$2";
suffix="$3";
filter="$4";
local prods="org.cache2k.benchmark.cache.Cache2kFactory";
if test -n "$suffix"; then
f=$RESULT/${name}-ScanCount-${suffix}.dat
else
f=$RESULT/${name}-ScanCount.dat
fi
local selector="`benchmarkSelector "$name"`";
(
header4 "$prods";
local query=`cat << EOF
.[] | $selector |
[ (.threads | tostring) + "-" + .params.entryCount + "-" + .params.$param,
.params.cacheFactory,
.["secondaryMetrics"]["+c2k.stat.scanPerEviction"].score,
.["secondaryMetrics"]["+c2k.stat.scanPerEviction"].scoreError,
.["secondaryMetrics"]["+c2k.stat.scanPerEviction"].scoreConfidence[0],
.["secondaryMetrics"]["+c2k.stat.scanPerEviction"].scoreConfidence[1]
] | @csv
EOF
`
local tmp="$RESULT/tmp-plotScanCount-$name-$param.data"
test -f "$tmp" || json | \
jq -r "$query" | sort | tr -d '"' | pivot4 $prods | sort -n -t- -k1,1 -k2,2 -k3,3 | shortenParamValues > "$tmp"
cat "$tmp" | grep "$filter" | stripEmpty
) > $f
plot --withConfidence $f "${name} / scans per eviction" "threads - size - $param" "scan count"
}
header4() {
local I;
local n;
echo -n "param ";
for I in $@; do
n="`echo $I | cacheShortNames`";
echo -n "$n error lowerConvidence upperConvidence ";
done
echo "";
}
# shortenParamValuesWithE
#
# 8-100000-20 gets to: 8-1E5-20
#
shortenParamValuesWithE() {
awk "$shorten_awk_withE";
}
shorten_awk_withE=`cat <<"EOF"
{
cnt = split($1, params, "-");
out = "";
for (I in params) {
val=params[I];
if (val >= 1000) {
ex = 0;
while (val % 10 == 0) {
val /= 10;
ex++;
}
val = val"E"ex;
}
if (out != "") {
out = out "-" val;
} else {
out = out val;
}
}
$1 = out;
print;
}
EOF
`
shortenParamValues() {
awk "$shorten_awk";
}
shorten_awk=`cat <<"EOF"
{
cnt = split($1, params, "-");
out = "";
for (I in params) {
val=params[I];
if (val >= 1000) {
ex = 0;
while (val % 1000 == 0) {
val /= 1000;
ex += 3;
}
suffix = "E" ex;
if (ex == 0) {
suffix = "";
} else if (ex == 3) {
suffix = "K";
} else if (ex == 6) {
suffix = "M";
} else if (ex == 8) {
suffix = "G";
}
val = val suffix;
}
if (out != "") {
out = out "-" val;
} else {
out = out val;
}
}
# third parameter might not be used, remove
if (substr(out, length(out)) == "-") {
out=substr(out, 0, length(out) -1);
}
$1 = out;
print;
}
EOF
`
# plot main score, typically through put in operations per second.
# in case the benchmark has no additional parameter "none" can be specified
plotOps() {
name="$1";
param="$2";
suffix="$3";
filter="$4";
prods="$CACHE_FACTORY_LIST $5";
tmpext="";
if test -n "$6"; then
prods="$6";
# seperate tmp files if different list ist used!
tmpext="-$suffix";
fi
if test -n "$suffix"; then
f=$RESULT/${name}-${suffix}.dat
else
f=$RESULT/${name}.dat
fi
local selector="`benchmarkSelector "$name"`";
(
header4 "$prods";
local tmp="$RESULT/tmp-plotOps-$name-$param$tmpext.data"
# old query: jq -r ".[] | select (.benchmark | contains (\".${name}\") ) | [ (.threads | tostring) + \"-\" + .params.entryCount + \"-\" + .params.$param, .params.cacheFactory, .primaryMetric.score, .primaryMetric.scoreError, .primaryMetric.scoreConfidence[0], .primaryMetric.scoreConfidence[1] ] | @csv" | \
# old query on primary result
local queryOld=`cat << EOF
.[] | $selector |
[ (.threads | tostring) + "-" + .params.entryCount + "-" + .params.$param,
.params.cacheFactory,
.primaryMetric.score,
.primaryMetric.scoreError,
.primaryMetric.scoreConfidence[0],
.primaryMetric.scoreConfidence[1]
] | @csv
EOF
`
local query=`cat << EOF
.[] | $selector |
[ (.threads | tostring) + "-" + .params.entryCount + "-" + .params.$param,
.params.cacheFactory,
.["secondaryMetrics"]["+misc.requests.throughput"].score,
.["secondaryMetrics"]["+misc.requests.throughput"].scoreError,
.["secondaryMetrics"]["+misc.requests.throughput"].scoreConfidence[0],
.["secondaryMetrics"]["+misc.requests.throughput"].scoreConfidence[1]
] | @csv
EOF
`
# request throughput based on AuxCounters
local queryAuxCounters=`cat << EOF
.[] | select (.benchmark | contains (".${name}") ) |
[ (.threads | tostring) + "-" + .params.entryCount + "-" + .params.$param,
.params.cacheFactory,
.["secondaryMetrics"]["requests"].score,
.["secondaryMetrics"]["requests"].scoreError,
.["secondaryMetrics"]["requests"].scoreConfidence[0],
.["secondaryMetrics"]["requests"].scoreConfidence[1]
] | @csv
EOF
`
test -f "$tmp" || json | \
jq -r "$query" | \
sort | tr -d '"' | \
pivot4 $prods | \
sort -n -t- -k1,1 -k2,2 -k3,3 | shortenParamValues > "$tmp"
cat "$tmp" | grep "$filter" | stripEmpty
) > $f
xLabel="threads-size-$param";
if [ "$param" = "none" ]; then
xLabel="threads-size";
fi
plot --withConfidence $f "${name} / Throughput (higher is better)" "$xLabel" "ops/s"
}
# For one shot benchmarks, not used any more, plot main score, typically runtime
plotRuntime() {
name="$1";
param="$2";
suffix="$3";
filter="$4";
local prods="$CACHE_FACTORY_LIST";
if test -n "$suffix"; then
f=$RESULT/${name}-${suffix}.dat
else
f=$RESULT/${name}.dat
fi
local selector="`benchmarkSelector "$name"`";
(
header4 "$prods";
local tmp="$RESULT/tmp-plotOps-$name-$param.data"
test -f "$tmp" || json | \
jq -r ".[] | $selector | [ (.threads | tostring) + \"-\" + .params.entryCount, .params.cacheFactory, .primaryMetric.score, .primaryMetric.scoreError, .primaryMetric.scoreConfidence[0], .primaryMetric.scoreConfidence[1] ] | @csv" | \
sort | tr -d '"' | \
pivot4 $prods | sort -n -t- -k1,1 -k2,2 -k3,3 | shortenParamValues > "$tmp"
cat "$tmp" | grep "$filter" | stripEmpty
) > $f
plot --withConfidence $f "${name} / Runtime (lower is better)" "threads-size" "runtime[s]"
}
noBenchmark() {
local I;
if [[ "$1" = *"-"* ]]; then
local variant="${1#*-}";
local benchmark="${1%-*}";
for I in $RESULT/result-*"$benchmark"*"$variant".json; do
if test -f $I; then
return 1;
fi
done
return 0;
else
for I in $RESULT/result-*"$1"*.json; do
if test -f $I; then
return 1;
fi
done
return 0;
fi
}
#
# Merge all results into single JSON file
#
bigJson() {
result=$RESULT/data.json
# A sequence of the lines "]", "[", "]" will be ignored, there may be an empty json file, if a run fails
# A sequence of the lines "]", "[" will be replaced with ","
cat $RESULT/result-*.json | awk '/^]/ { f=1; g=0; next; } f && /^\[/ { g=1; f=0; next; } g { print " ,"; g=0; } { print; } END { print "]"; }' > $result
}
websiteResult="`cat - << "EOF"
PopulateParallelOnceBenchmark-byThreads-4M
PopulateParallelTwiceBenchmark-byThreads-4M
ZipfianSequenceLoadingBenchmark-byThread-1Mx110
ZipfianSequenceLoadingBenchmark-byThread-1Mx500
ZipfianSequenceLoadingBenchmark-EffectiveHitrate-byThread-1Mx110
ZipfianSequenceLoadingBenchmark-EffectiveHitrate-byThread-1Mx500
ZipfianSequenceLoadingBenchmark-Memory-4-1M-500-liveObjects-sorted
ZipfianSequenceLoadingBenchmark-Memory-4-1M-500-VmHWM-sorted
PopulateParallelClearBenchmark
EOF
`"
websiteResultGrep=`echo "$websiteResult" | awk '{print $0"|"; }'`;
typesetPlainMarkDown() {
(
echo "![](benchmark-result/$1-notitle.svg)"
echo
echo "*$2 ([Alternative image](benchmark-result/$1-notitle-print.svg), [Data file](benchmark-result/$1.dat))*"
echo;
) >> $RESULT/typeset-plain.md
# find substring, see: https://stackoverflow.com/questions/229551/how-to-check-if-a-string-contains-a-substring-in-bash
if [[ "$websiteResultGrep" == *"$1|"* ]]; then
(
echo "![](benchmark-result/$1-notitle.svg)"
echo
echo "*$2 ([Alternative image](benchmark-result/$1-notitle-print.svg), [Data file](benchmark-result/$1.dat))*"
echo;
) >> $RESULT/website.md
mkdir -p $RESULT/benchmark-result;
cp -a $RESULT/$1-notitle.svg $RESULT/$1.dat $RESULT/$1-notitle-print.svg $RESULT/benchmark-result/
fi
}
typesetAsciiDoc() {
(
echo ".$2";
echo "image::$1-notitle.svg[link=\"$1-notitle.svg\"]"
echo;
echo "link:$1-notitle-print.svg[Alternative image], link:$1.dat[Data file]"
echo;
echo "link:$1-notitle.svg[Color image], link:$1-notitle-print.svg[Alternative image], link:$1.dat[Data file]"
echo;
) >> $RESULT/typeset.adoc
}
cleanTypesetting() {
echo -n > $RESULT/typeset-plain.md
echo -n > $RESULT/typeset.adoc
echo -n > $RESULT/website.md
rm -rf $RESULT/benchmark-result
}
# add graph to result report
graph() {
test -f $RESULT/$1-notitle.svg || return 0;
typesetPlainMarkDown "$1" "$2";
typesetAsciiDoc "$1" "$2";
}
processGraphs() {
for I in PopulateParallelOnceBenchmark PopulateParallelTwiceBenchmark; do
noBenchmark $I || {
plotRuntime I runtime;
graph "$graphName" "I";
for T in 4; do
plotRuntime $I hitRate "bySize-${T}" "^$T-.*";
graph "$graphName" "$I, runtime by size for ${T} threads";
done
for S in 2M 4M 8M; do
plotRuntime $I hitRate "byThreads-${S}" "^.*-${S}";
graph "$graphName" "$I, runtime by thread count for ${S} cache size";
done
}
done
benchmarks="ReadOnlyBenchmark"
for I in $benchmarks; do
noBenchmark $I || {
plotOps $I hitRate "naive" "" "" "org.cache2k.benchmark.ConcurrentHashMapFactory org.cache2k.benchmark.SynchronizedLinkedHashMapFactory org.cache2k.benchmark.thirdparty.GuavaCacheFactory";
graph "$graphName" "$I, operations per second with simple cache based on LinkedHashMap";
}
done
benchmarks="ReadOnlyBenchmark"
for I in $benchmarks; do
noBenchmark $I || {
plotOps $I hitRate "naive2" "" "" "org.cache2k.benchmark.ConcurrentHashMapFactory org.cache2k.benchmark.SynchronizedLinkedHashMapFactory org.cache2k.benchmark.thirdparty.GuavaCacheFactory org.cache2k.benchmark.PartitionedLinkedHashMapFactory";
graph "$graphName" "$I, operations per second with simple cache based on LinkedHashMap with single or partitioned locking";
}
done
benchmarks="ReadOnlyBenchmark"
for I in $benchmarks; do
noBenchmark $I || {
plotOps $I hitRate "" "" org.cache2k.benchmark.ConcurrentHashMapFactory;
graph "$graphName" "$I, operations per second (complete)";
for TC in 10 4; do
for HR in 100 50 33; do
plotOps $I hitRate "bySize-${TC}x$HR" "^$TC-.*-$HR .*" org.cache2k.benchmark.ConcurrentHashMapFactory;