time-and-save.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Save path the current path that will be used to store the results.
  3. BASE_PATH=$(pwd)
  4. # Variable to store the name of the benchmark
  5. BENCH_NAME=$1
  6. # Local variable to store if cpu or gpu directed benchmark
  7. TYPE=$2
  8. # A bit of debug info to the user
  9. echo "We are executing the benchmark $BENCH_NAME for $TYPE"
  10. # Check if we need to create the directories to store the results
  11. if [ ! -d "results" ]; then
  12. mkdir results
  13. fi
  14. if [ ! -d "results/$TYPE" ]; then
  15. mkdir results/$TYPE
  16. fi
  17. # Start power measurement
  18. ./SmartPower results/$TYPE/power-usage.csv >/dev/null & export PID_POWER=$!
  19. # Enter in the directory of the benchmarks
  20. cd $BENCH_NAME
  21. # Start and time the actual benchmark and save the result in a local variable
  22. BENCH_TIME=`(/usr/bin/time -f "%e" ./run-$TYPE) 2>&1 > /dev/zero | tail -1`
  23. # Stop power measurement
  24. kill -SIGUSR1 $PID_POWER
  25. # Wait until the Smartpower utility has received the kill signal and force a sync on the disk to avoid reading the previous result from the result file
  26. sleep 10 && sync
  27. # A bit of debug info to the user
  28. echo "Saving the results and preparing for the next benchmark"
  29. # Prepare a log that contains all the info relative to a benchmark
  30. # To retrieve the power measurement we take the third column of the last row from the file where the measurement utility has saved the results
  31. BENCH_CONSUMPTION=`tail -1 $BASE_PATH/results/$TYPE/power-usage.csv | awk '{print $3}' | cut -d, -f2`
  32. echo "$BENCH_NAME, $BENCH_TIME, $BENCH_CONSUMPTION" >> $BASE_PATH/results/$TYPE/total.dat
  33. # Sleep in order to give time to the power measurement script to reset.
  34. sleep 3
  35. # Add an additional SIGKILL to avoid zombie processes in case of a faulty measurement, we ignore the standard output/error and we always succeed, otherwise make will complain
  36. kill -SIGKILL $PID_POWER >/dev/null 2>&1 > /dev/null || true
  37. # Sleep in order to give time to the power measurement script to reset and to dissipate the heat accumuled in the previous benchmark.
  38. sleep 3