Home | History | Annotate | Download | only in pi_test
      1 #! /bin/sh
      2 
      3 FILE=$1
      4 TMP=$(mktemp -d /tmp/tmp.XXXXXX)
      5 function error
      6 {
      7     cat 1>&2
      8     exit 1
      9     rm -rf $TMP
     10 }
     11 
     12 if ! cols=$(grep "#[ ]*COLUMNS" $FILE)
     13 then
     14     error <<EOF
     15 E: $FILE: Cannot locate the COLUMNS descriptor
     16 EOF
     17 fi
     18 cols=$(echo $cols | sed 's/#//')
     19 columns=$(echo $cols | awk '{print $2;}')
     20 count=1
     21 while [ $count -le $columns ]
     22 do
     23   column[$count]=$(echo $cols | awk -vcount=$count '{print $(2 + count);}')
     24   if [ -z "${column[$count]}" ]
     25       then
     26       column[$count]=$count;
     27   fi
     28   count=$(($count + 1))
     29 done
     30 
     31 # Set up the plot area
     32 count=2
     33 with="with dots"
     34 cat > $TMP/gnuplot.script <<EOF
     35 set xlabel "${column[1]} (s)"
     36 set ylabel "Progress"
     37 EOF
     38 
     39 # Plot the events
     40 height=15
     41 grep "#[ ]*EVENT" $FILE | sed 's/#//' > $TMP/events
     42 cat $TMP/events | while read event x text
     43 do
     44   if ! [ $event = "EVENT" ]
     45       then
     46       cat 1>&2 <<EOF
     47 E: Unknown event type "$event", ignoring
     48 EOF
     49       continue;
     50   fi
     51   height_text=$(($height + 2))
     52   echo "set arrow from $x, graph 0 to $x, graph 0.$height" >> $TMP/gnuplot.script
     53   echo "set label \"$text\" at $x, graph 0.$height_text center" >> $TMP/gnuplot.script
     54   height=$(($height + 8))
     55 done
     56 
     57 # Set Key
     58 echo "set key left top box lt 0" >> $TMP/gnuplot.script
     59 # Plot the data
     60 echo "plot '$FILE' using 1:2 title \"${column[$count]}\" $with" >> $TMP/gnuplot.script
     61 count=3
     62 while [ $count -le $columns ]
     63 do
     64   echo "replot '$FILE' using 1:$count title \"${column[$count]}\" $with" \
     65       >> $TMP/gnuplot.script
     66   count=$(($count + 1))
     67 done
     68 
     69 
     70 ( cat $TMP/gnuplot.script; cat ) | gnuplot
     71 rm -rf $TMP
     72