#!/bin/sh

clients="32"
times="1800"
scales="300"
types="p"
branches="dwbuf2"

~/install/master/bin/pg_ctl stop -mf

for x in 1; do
  for client in $clients; do
    for time in $times; do
      for scale in $scales; do
        for branch in $branches; do
          for type in $types; do
            ident="l$type.$branch.$client.$scale.$time"
			echo "run=$x clients=$client time=$time scale=$scale branch=$branch type=$type"
			~/install/$branch/bin/pg_ctl start -l ~/log/log.$ident
			sleep 5
			~/install/$branch/bin/dropdb rhaas
			~/install/$branch/bin/createdb rhaas
			if [ $type = u ]; then
				~/install/master/bin/pgbench -i -s $scale --unlogged-tables
			else
				~/install/master/bin/pgbench -i -s $scale
			fi
			if [ $type = s ]; then
				extraopts="-n -S"
			else
				extraopts="-n"
			fi
			sleep 5
			mkdir -p  ~/results/latency/$branch || exit 1
			cd ~/results/latency/$branch || exit 1
			~/install/master/bin/pgbench -l -T $time -c $client -j $client $extraopts \
				>> ~/results/results$ident
			psql -c CHECKPOINT
			~/install/$branch/bin/pg_ctl stop -m fast
			sleep 5
          done
		done
	  done
	done
  done
done
