2 # dumps a gnuplot script to stdout that plot of the given log
5 Usage:$0 [--title=<title>] [--log=<log>] [--format={png,pdf,ps,svg}] [--pagesize={a3,a4}]| gnuplot"
8 title="GStreamer trace"
13 # process commandline options
14 # @todo: add support for single letter options
17 X--version) echo "0.1"; exit 0;;
18 X--help) echo "$usage"; exit 0;;
19 X--title=*) title=`echo $1 | sed s/.*=//`; shift;;
20 X--log=*) log=`echo $1 | sed s/.*=//`; shift;;
21 X--format=*) format=`echo $1 | sed s/.*=//`; shift;;
22 X--pagesize=*) pagesize=`echo $1 | sed s/.*=//`; shift;;
33 base=`basename "$log" ".log"`
36 grep "TRACE" $log | grep "GST_TRACER" >$tmp/trace.log
39 grep -o "proc-rusage,.*" $log | cut -c14- | sed -e 's#process-id=(guint64)[0-9][0-9]*, ##' -e 's#ts=(guint64)##' -e 's#[a-z]*-cpuload=(uint)##g' -e 's#time=(guint64)##' -e 's#;##' -e 's#, # #g' >$tmp/cpu_proc.dat
40 grep -o "thread-rusage,.*" $log | cut -c35- | sed -e 's#ts=(guint64)##' -e 's#thread-id=(uint)##g' -e 's#[a-z]*-cpuload=(uint)##g' -e 's#time=(guint64)##' -e 's#;##' -e 's#, # #g' >$tmp/cpu_threads.dat
41 ( cd $tmp; awk -F" " '{ print $2, $3, $4, $5 >"cpu_thread."$1".dat" }' cpu_threads.dat )
44 # http://en.wikipedia.org/wiki/Paper_size
46 a3) page_with="29.7 cm";page_height="42.0 cm";;
47 a4) page_with="21.0 cm";page_height="29.7 cm";;
49 # http://www.gnuplot.info/docs/node341.html (terminal options)
51 # this doesn't like fonts
52 png) echo "set term png truecolor font \"Sans,7\" size $plot_width,$plot_height";;
53 # pdf makes a new page for each plot :/
54 pdf) echo "set term pdf color font \"Sans,7\" size $page_with,$page_height";;
55 ps) echo "set term postscript portrait color solid \"Sans\" 7 size $page_with,$page_height";;
56 svg) echo "set term svg size $plot_width,$plot_height font \"Sans,7\"";;
59 set output '$base.cpu.$format'
60 set xlabel "Time (ns)"
61 set ylabel "Per-Mille"
64 '$tmp/cpu_proc.dat' using 1:2 with lines title 'avg cpu', \\
65 '' using 1:3 with lines title 'cur cpu'
67 set output '$base.thread.$format'
68 set xlabel "Time (ns)"
69 set ylabel "Per-Mille"
73 for file in $tmp/cpu_thread.*.dat ; do
74 ct=`cat $file | wc -l`
75 if [ $ct -lt 100 ]; then
78 id=`echo $file | sed 's#.*cpu_thread.\([0-9]*\).dat#\1#'`
80 '$file' using 1:2 with lines title '$id avg cpu', \\
81 '' using 1:3 with lines title '$id cur cpu', \\