f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#!/bin/sh
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Driver script to run resperf and generate an HTML report of
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# the results, with graphs.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt#
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Program locations - change these if not in $PATH
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntresperf=resperf
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntgnuplot=gnuplot
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# The gnuplot terminal type. This determines the image format for the
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# plots; "png" or "gif" will both work as long as the corresponding
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# terminal support is compiled into your copy of gnuplot.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntterminal=png
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Create a unique ID for this report
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntid=`date '+%Y%m%d-%H%M'`
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Set up file names
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntreportfile="$id.html"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntoutputfile="$id.output"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntplotfile="$id.gnuplot"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntrate_graph="$id.rate.$terminal"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntlatency_graph="$id.latency.$terminal"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Run the test
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt$resperf -P "$plotfile" "$@" >"$outputfile" 2>&1 ||
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt { echo "`basename $0`: error running resperf:" >&2;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt cat $outputfile >&2;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt exit 1;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt }
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Create plots
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntif
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt $gnuplot <<EOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset terminal $terminal
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset output "$rate_graph"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset title "Query / response / failure rate"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset key top left
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset xlabel "Time (seconds)"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset yrange [0:]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntplot \
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt"$plotfile" using 1:3 title "Queries sent per second" with lines, \
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt"$plotfile" using 1:4 title "Total responses received per second" with lines, \
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt"$plotfile" using 1:5 title "Failure responses received per second" with lines
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntEOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntthen
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt :
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntelse
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt echo "`basename $0`: error running gnuplot" >&2; exit 1;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntfi
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntif
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt $gnuplot <<EOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset terminal $terminal
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset output "$latency_graph"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset title "Latency"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset key top left
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset xlabel "Time (seconds)"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset yrange [0:]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntplot \
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt"$plotfile" using 1:6 title "Average latency (seconds)" with lines
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntEOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntthen
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt :
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntelse
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt echo "`basename $0`: error running gnuplot" >&2; exit 1;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntfi
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Generate the report
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntexec >"$reportfile"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntcat <<EOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<html><head></head><body>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<h1>Resperf report $id</h1>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<h2>Resperf output</h2>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<pre>
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntEOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntcat "$outputfile"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntcat <<EOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt</pre>
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntEOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntcat <<EOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<h2>Plots</h2>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<p>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<img src="$rate_graph" />
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt<img src="$latency_graph" />
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt</p>
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt</body></html>
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntEOF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntecho "Done, report is in $reportfile" >&2
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt