-#!/bin/sh
+#!/usr/bin/perl -w
+use Getopt::Std;
+use File::Basename;
-SET_TERM_TEMPLATE='set term push; set term x11 enhanced; set term wxt enhanced; set term pop'
+# Default values
+$SET_TERM_TEMPLATE='set term push; set term x11 enhanced; set term wxt enhanced; set term pop';
+$DELAY_BOUND="[]";
+$MULTIPDF_FILENAME="all.pdf";
-DELAY_BOUND="[]"
+# Process command line options
+my %opt;
+getopts('bd:emnso:pPt:', \%opt);
+$PLOT_SINGLE_EXPERIMENT = $opt{'m'} ? 0 : 1;
+$EXPERIMENT_TITLES = $opt{'t'};
+$PLOT_BOTH_DIRECTIONS=1 if $opt{'b'};
+$
+$DELAY_BOUND="[0:".$opt{'d'}."]" if $opt{'d'};
+$SET_TERM_TEMPLATE='set term postscript color eps enhanced; set output "${FILE}.eps"' if $opt{'e'};
+$SET_TERM_TEMPLATE='set term png enhanced; set output "${FILE}.png"' if $opt{'n'};
+$SET_TERM_TEMPLATE='set term svg enhanced; set output "${FILE}.svg"' if $opt{'s'};
+$MULTIPDF_FILENAME=$opt{'o'} if $opt{'o'};
+if ($opt{'p'}) {
+ $SET_TERM_TEMPLATE='set term postscript color landscape enhanced';
+ $PDF_OUTPUT=1;
+}
+if ($opt{'P'}) {
+ $SET_TERM_TEMPLATE='set term postscript color landscape enhanced';
+ $MULTIPLE_GRAPHS_IN_PDF=1;
+ $GNUPLOT_CMD_FILE="plot_commands.$$";
+ unlink ${GNUPLOT_CMD_FILE};
+}
-while getopts d:enso:pP opt
-do
- case $opt in
- d) DELAY_BOUND="[0:$OPTARG]";;
- e) SET_TERM_TEMPLATE='set term postscript color eps enhanced; set output "${FILE}.eps"';;
- n) SET_TERM_TEMPLATE='set term png enhanced; set output "${FILE}.png"';;
- s) SET_TERM_TEMPLATE='set term svg enhanced; set output "${FILE}.svg"';;
- o) MULTIPDF_FILENAME=$OPTARG;;
- p)
- SET_TERM_TEMPLATE='set term postscript color landscape enhanced'
- PDF_OUTPUT=1
- ;;
- P)
- SET_TERM_TEMPLATE='set term postscript color landscape enhanced'
- MULTIPLE_GRAPHS_IN_PDF=1
- GNUPLOT_CMD_FILE=plot_commands.$$
- rm -f ${GNUPLOT_CMD_FILE}
- ;;
- esac
-done
+if ($#ARGV < 0 && -r "delay_stats.dat") {$ARGV[0]="delay_stats.dat";}
-shift $(($OPTIND - 1))
+# Process the data files and plot graph(s)
+foreach $dat_file (@ARGV) {
+ ($FILE, , ) = fileparse($dat_file, (".dat"));
-[ $# -eq 0 -a -r delay_stats.dat ] && set delay_stats.dat
+ # Get labels from data file
+ $COMMAND="";
+ $STREAMS="";
+ open F, $dat_file;
+ while (<F>) {
+ if (/wclient.*/) {
+ $_=$&;
+ s/ -o [^ ]*//g;
+ $COMMAND="Results of: $_";
+ #$COMMAND="Results of: grep -o 'wclient.*'|sed -e 's/ -o [^ ]*//' -e 's/ [^ ]* ?$//')"
+ } elsif (/^#[^#] */) {
+ $STREAMS .= "$'";
+ }
+
+
+ }
+ close F;
+ $STREAMS =~ s/\n/\\n/g;
+ if ($MULTIPLE_GRAPHS_IN_PDF) {
+ open CMD, ">>$GNUPLOT_CMD_FILE";
+ } elsif ($PDF_OUTPUT) {
+ open CMD, "| gnuplot | ps2pdf - ${FILE}.pdf";
+ } else {
+ open CMD, "| gnuplot -persist";
+ }
+# close CMD;
+# open CMD, ">&STDOUT";
+ $SET_TERM = $SET_TERM_TEMPLATE;
+ $SET_TERM =~ s/\${FILE}/$FILE/;
-while [ $# -gt 0 ];
-do
- FILE=`basename "$1" .dat`
- shift
-
- COMMAND="Results of: $(grep 'Invoked as' ${FILE}.dat|grep -o 'wclient.*'|sed -e 's/ -o [^ ]*//' -e 's/ [^ ]* ?$//')"
- STREAMS="$(grep '^#' ${FILE}.dat|sed -ne '2,$ s/^# //p'|while read LINE; do echo $LINE\\n; done|tr -d '\n')"
-
- SET_TERM=$(echo $SET_TERM_TEMPLATE|sed -e s/\${FILE}/$FILE/)
- if [ -n "$MULTIPLE_GRAPHS_IN_PDF" ]; then
- CMD="cat >>$GNUPLOT_CMD_FILE"
- elif [ -n "$PDF_OUTPUT" ]; then
- CMD="cat | gnuplot | ps2pdf - ${FILE}.pdf"
- else
- CMD="cat | gnuplot -persist"
- fi
- eval $CMD <<EOF
+ print CMD qq/
${SET_TERM}
set xlabel "Response-Time [ms]"
set ylabel "Cumulative % of packets"
set size 1,0.8
unset label
set label "${COMMAND}" noenhanced at graph 0,1.3
-set label "${STREAMS}" noenhanced at graph 0,1.2 font "helv,6"
-plot $DELAY_BOUND \
- "${FILE}.dat" index 0 title "AC\\\\_VO",\
- "${FILE}.dat" index 1 title "AC\\\\_VI",\
- "${FILE}.dat" index 2 title "AC\\\\_BE",\
- "${FILE}.dat" index 3 title "AC\\\\_BK"
-EOF
-done
+set label "${STREAMS}" noenhanced at graph 0,1.2 font "Helvetica,9"
+/;
+ if ($PLOT_SINGLE_EXPERIMENT) {
+ print CMD qq/
+set style line 1 lt 1 lc rgb "red"
+set style line 2 lt 1 lc rgb "green"
+set style line 3 lt 1 lc rgb "blue"
+set style line 4 lt 1 lc rgb "magenta"
+set style line 5 lt 2 lc rgb "red" lw 2
+set style line 6 lt 2 lc rgb "green" lw 2
+set style line 7 lt 2 lc rgb "blue" lw 2
+set style line 8 lt 2 lc rgb "magenta" lw 2
+set style line 9 lt 3 lc rgb "red" lw 2
+set style line 10 lt 3 lc rgb "green" lw 2
+set style line 11 lt 3 lc rgb "blue" lw 2
+set style line 12 lt 3 lc rgb "magenta" lw 2
+/;
+ print CMD qq/plot $DELAY_BOUND [0.01:100]\\
+ "${FILE}.dat" index 0 using 1:2 with linespoints ls 1 title "AC\\\\_VO",\\
+ "${FILE}.dat" index 1 using 1:2 with linespoints ls 2 title "AC\\\\_VI",\\
+ "${FILE}.dat" index 2 using 1:2 with linespoints ls 3 title "AC\\\\_BE",\\
+ "${FILE}.dat" index 3 using 1:2 with linespoints ls 4 title "AC\\\\_BK"/;
+
+ if ($PLOT_BOTH_DIRECTIONS) {
+ print CMD qq/,\\
+ "${FILE}.dat" index 0 using 1:3 with lines ls 5 title "AC\\\\_VO cs",\\
+ "${FILE}.dat" index 1 using 1:3 with lines ls 6 title "AC\\\\_VI cs",\\
+ "${FILE}.dat" index 2 using 1:3 with lines ls 7 title "AC\\\\_BE cs",\\
+ "${FILE}.dat" index 3 using 1:3 with lines ls 8 title "AC\\\\_BK cs",\\
+ "${FILE}.dat" index 0 using 1:4 with lines ls 9 title "AC\\\\_VO sc",\\
+ "${FILE}.dat" index 1 using 1:4 with lines ls 10 title "AC\\\\_VI sc",\\
+ "${FILE}.dat" index 2 using 1:4 with lines ls 11 title "AC\\\\_BE sc",\\
+ "${FILE}.dat" index 3 using 1:4 with lines ls 12 title "AC\\\\_BK sc"
+/;
+ } else {
+ print CMD "\n";
+ }
+ } else {
+ # Multiple experiments in a single plot
+ print CMD qq/
+set style line 1 lt 1 lc rgb "red" lw 2
+set style line 2 lt 1 lc rgb "green" lw 2
+set style line 3 lt 1 lc rgb "blue" lw 2
+set style line 4 lt 1 lc rgb "magenta" lw 2
+set style line 5 lt 2 lc rgb "red" lw 2
+set style line 6 lt 2 lc rgb "green" lw 2
+set style line 7 lt 2 lc rgb "blue" lw 2
+set style line 8 lt 2 lc rgb "magenta" lw 2
+set style line 9 lt 3 lc rgb "red" lw 2
+set style line 10 lt 3 lc rgb "green" lw 2
+set style line 11 lt 3 lc rgb "blue" lw 2
+set style line 12 lt 3 lc rgb "magenta" lw 2
+/;
+ my ($ls1, $ls2, $ls3, $ls4) = (1,2,3,4);
+ my @titles = split(/;/, $EXPERIMENT_TITLES);
+ my $experiment = 0;
+ my $t=$titles[$experiment];
+ $t = '' unless $t;
+ print CMD qq/plot $DELAY_BOUND [0.01:100]\\
+ "${FILE}.dat" index 0 with lines ls $ls1 title "AC\\\\_VO $t",\\
+ "${FILE}.dat" index 1 with lines ls $ls2 title "AC\\\\_VI $t",\\
+ "${FILE}.dat" index 2 with lines ls $ls3 title "AC\\\\_BE $t",\\
+ "${FILE}.dat" index 3 with lines ls $ls4 title "AC\\\\_BK $t"/;
+ foreach $dat_file (@ARGV[1,2]) {
+ last if (!defined $dat_file);
+ $experiment++;
+ $t=$titles[$experiment];
+ $t = '' unless $t;
+ ($FILE, , ) = fileparse($dat_file, (".dat"));
+ ($ls1, $ls2, $ls3, $ls4) = map($_+4, ($ls1, $ls2, $ls3, $ls4));
+ print CMD qq/,\\
+ "${FILE}.dat" index 0 with lines ls $ls1 title "AC\\\\_VO $t",\\
+ "${FILE}.dat" index 1 with lines ls $ls2 title "AC\\\\_VI $t",\\
+ "${FILE}.dat" index 2 with lines ls $ls3 title "AC\\\\_BE $t",\\
+ "${FILE}.dat" index 3 with lines ls $ls4 title "AC\\\\_BK $t"/;
+ }
+ print CMD "\n";
+ last;
+ }
+
+ close CMD;
+}
-if [ -n "$MULTIPLE_GRAPHS_IN_PDF" ]; then
- gnuplot $GNUPLOT_CMD_FILE|ps2pdf - $MULTIPDF_FILENAME
- rm -f $GNUPLOT_CMD_FILE
-fi
+if ($MULTIPLE_GRAPHS_IN_PDF) {
+ system("gnuplot $GNUPLOT_CMD_FILE|ps2pdf - $MULTIPDF_FILENAME");
+ unlink ${GNUPLOT_CMD_FILE};
+}