#!/bin/bash

chmod 777 output -R
ps auxwwf > output/ps.before
for TEST in 1 2 3
do
    echo "`date` - test #$test started"
    sql test -U pgdba -d template1 -c 'drop database depesz; create database depesz'
    for a in test*.sql
    do
        F=`echo $a | sed 's/.sql$//'`
        if [ -e output/$F-$TEST-stat-after ]
        then
            continue
        fi
        echo "$TEST-$a"
        cat $a > /dev/null # populate kernel file-cache
        cp /proc/stat output/$F-$TEST-stat-before
        /usr/bin/time -p -o output/$F-$TEST-time sql test -qAt -f $a > output/$F-$TEST-output 2>&1
        cp /proc/stat output/$F-$TEST-stat-after
        sql test -qAt -c "DROP TABLE $F"
    done
    echo "`date` - test #$test finished"
done
ps auxwwf > output/ps.after
