blob: 19d123ba5a6c8bdda337e806f9c278ad118517e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
|