1#!/bin/bash
2
3# A script for running the wtperf benchmark to analyze the performance
4# of checkpoint operations.
5
6# General configuration settings:
7BIN_DIR='.'
8ROOT_DIR=`/bin/pwd`
9SCRIPT_DIR=`dirname $0`
10RUNTIME=900
11REUSE=0
12VERBOSE=0
13WORKLOAD=0 # skip the populate phase.
14PERF_BASE="-M"
15OPTFILE=''
16DEBUG=
17GDB=${GDB:-gdb}
18
19USAGE="Usage: `basename $0` [-hdRWsv] [-b binary dir] [-r root dir] [-O optfile]"
20
21# Parse command line options.
22while getopts b:dhO:RWr:sv OPT; do
23    case "$OPT" in
24        b)
25            BIN_DIR=$OPTARG
26            ;;
27        d)
28            export TERM=dtterm
29            DEBUG="$GDB --args"
30            ;;
31        h)
32            echo $USAGE
33            exit 0
34            ;;
35        O)
36            OPTFILE=-O$OPTARG
37            PERF_BASE=""
38            ;;
39        R)
40            REUSE=1
41            ;;
42        r)
43            ROOT_DIR=$OPTARG
44            ;;
45        s)
46            RUNTIME=20
47	    PERF_BASE="-S"
48            ;;
49        v)
50            VERBOSE=0
51            ;;
52        W)
53            WORKLOAD=1
54	    REUSE=1 # skip the populate phase.
55            ;;
56        \?)
57            # getopts issues an error message
58            echo $USAGE >&2
59            exit 1
60            ;;
61    esac
62done
63
64# Configuration settings that may be altered by command line options
65WTPERF=${BIN_DIR}/wtperf
66if [ ! -x $WTPERF ]; then
67	echo "Could not find or execute $WTPERF"
68	exit 1
69fi
70
71DB_HOME="$ROOT_DIR/WT_TEST"
72OUT_DIR="$ROOT_DIR/results"
73SHARED_OPTS="${OPTFILE} ${PERF_BASE} -o read_threads=1,update_threads=1,report_interval=1,uri=\"table:test\" -o verbose=1 -h ${DB_HOME}"
74CREATE_OPTS="$SHARED_OPTS -o run_time=0"
75RUN_OPTS="$SHARED_OPTS -o run_time=$RUNTIME"
76if [ $WORKLOAD -eq 0 ]; then
77	RUN_OPTS="$RUN_OPTS -o create=false"
78else
79	RUN_OPTS="$RUN_OPTS -o icount=0"
80fi
81
82if [ $REUSE -eq 0 ]; then
83	if [ $VERBOSE -ne 0 ]; then
84		echo "Creating database and archiving it for reuse."
85	fi
86	rm -rf $DB_HOME && mkdir $DB_HOME
87	$DEBUG $WTPERF $CREATE_OPTS || exit 1
88
89	# Save the database so that it can be re-used by all runs.
90	# I'd rather not hard code WT_TEST, but need to get the path right.
91	rm -f $ROOT_DIR/WT_TEST.tgz
92	tar zcf $ROOT_DIR/WT_TEST.tgz -C $ROOT_DIR WT_TEST
93fi
94
95rm -rf $OUT_DIR && mkdir $OUT_DIR
96
97# Run the benchmarks..
98# for ckpt in "" "-c 120"; do
99for ckpt in "checkpoint_threads=1,checkpoint_interval=120"; do
100	# for opts in "" "-C eviction_dirty_target=20"; do
101	for opts in ""; do
102		if [ $VERBOSE -ne 0 ]; then
103			echo "Doing a run with:"
104			echo "\t$WTPERF $RUN_OPTS $ckpt $opts"
105		fi
106		res_name="run_${ckpt},${opts}"
107		res_name=`echo $res_name | tr '[:upper:][=\- ,]' '[:lower:]_'`
108		if [ $WORKLOAD -eq 0 ]; then
109			rm -rf $DB_HOME && tar zxf $ROOT_DIR/WT_TEST.tgz -C $ROOT_DIR
110		else
111			rm -rf $DB_HOME && mkdir $DB_HOME
112		fi
113		if [ "$DEBUG" = '' ]; then
114			$WTPERF $RUN_OPTS -o "$ckpt" -o "$opts" &
115			pid=$!
116			t=0
117			while kill -0 $pid 2> /dev/null; do
118				echo "Time $t"
119				pmp $pid
120				sleep 1
121				(( t++ ))
122			done > $OUT_DIR/${res_name}.trace
123		else
124			$DEBUG $WTPERF $RUN_OPTS $ckpt $opts
125		fi
126		cp $DB_HOME/test.stat "$OUT_DIR/${res_name}.res"
127	done
128done
129
130if [ $VERBOSE -ne 0 ]; then
131	echo "Post processing result files."
132fi
133for f in ${OUT_DIR}/*res; do
134	grep "^[0-9]* reads" ${f} | sed -e 's/ reads//' -e 's/ inserts//' -e 's/ updates in 1 secs//' > ${f}.out
135	${SCRIPT_DIR}/get_ckpt.py < ${f} > ${f}.ckpt
136done
137