test_pgo.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \
  5. aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \
  6. box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \
  7. core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \
  8. generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \
  9. onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \
  10. pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \
  11. scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \
  12. scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \
  13. secretbox secretstream_xchacha20poly1305 shorthash sign siphashx24 sodium_core \
  14. sodium_utils2 sodium_utils stream2 stream3 stream4 stream verify1 xchacha20"
  15. PLATFORM=$(uname -s | tr A-Z a-z)
  16. readonly OUT_DIR=$PWD/libsodium/zig-out/bin
  17. readonly REPORT=$PWD/report.txt
  18. if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then
  19. readonly IWASM_CMD="$PWD/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm"
  20. readonly WAMRC_CMD="$PWD/../../../wamr-compiler/build/wamrc -sgx"
  21. else
  22. readonly IWASM_CMD="$PWD/../../../product-mini/platforms/${PLATFORM}/build/iwasm"
  23. readonly WAMRC_CMD="$PWD/../../../wamr-compiler/build/wamrc"
  24. fi
  25. readonly TIME=/usr/bin/time
  26. BENCH_NAME_MAX_LEN=20
  27. rm -f $REPORT
  28. touch $REPORT
  29. function print_bench_name()
  30. {
  31. name=$1
  32. echo -en "$name" >> $REPORT
  33. name_len=${#name}
  34. if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
  35. then
  36. spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
  37. for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
  38. fi
  39. }
  40. pushd $OUT_DIR > /dev/null 2>&1
  41. for t in $libsodium_CASES
  42. do
  43. if [ ! -e "${t}.wasm" ]; then
  44. echo "${t}.wasm doesn't exist, please run build.sh first"
  45. exit
  46. fi
  47. echo ""
  48. echo "Compile ${t}.wasm to ${t}.aot .."
  49. ${WAMRC_CMD} -o ${t}.aot ${t}.wasm
  50. echo ""
  51. echo "Compile ${t}.wasm to ${t}_pgo.aot .."
  52. ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm
  53. echo ""
  54. echo "Run ${t}_pgo.aot to generate the raw profile data .."
  55. ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot
  56. echo ""
  57. echo "Merge the raw profile data to ${t}.profdata .."
  58. rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw
  59. echo ""
  60. echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .."
  61. ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm
  62. done
  63. # run benchmarks
  64. cd $OUT_DIR
  65. echo -en "\t\t\t\t\t\tnative\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT
  66. for t in $libsodium_CASES
  67. do
  68. print_bench_name $t
  69. echo "run $t with native..."
  70. echo -en "\t" >> $REPORT
  71. if [[ $t != "sodium_utils2" ]]; then
  72. ./${t} | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT
  73. else
  74. # sodium_utils2 doesn't print the result,
  75. # use time command to get result instead
  76. $TIME -f "real-%e-time" ./${t} 2>&1 | grep "real-.*-time" |
  77. awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT
  78. fi
  79. echo "run $t with iwasm aot..."
  80. echo -en "\t \t" >> $REPORT
  81. if [[ $t != "sodium_utils2" ]]; then
  82. $IWASM_CMD ${t}.aot | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT
  83. else
  84. # sodium_utils2 doesn't print the result,
  85. # use time command to get result instead
  86. $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" |
  87. awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT
  88. fi
  89. echo "run $t with iwasm aot opt..."
  90. echo -en "\t \t" >> $REPORT
  91. if [[ $t != "sodium_utils2" ]]; then
  92. $IWASM_CMD ${t}_opt.aot | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT
  93. else
  94. # sodium_utils2 doesn't print the result,
  95. # use time command to get result instead
  96. $TIME -f "real-%e-time" $IWASM_CMD ${t}_opt.aot 2>&1 | grep "real-.*-time" |
  97. awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT
  98. fi
  99. echo -en "\n" >> $REPORT
  100. done