#!/bin/sh
#
# Driver script to run resperf and generate an HTML report of
# the results, with graphs.
#

# Program locations - change these if not in $PATH
resperf=resperf
gnuplot=gnuplot

# Create a unique ID for this report
id=`date '+%Y%m%d-%H%M'`

# Set up file names
reportfile="$id.html"
outputfile="$id.output"
plotfile="$id.gnuplot"
rate_gif="$id.rate.gif"
latency_gif="$id.latency.gif"

# Run the test
$resperf -P "$plotfile" "$@" >"$outputfile" 2>&1

# Create plots

$gnuplot <<EOF
set terminal gif
set output "$rate_gif"
set title "Query / response / failure rate"
set key top left
set xlabel "Time (seconds)"
set yrange [0:]
plot \
"$plotfile" using 1:3 title "Queries sent per second" with lines, \
"$plotfile" using 1:4 title "Total responses received per second" with lines, \
"$plotfile" using 1:5 title "Failure responses received per second" with lines
EOF

$gnuplot <<EOF
set terminal gif
set output "$latency_gif"
set title "Latency"
set key top left
set xlabel "Time (seconds)"
set yrange [0:]
plot \
"$plotfile" using 1:6 title "Average latency (seconds)" with lines
EOF

# Generate the report

exec >"$reportfile"

cat <<EOF
<html><head></head><body>
<h1>Resperf report $id</h1>
<h2>Resperf output</h2>
<pre>
EOF
cat "$outputfile"
cat <<EOF
</pre>
EOF

cat <<EOF
<h2>Plots</h2>
<p>
<img src="$rate_gif" />
<img src="$latency_gif" />
</p>
</body></html>
EOF

echo "Done, report is in $reportfile" >&2



syntax highlighted by Code2HTML, v. 0.9.1