gst-plot-traces.sh: add a script to plot gst-tracer graphs
[platform/upstream/gstreamer.git] / scripts / gst-plot-traces.sh
1 #!/bin/bash
2 # dumps a gnuplot script to stdout that plot of the given log
3
4
5 usage="\
6 Usage:$0 [--title=<title>] [--log=<log>] [--format={png,pdf,ps,svg}] [--pagesize={a3,a4}]| gnuplot"
7
8 # default options
9 title="GStreamer trace"
10 log="trace.log"
11 format="png"
12 pagesize="a3"
13
14 # process commandline options
15 # @todo: add support for single letter options
16 while true; do
17   case "X$1" in
18     X--version) echo "0.1"; exit 0;;
19     X--help) echo "$usage"; exit 0;;
20     X--title=*) title=`echo $1 | sed s/.*=//`; shift;;
21     X--log=*) log=`echo $1 | sed s/.*=//`; shift;;
22     X--format=*) format=`echo $1 | sed s/.*=//`; shift;;
23     X--pagesize=*) pagesize=`echo $1 | sed s/.*=//`; shift;;
24     X--*) shift;;
25     X*) break;;
26   esac
27 done
28
29 tmp=`mktemp -d`
30
31 plot_width=1600
32 plot_height=1200
33
34 # filter log
35 grep "proc-rusage," $log | cut -c154- | sed -e 's#ts=(guint64)##' -e 's#[a-z]*-cpuload=(uint)##g' -e 's#time=(guint64)##' -e 's#;##' -e 's#, # #g' | sort -n >$tmp/cpu_proc.dat
36 grep "thread-rusage," $log | cut -c156- | 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' | sort -n >$tmp/cpu_threads.dat
37 ( cd $tmp; awk -F" " '{ print $1, $3, $4, $5 >"cpu_thread."$2".dat" }' cpu_threads.dat )
38
39 # configure output
40 # http://en.wikipedia.org/wiki/Paper_size
41 case $pagesize in
42   a3) page_with="29.7 cm";page_height="42.0 cm";;
43   a4) page_with="21.0 cm";page_height="29.7 cm";;
44 esac
45 # http://www.gnuplot.info/docs/node341.html (terminal options)
46 case $format in
47   # this doen't like fonts
48   png) echo "set term png truecolor font \"Sans,7\" size $plot_width,$plot_height";;
49   # pdf makes a new page for each plot :/
50   pdf) echo "set term pdf color font \"Sans,7\" size $page_with,$page_height";;
51   ps) echo "set term postscript portrait color solid \"Sans\" 7 size $page_with,$page_height";;
52   svg) echo "set term svg size $plot_width,$plot_height font \"Sans,7\"";;
53 esac
54 cat <<EOF
55 set output '$log.cpu.$format'
56 set xlabel "Time (ns)"
57 set ylabel "Per-Mille"
58 set grid
59 plot \\
60   '$tmp/cpu_proc.dat' using 1:2 with lines title 'avg cpu', \\
61   '' using 1:3 with lines title 'cur cpu'
62
63 set output '$log.thread.$format'
64 set xlabel "Time (ns)"
65 set ylabel "Per-Mille"
66 set grid
67 plot \\
68 EOF
69 for file in $tmp/cpu_thread.*.dat ; do
70   ct=`cat $file | wc -l`
71   if [ $ct -lt 100 ]; then
72     continue
73   fi
74   id=`echo $file | sed 's#.*cpu_thread.\([0-9]*\).dat#\1#'`
75   cat <<EOF
76   '$file' using 1:2 with lines title '$id avg cpu', \\
77   '' using 1:3 with lines title '$id  cur cpu', \\
78 EOF
79 done
80 cat <<EOF
81
82 EOF
83