graph.sh 9.3 KB

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