summaryrefslogtreecommitdiff
path: root/cdrom/tools/latencies.sh
diff options
context:
space:
mode:
authorguest <guest@cba7306a-a4a0-4afd-bcb4-bd19f8a24309>2007-11-30 13:41:25 +0000
committerguest <guest@cba7306a-a4a0-4afd-bcb4-bd19f8a24309>2007-11-30 13:41:25 +0000
commiteacbf5bb4d57af21c731f41251015d3b991ad490 (patch)
tree477f43a79c75b400228a7c492f670a1c4886b5c3 /cdrom/tools/latencies.sh
final version, initial import
git-svn-id: svn+ssh://mecka.net/home/svn/rtcorba-thesis@1 cba7306a-a4a0-4afd-bcb4-bd19f8a24309
Diffstat (limited to 'cdrom/tools/latencies.sh')
-rwxr-xr-xcdrom/tools/latencies.sh143
1 files changed, 143 insertions, 0 deletions
diff --git a/cdrom/tools/latencies.sh b/cdrom/tools/latencies.sh
new file mode 100755
index 0000000..19d123b
--- /dev/null
+++ b/cdrom/tools/latencies.sh
@@ -0,0 +1,143 @@
+#!/bin/bash
+#
+# Simple bash script for parsing and evaluating a CSV file
+# (C) 2006 Jan Altenberg <tb10alj@tglx.de>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License Version
+# 2 as published by the Free Software Foundation.
+
+GNUPLOT=`which gnuplot`
+
+split_values ()
+{
+ if [ "$2" = "save_old_state" ]
+ then
+ OLD_TIME=$TIME
+ OLD_CH1=$CH1
+ OLD_CH2=$CH2
+ TIME=`echo $1 | cut -f1 -d,`
+ CH1=`echo $1 | cut -f2 -d,`
+ CH2=`echo $1 | cut -f3 -d,`
+ else
+ TIME=`echo $1 | cut -f1 -d,`
+ CH1=`echo $1 | cut -f2 -d,`
+ CH2=`echo $1 | cut -f3 -d,`
+ fi
+}
+
+# We need to convert the TIME value in a format which is readable by bc ;-(
+# 1e-04 -> 1 / (10^4)
+# 1e+04 -> 1 * (10^4)
+convert_time_value ()
+{
+ VALUE=`echo $1 | sed 's/e-\(.*\)$/\/(10\^\1)/g' | sed 's/e+\(.*\)$/*(10^\1)/'`
+ echo $VALUE
+}
+
+print_help ()
+{
+ echo "Usage: $0 -f CSV-file -p PLOT-file"
+ echo " -f CSV-file (where your data is stored)"
+ echo " -p PLOT-file (where the plot image will be stored)"
+}
+
+# Parsing command line options
+while getopts "f:p:v" OPTION
+do
+ case $OPTION in
+ f ) FILE=$OPTARG;;
+ p ) PLOT_FILE=$OPTARG;;
+ v ) VERBOSE="ON";;
+ * ) print_help; exit 1;;
+ esac
+done
+
+if [ ! "$FILE" ]
+then
+ print_help
+ exit 1
+fi
+
+if [ ! -e $FILE ]
+then
+ echo "Input file does not exist!"
+ exit 1
+fi
+
+if [ ! "$PLOT_FILE" ]
+then
+ print_help
+ exit 1
+fi
+
+if [ ! "$GNUPLOT" ]
+then
+ echo "Please install gnuplot ! !"
+ exit 1
+fi
+
+TMPFILE=/tmp/latencies_$$
+RESULT_TMPFILE=/tmp/latencies_results_$$
+
+echo "Parsing CSV file..."
+echo " Removing table head..."
+cat $FILE | sed '/.*TIME.*/d' > $TMPFILE
+
+echo " Seperating values..."
+for LINE in $(cat $TMPFILE)
+do
+ if [ ! "$TIME_START" ]
+ then
+ if [ ! "$TIME" ]
+ then
+ split_values $LINE
+ continue
+ else
+ split_values $LINE "save_old_state"
+ if [ "`echo "scale=2; $CH1 - $OLD_CH1" | bc`" != "0" ]
+ then
+ TIME_START=`convert_time_value $TIME`
+ TIME=""
+ else
+ continue
+ fi
+ fi
+ else
+ split_values $LINE "save_old_state"
+ if [ "`echo "scale=2; $CH2 - $OLD_CH2" | bc`" != "0" ]
+ then
+ TIME_END=`convert_time_value $TIME`
+ [ "$VERBOSE" = "ON" ] && echo " Found latency -> $TIME_END - $TIME_START"
+ echo "scale=10; ($TIME_END - $TIME_START)" | bc | sed 's/^\./0\./' >> $RESULT_TMPFILE
+ TIME_START=""
+ TIME_END=""
+ TIME=""
+ else
+ continue
+ fi
+ fi
+done
+
+echo "Generating plot..."
+cat $RESULT_TMPFILE | sort -n | uniq -c | sed 's/^ *//' | sed s'/0*$//'> $TMPFILE
+cp $TMPFILE $RESULT_TMPFILE
+
+XMAX=`cat $RESULT_TMPFILE | cut -f2 -d' ' | sort -rn | head -n1`
+YMAX=`cat $RESULT_TMPFILE | cut -f1 -d' ' | sort -rn | uniq | head -n1`
+XRANGE=`expr "$XMAX * 2"`
+YRANGE=`expr "$YMAX * 2"`
+
+echo " XMAX $XMAX"
+echo " YMAX $YMAX"
+
+echo -e "set title \"Latency test\"\n\
+set terminal pbm color\n\
+set xrange [0:$XRANGE]\n\
+set yrange [0:$YRANGE]\n\
+set ylabel\"n\"\n\
+set style fill solid 0.250000 border\n\
+set output \"$PLOT_FILE\"
+plot \"$RESULT_TMPFILE\" using 2:1 \"%lf%lf\" notitle with boxes" | gnuplot -persist
+
+display $PLOT_FILE