#!/bin/sh
# See LICENSE file for copyright and license details.
#
# Example usage:
# sbm -c 60 -t | sbm-plot > stats.png

command -v gnuplot >/dev/null || {
	echo gnuplot is not installed 1>&2
	exit 1
}

datafile=`mktemp`
while read line; do
	echo "$line" >> "$datafile"
done < /dev/stdin

DATAFILE="$datafile" gnuplot << 'EOF'
set terminal png x040418 xffba00
set terminal png enhanced size 1024, 768
set multiplot layout 1, 2
set autoscale
set grid
set xlabel "time"
set ylabel "Mbps"
datafile=system("echo $DATAFILE")
plot datafile using ($1/1000/1000) with lines title "Rx", \
     datafile using ($2/1000/1000) with lines title "Tx"
set xlabel "time"
set ylabel "pps"
plot datafile using ($3) with lines title "Rx", \
     datafile using ($4) with lines title "Tx"
unset multiplot
EOF

rm -f "$datafile"
