#!/bin/bash
# Run S-startup benchmark

###SHELLPACK preamble S-startup-bench 8d22ab8

###SHELLPACK parseargBegin
###SHELLPACK parseargParam --iterations       S_STARTUP_ITERATIONS
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required S-startup-${VERSION}
###SHELLPACK init_complete

if [ "$SUDO_USER" != "" ]; then
	CONF_DEST_DIR=/home/$SUDO_USER
else
	CONF_DEST_DIR=~
fi

rm $CONF_DEST_DIR/.S-config.sh
sed -i "s<\$PWD/../workfiles<$SHELLPACK_DATA<g" def_config.sh

# set the number of iterations of each benchmark to $S_STARTUP_ITERATIONS
sed -i "s/NUM_ITER_STARTUP=.*/NUM_ITER_STARTUP=$S_STARTUP_ITERATIONS/g" \
    run_multiple_benchmarks/run_main_benchmarks.sh

# make the test leave single start-up times (raw data) in
# $LOGDIR_RESULTS/results/
# The names of the files containing raw data terminate in -single_times.txt
#
# If a raw file for a given benchmark run contains less samples than
# expected, then the application did not start within 120 seconds at
# some iteration, and then the benchmark was stopped.
sed -i 's<^rm -rf results-${sched}<mv results-${sched}/lat-${sched} $STAT_DEST_DIR/${sched}-${NUM_READERS}r${NUM_WRITERS}w-${RW_TYPE}-single_times.txt 2> /dev/null; rm -rf results-${sched}<' comm_startup_lat/comm_startup_lat.sh

rm -rf $LOGDIR_RESULTS/results
cd run_multiple_benchmarks/

monitor_pre_hook $LOGDIR_RESULTS $P
./run_main_benchmarks.sh replayed-startup cur-sched fs "" "" "" 1 \
			 $LOGDIR_RESULTS/results
monitor_post_hook $LOGDIR_RESULTS $P

exit $SHELLPACK_SUCCESS
