#!/bin/bash
# This is the script to start and stop the db2snapshot profiler.
#
# reqparam value start|stop|report|postprocess|install Which action you'd like to perform
# reqparam value db - Name of the database for the snapshots to be made of
# reqparam value dbuser - Name of the database user for the snapshots to be made using
# reqparam value interval - Collection interval
# optparam value Suffix - an optional string to append to the name of the log file 
#

# adapted from oprofile script, Karl Rister

. /etc/autobench.conf || . functions

DB2=$1									 
DB=$2
DBUSER=$3
INTERVAL=$4

REPORT_DEST="$LOGDIR/analysis/db2snapshot.$DB.$RUN_NUMBER"
mkdir $REPORT_DEST
touch $AUTODIR/var/tmp/db2snapshot.$DB.running
su - $DBUSER -c "$DB2 connect to $DB; \
OUTNUM=001; \
while [ -e $AUTODIR/var/tmp/db2snapshot.$DB.running ]; do \
	$DB2 get snapshot for database on $DB > $REPORT_DEST/snapshot.\$OUTNUM; \
    OUTNUM=\$(echo \$OUTNUM | awk '{printf (\"%03d\", \$1 + 1)}'); \
	sleep $INTERVAL; \
done; \
$DB2 connect reset"
