time-and-save.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. # Save path the current path that will be used to store the results.
  3. BASE_PATH=$(pwd)
  4. # Local variable to store if cpu or gpu directed benchmark
  5. TYPE=$3
  6. # Check if we need to create the directories to store the results
  7. if [ ! -d "results" ]; then
  8. mkdir results
  9. fi
  10. if [ ! -d "results/$TYPE" ]; then
  11. mkdir results/$TYPE
  12. fi
  13. # Start power measurement
  14. ./SmartPower results/$TYPE/power-usage.csv & export PID_POWER=$!
  15. echo $PID_POWER
  16. # Enter in the directory passed as first parameter, then execute run and save the results in the file passed as second parameter
  17. cd $1
  18. BENCH_NAME=$1
  19. # Start and time the actual benchmark
  20. BENCH_TIME=`(/usr/bin/time -f "%e" ./run-$TYPE) 2>&1 > /dev/zero | tail -1`
  21. # Stop power measurement
  22. kill -SIGUSR1 $PID_POWER
  23. # Add an additional SIGKILL to avoid zombie processes in case of a faulty measurement
  24. kill -SIGKILL $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
  26. sleep 5 && sync
  27. # Save execution time in the log
  28. echo "$BENCH_NAME $BENCH_TIME" >> $BASE_PATH/results/$TYPE/$2
  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