Graphing bandwidth of a pcap file on arbitrary granularity

OK it seems like i’ve done this enough times in my career w/ 1-off command line, i thought i would share w/ the group. This may not have the mass-market appeal of the cat videos, but its probably better for productivity.

The below script will take a capture file, and then graph it’s bandwidth on any arbitrary time-grid granularity. E.g. if you want to know the bandwidth of something over any 0.1s interval, 1s interval, etc.

set -e
if [ $# != 2 ]
 echo "Usage: $0 cap-file granularity(s)"
 exit 1
d=$(mktemp -d)
tshark -o column.format:'"T","%t","L","%L"' -r "$ifile" | awk -v gran=$gran '
 offset = 0
 if ( ($1 - offset) > gran) {
 offset += gran
 bytes[offset] = 0
 printf("%f,%u,%6.2f\n", offset, b, (8.0 * b) / gran)
 bytes[offset] += $2
' > $d/x.dat
cat << EOF > $d/gnuplot.txt
set datafile separator ","
set title "$ifile bitrate (${gran}s granularity)"
set xlabel "Time(seconds)"
set ylabel "Bitrate(bps)"
plot "$d/x.dat" using 1:3 title "$ifile" with lines
pause -1
echo "Press return to finish"
gnuplot $d/gnuplot.txt
rm -rf $d


Leave a Reply

Your email address will not be published. Required fields are marked *