#!/bin/bash
#
# webreport.sh connects to the Results database and generates a web page
# as index.htm that includes links to all the results in the database
#
source ./config
OUTFILE="results/index.htm"
RESULTPSQL="psql -h $RESULTHOST -U $RESULTUSER -p $RESULTPORT -d $RESULTDB"
# Emulate 'sed -i' behavior from GNU sed with standard sed instead.
# Needed on platforms like Solaris.
function sed-i {
replace=$1
filename=$2
sed "$replace" ${filename} > ${filename}.new
mv ${filename}.new ${filename}
}
# TODO These two plots should be computed on a per-set basis by the below code
# instead of just having the one combined graph here
$RESULTPSQL -At -F" " -c "select scale,round(avg(dbsize) / (1024 * 1024)) as dbsize,round(avg(tps)) as tps from tests group by scale order by scale" > scaling.txt
gnuplot plots/scaling.plot
mv scaling.png results/
rm scaling.txt
$RESULTPSQL -At -F" " -c "select clients,round(avg(tps)) as tps from tests group by clients order by clients" > clients.txt
gnuplot plots/clients.plot
mv clients.png results/
rm clients.txt
$RESULTPSQL -At -F" " -c "select scale,clients,round(avg(tps)) as tps from tests group by scale,clients order by scale,clients" > 3d.txt
gnuplot plots/3d.plot
mv 3d.png results/
rm 3d.txt
# Generate HTML
echo > $OUTFILE
echo "
" >> $OUTFILE
echo "
" >> $OUTFILE
echo "
" >> $OUTFILE
# Loop over all the active test sets
SETS=`$RESULTPSQL -A -t -c "select set from tests group by set order by set"`
for SET in $SETS ; do
DESCR=`$RESULTPSQL -A -t -c "select info from testset where set='$SET'"`
echo "
Set" $SET : $DESCR"
" >> $OUTFILE
# Summarize the test set
echo Averages for test set $SET by scale: >> $OUTFILE
$RESULTPSQL -H -c "select set,scale,round(avg(tps)) as tps,round(1000*avg(avg_latency))/1000 as avg_latency,round(1000*avg(percentile_90_latency))/1000 as \"90%<\",round(1000 * avg(max_latency))/1000 as max_latency from tests where tests.set='$SET' group by set,scale order by set,scale;" >> $OUTFILE
echo Averages for test set $SET by clients: >> $OUTFILE
$RESULTPSQL -H -c "select set,clients,round(avg(tps)) as tps,round(1000*avg(avg_latency))/1000 as avg_latency,round(1000*avg(percentile_90_latency))/1000 as \"90%<\",round(1000 * avg(max_latency))/1000 as max_latency from tests where tests.set='$SET' group by set,clients order by set,clients;" >> $OUTFILE
echo Averages for test set $SET by scale and client: >> $OUTFILE
$RESULTPSQL -H -c "select set,scale,clients,round(avg(tps)) as tps,round(1000*avg(avg_latency))/1000 as avg_latency,round(1000*avg(percentile_90_latency))/1000 as \"90%<\",round(1000 * avg(max_latency))/1000 as max_latency from tests where tests.set='$SET' group by set,scale,clients order by set,scale,clients;" >> $OUTFILE
echo Detail for test set $SET: >> $OUTFILE
# Create a line showing the results for every test as an HTML table
$RESULTPSQL -H -c "select set,'' || tests.test || '' as test,scale,clients,round(tps) as tps,max_latency, checkpoints_timed+checkpoints_req as chkpts,buffers_checkpoint as buf_check,buffers_clean as buf_clean,buffers_backend as buf_backend,buffers_alloc as buf_alloc, maxwritten_clean as max_clean, buffers_backend_fsync as backend_sync from test_bgwriter right join tests on tests.test=test_bgwriter.test where tests.set='$SET' order by set,scale,clients,tests.test;" > temp.txt
# Now we need to fix lines like this
# <a href="results/201/">201</a> |
# where PSQL has quoted things we wanted literally
sed-i "s/<//g" temp.txt
sed-i "s/"/\"/g" temp.txt
cat temp.txt >> $OUTFILE
# Remove row counts
cp $OUTFILE temp.txt
cat temp.txt | grep -v " rows)" > $OUTFILE
done
rm temp.txt