test_pgo.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. CUR_DIR=$PWD
  5. OUT_DIR=$CUR_DIR/out
  6. REPORT=$CUR_DIR/report.txt
  7. TIME=/usr/bin/time
  8. PLATFORM=$(uname -s | tr A-Z a-z)
  9. if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then
  10. IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm"
  11. WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc -sgx"
  12. else
  13. IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm"
  14. WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc"
  15. fi
  16. BENCH_NAME_MAX_LEN=20
  17. JETSTREAM_CASES="gcc-loops HashSet tsf float-mm quicksort"
  18. rm -f $REPORT
  19. touch $REPORT
  20. function print_bench_name()
  21. {
  22. name=$1
  23. echo -en "$name" >> $REPORT
  24. name_len=${#name}
  25. if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
  26. then
  27. spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
  28. for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
  29. fi
  30. }
  31. pushd $OUT_DIR > /dev/null 2>&1
  32. for t in $JETSTREAM_CASES
  33. do
  34. if [ ! -e "${t}.wasm" ]; then
  35. echo "${t}.wasm doesn't exist, please run build.sh first"
  36. exit
  37. fi
  38. echo ""
  39. echo "Compile ${t}.wasm to ${t}.aot .."
  40. ${WAMRC_CMD} -o ${t}.aot ${t}.wasm
  41. echo ""
  42. echo "Compile ${t}.wasm to ${t}_pgo.aot .."
  43. ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm
  44. echo ""
  45. echo "Run ${t}_pgo.aot to generate the raw profile data .."
  46. ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot
  47. echo ""
  48. echo "Merge the raw profile data to ${t}.profdata .."
  49. rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw
  50. echo ""
  51. echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .."
  52. ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm
  53. done
  54. popd > /dev/null 2>&1
  55. echo "Start to run cases, the result is written to report.txt"
  56. #run benchmarks
  57. cd $OUT_DIR
  58. echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT
  59. for t in $JETSTREAM_CASES
  60. do
  61. print_bench_name $t
  62. echo "run $t with native .."
  63. echo -en "\t" >> $REPORT
  64. $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  65. echo "run $t with iwasm aot .."
  66. echo -en "\t" >> $REPORT
  67. $TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  68. echo "run $t with iwasm aot opt .."
  69. echo -en "\t" >> $REPORT
  70. $TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  71. echo -en "\n" >> $REPORT
  72. done