graph.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #!/usr/bin/env bash
  2. #
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. #
  5. # Parametrisation to this script is as follows:
  6. # * none yet
  7. ###
  8. # Preamble
  9. ###
  10. readonly my_path="$(dirname $(readlink -f $0))"
  11. readonly csv_path="$my_path/data"
  12. readonly log_path="$csv_path/logs"
  13. readonly img_path="$csv_path/images"
  14. readonly gnuplot_terminal="svg enhanced background rgb 'white' size 800 600"
  15. mkdir -p "$log_path"
  16. mkdir -p "$img_path"
  17. function cleanup() {
  18. echo OK
  19. }
  20. trap cleanup EXIT
  21. function error_out() {
  22. exit 1
  23. }
  24. trap error_out INT TERM
  25. ###
  26. # Functions
  27. ###
  28. function cg() {
  29. csvgrep -c $1 -r $2 $3
  30. }
  31. ###
  32. # Implementation
  33. ###
  34. readonly desc_block_ciphers="Benchmarks were done with growing sample size and averaging over\nprocessing of 128 samples of said sample size"
  35. readonly desc_asymmetric="Benchmarks were done with averaging over\nas many repetitions possible of the benchmarked operation in 1s"
  36. readonly desc_others="Benchmarks were done with 1MiB block size and averaging over\nas many repetitions possible of processing 5MiB data in 1s"
  37. readonly configs=$(find $csv_path -type d -name '*results*' | sed 's@.*results_@@g')
  38. ###
  39. # Symmetric crypto
  40. readonly sym="cbc ccm gcm"
  41. declare -A directions
  42. directions["dec"]="decryption"
  43. directions["enc"]="encryption"
  44. declare -A aad_sizes
  45. aad_sizes["no_AAD"]="0 Bytes"
  46. aad_sizes["custom"]="13 Bytes"
  47. aad_sizes["default"]="16 Bytes"
  48. # not pretty but works for me :)
  49. # CBC&GCM encryption is in software a lot faster than decryption,
  50. # therefor use the same Range on the Y-Axis to also have a visual indication.
  51. # This will break if something changes, so let the user override the value
  52. cbc_yrange="${cbc_yrange:=1400}"
  53. gcm_yrange="${gcm_yrange:=500}"
  54. for mode in $sym
  55. do
  56. infile="$csv_path/combined_${mode}.csv"
  57. for dir in ${!directions[@]}
  58. do
  59. plotstring=
  60. more_style=
  61. for cfg in $configs
  62. do
  63. for bsize in $(csvcut -c blocksize $infile | tail -n +2 | sort -u)
  64. do
  65. if [ "$mode" == "cbc" ]; then
  66. outfile=$log_path/${mode}${bsize}_${cfg}_${dir}.log
  67. val="$(cg config $cfg $infile | cg blocksize $bsize | cg direction $dir | csvcut -c chunksize,MiB/s | tail -n +2 | tr ',' ' ')"
  68. if [ "$val" != "" ]; then
  69. echo "$val" > $outfile
  70. [ -z "$plotstring" ] && plotstring="plot" || plotstring="${plotstring},"
  71. plotstring="${plotstring} '"$outfile"' smooth bezier title \"$cfg AES$bsize\""
  72. fi
  73. [ "$mode" == "cbc" -a "$cbc_yrange" != "" ] && more_style="set yrange [ 0 : $cbc_yrange ]"
  74. else
  75. for aad in ${!aad_sizes[@]}
  76. do
  77. outfile=$log_path/${mode}${bsize}_${cfg}_${dir}_${aad}.log
  78. val="$(cg config $cfg $infile | cg blocksize $bsize | cg direction $dir | cg AAD $aad | csvcut -c chunksize,MiB/s | tail -n +2 | tr ',' ' ')"
  79. if [ "$val" != "" ]; then
  80. echo "$val" > $outfile
  81. [ -z "$plotstring" ] && plotstring="plot" || plotstring="${plotstring},"
  82. plotstring="${plotstring} '"$outfile"' smooth bezier title \"$cfg AES$bsize ${aad_sizes[$aad]} AAD\""
  83. fi
  84. done
  85. [ "$mode" == "gcm" -a "$gcm_yrange" != "" ] && more_style="set yrange [ 0 : $gcm_yrange ]"
  86. fi
  87. done
  88. done
  89. modep=${mode^^}
  90. gnuplot << EOF
  91. set terminal $gnuplot_terminal
  92. set title "${modep} ${directions[${dir}]} on Xilinx Versal"
  93. set x2label "${desc_block_ciphers}"
  94. set xlabel "Sample size"
  95. set ylabel "MiB/s"
  96. set style data lines
  97. $more_style
  98. set output "${img_path}/${mode}_${dir}.${gnuplot_terminal%% *}"
  99. $plotstring
  100. EOF
  101. done
  102. done
  103. ###
  104. # Also create separate graphs for AES-GCM-128 and -256 since that's too many lines in one image
  105. for mode in gcm
  106. do
  107. infile="$csv_path/combined_${mode}.csv"
  108. for dir in ${!directions[@]}
  109. do
  110. for bsize in $(csvcut -c blocksize $infile | tail -n +2 | sort -u)
  111. do
  112. plotstring=
  113. more_style="set yrange [ 0 : $gcm_yrange ]"
  114. for cfg in $configs
  115. do
  116. for aad in ${!aad_sizes[@]}
  117. do
  118. outfile=$log_path/${mode}${bsize}_${cfg}_${dir}_${aad}.log
  119. val="$(cg config $cfg $infile | cg blocksize $bsize | cg direction $dir | cg AAD $aad | csvcut -c chunksize,MiB/s | tail -n +2 | tr ',' ' ')"
  120. if [ "$val" != "" ]; then
  121. echo "$val" > $outfile
  122. [ -z "$plotstring" ] && plotstring="plot" || plotstring="${plotstring},"
  123. plotstring="${plotstring} '"$outfile"' smooth bezier title \"$cfg AES$bsize ${aad_sizes[$aad]} AAD\""
  124. fi
  125. done
  126. done
  127. modep=${mode^^}
  128. gnuplot << EOF
  129. set terminal $gnuplot_terminal
  130. set title "${modep}-${bsize} ${directions[${dir}]} on Xilinx Versal"
  131. set x2label "${desc_block_ciphers}"
  132. set xlabel "Sample size"
  133. set ylabel "MiB/s"
  134. set style data lines
  135. $more_style
  136. set output "${img_path}/${mode}${bsize}_${dir}.${gnuplot_terminal%% *}"
  137. $plotstring
  138. EOF
  139. done
  140. done
  141. done
  142. ###
  143. # Asymmetric crypto
  144. declare -A asym_operations
  145. asym_operations["ecc"]="keygen agree sign verify"
  146. asym_operations["rsa"]="keygen public private"
  147. for algo in ${!asym_operations[@]}
  148. do
  149. infile="$csv_path/combined_${algo}.csv"
  150. for op in ${asym_operations[$algo]}
  151. do
  152. outfile=$log_path/${algo}_${op}.log
  153. echo -n "" > $outfile
  154. for ksize in $(csvcut -c keysize $infile | tail -n +2 | sort -u)
  155. do
  156. for cfg in $configs
  157. do
  158. h="${algo^^}-$ksize"
  159. v=$(cg config $cfg $infile | cg operation $op | cg keysize $ksize | csvcut -c "avg ms" | tail -n +2 | tr ',' ' ')
  160. [ "$v" != "" ] && echo "$h\n$cfg $v" >> $outfile
  161. done
  162. done
  163. algop=${algo^^}
  164. gnuplot << EOF
  165. set terminal $gnuplot_terminal
  166. set title "${algop} ${op} on Xilinx Versal"
  167. set x2label "${desc_asymmetric}"
  168. set xlabel 'Configurations' offset 0,-1
  169. set ylabel "ms per op"
  170. set style fill solid
  171. set style line 1 lc rgb "grey50"
  172. set boxwidth 0.5
  173. unset key
  174. set output "${img_path}/${algo}_${op}.${gnuplot_terminal%% *}"
  175. plot "$outfile" using :2:xtic(1) with boxes ls 1, \
  176. '' using :2:2 w labels offset 0,0.7
  177. EOF
  178. done
  179. done
  180. ###
  181. # Hashes
  182. declare -A hash_sizes
  183. hash_sizes["sha2"]="224 256 384 512"
  184. hash_sizes["sha3"]="384"
  185. plotstring=
  186. outfile=$log_path/sha.log
  187. echo -n "" > $outfile
  188. for algo in ${!hash_sizes[@]}
  189. do
  190. infile="$csv_path/combined_${algo}.csv"
  191. for hsize in ${hash_sizes[$algo]}
  192. do
  193. for cfg in $configs
  194. do
  195. h="${algo^^}-$hsize"
  196. v=$(cg config $cfg $infile | cg algorithm $h | csvcut -c MiB/s | tail -n +2 | sed 's@\..*$@@')
  197. [ "$v" != "" ] && echo "$h\n$cfg $v" >> $outfile
  198. done
  199. echo >> $outfile
  200. done
  201. done
  202. gnuplot << EOF
  203. set terminal $gnuplot_terminal
  204. set title "SHA2/SHA3 on Xilinx Versal"
  205. set x2label "${desc_others}"
  206. set xlabel 'Configurations' offset 0,-1
  207. set ylabel "MiB/s"
  208. set style fill solid
  209. set style line 1 lc rgb "grey50"
  210. set boxwidth 0.5
  211. unset key
  212. set output "${img_path}/sha.${gnuplot_terminal%% *}"
  213. plot "$outfile" using :2:xtic(1) with boxes ls 1, \
  214. '' using :2:2 w labels offset 0,0.7
  215. EOF
  216. ###
  217. # MACs
  218. declare -A macs
  219. macs["cmac"]="128 256"
  220. plotstring=
  221. outfile=$log_path/mac.log
  222. echo -n "" > $outfile
  223. for algo in ${!macs[@]}
  224. do
  225. infile="$csv_path/combined_${algo}.csv"
  226. for hsize in ${macs[$algo]}
  227. do
  228. for cfg in $configs
  229. do
  230. h="${algo^^}-$hsize"
  231. v=$(cg config $cfg $infile | cg keysize $hsize | csvcut -c MiB/s | tail -n +2 | sed 's@\..*$@@')
  232. [ "$v" != "" ] && echo "$h\n$cfg $v" >> $outfile
  233. done
  234. echo >> $outfile
  235. done
  236. done
  237. gnuplot << EOF
  238. set terminal $gnuplot_terminal
  239. set title "MAC's on Xilinx Versal"
  240. set x2label "${desc_others}"
  241. set xlabel 'Configurations' offset 0,-1
  242. set ylabel "MiB/s"
  243. set style fill solid
  244. set style line 1 lc rgb "grey50"
  245. set boxwidth 0.5
  246. unset key
  247. set yrange [ 0 : 500 ]
  248. set output "${img_path}/mac.${gnuplot_terminal%% *}"
  249. plot "$outfile" using :2:xtic(1) with boxes ls 1, \
  250. '' using :2:2 w labels offset 0,0.7
  251. EOF
  252. ###
  253. # RNG
  254. plotstring=
  255. outfile=$log_path/rng.log
  256. echo -n "" > $outfile
  257. for algo in rng
  258. do
  259. infile="$csv_path/combined_${algo}.csv"
  260. for cfg in $configs
  261. do
  262. h="${algo^^}"
  263. v=$(cg config $cfg $infile | csvcut -c MiB/s | tail -n +2 | sed 's@\..*$@@')
  264. [ "$v" != "" ] && echo "$h\n$cfg $v" >> $outfile
  265. done
  266. echo >> $outfile
  267. done
  268. gnuplot << EOF
  269. set terminal $gnuplot_terminal
  270. set title "RNG on Xilinx Versal"
  271. set x2label "${desc_others}"
  272. set xlabel 'Configurations' offset 0,-1
  273. set ylabel "MiB/s"
  274. set style fill solid
  275. set style line 1 lc rgb "grey50"
  276. set boxwidth 0.5
  277. unset key
  278. set yrange [ 0 : 50 ]
  279. with_unit(Value,Unit) = sprintf("%d %s", Value, Unit)
  280. set output "${img_path}/rng.${gnuplot_terminal%% *}"
  281. plot "$outfile" using :2:xtic(1) with boxes ls 1, \
  282. '' using :2:2 w labels offset 0,0.7
  283. EOF
  284. #eof