#!/bin/bash

`dirname $0`/latency-test-extract "$@" > data.txt
gnuplot <<\EOF
set term svg size 1024,768
set output "latency-sync-listener.svg"
set st d lp
set st li 1 lw 2
set st li 2 lw 2
set st li 3 lw 2
set st li 4 lw 2
set st li 5 lw 2

set multiplot
set logscale xy
set title "Latency"
set ylabel "[µs]"
set grid xtics ytics mytics
set xlabel "payload size [bytes]"
p "data.txt" u 1:3 ti "min", "" u 1:4 ti "median", "" u 1:5 ti "90%", "" u 1:6 ti "99%", "" u 1:7 ti "max"
unset logscale y
unset xlabel
unset ylabel
unset title
set grid nomytics
set origin .1, .40
set size .55, .5
clear
p [10:1000]  "data.txt" u 1:3 ti "min", "" u 1:4 ti "median", "" u 1:5 ti "90%", "" u 1:6 ti "99%", "" u 1:7 ti "max"
unset multiplot

unset origin
unset size

unset logscale
set logscale x
set output "latency-sync-listener-bwcpu.svg"
set title "Latency: network bandwidth and CPU usage"
set y2tics
set ylabel "[Gbps]"
set y2label "CPU [%]"
set xlabel "payload size [bytes]"
set key at graph 1, 0.7
p "data.txt" u 1:($8/1e3) ti "GbE transmit bandwidth (left)", "" u 1:($9/1e3) ti "GbE receive bandwidth (left)", "" u 1:13 axes x1y2 ti "ping CPU (right)", "" u 1:15 axes x1y2 ti "pong CPU (right)"

EOF
