gstpad: Probes that return HANDLED can reset the data info field
[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 usage="\
5 Usage:$0 [--title=<title>] [--log=<log>] [--format={png,pdf,ps,svg}] [--pagesize={a3,a4}]| gnuplot"
6
7 # default options
8 title="GStreamer trace"
9 log="trace.log"
10 format="png"
11 pagesize="a3"
12
13 # process commandline options
14 # @todo: add support for single letter options
15 while true; do
16   case "X$1" in
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;;
23     X--*) shift;;
24     X*) break;;
25   esac
26 done
27
28 tmp=`mktemp -d`
29
30 plot_width=1600
31 plot_height=1200
32
33 base=`basename "$log" ".log"`
34
35 # filter log
36 grep "TRACE" $log | grep "GST_TRACER" >$tmp/trace.log
37 log=$tmp/trace.log
38
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 )
42
43 # configure output
44 # http://en.wikipedia.org/wiki/Paper_size
45 case $pagesize in
46   a3) page_with="29.7 cm";page_height="42.0 cm";;
47   a4) page_with="21.0 cm";page_height="29.7 cm";;
48 esac
49 # http://www.gnuplot.info/docs/node341.html (terminal options)
50 case $format in
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\"";;
57 esac
58 cat <<EOF
59 set output '$base.cpu.$format'
60 set xlabel "Time (ns)"
61 set ylabel "Per-Mille"
62 set grid
63 plot \\
64   '$tmp/cpu_proc.dat' using 1:2 with lines title 'avg cpu', \\
65   '' using 1:3 with lines title 'cur cpu'
66
67 set output '$base.thread.$format'
68 set xlabel "Time (ns)"
69 set ylabel "Per-Mille"
70 set grid
71 plot \\
72 EOF
73 for file in $tmp/cpu_thread.*.dat ; do
74   ct=`cat $file | wc -l`
75   if [ $ct -lt 100 ]; then
76     continue
77   fi
78   id=`echo $file | sed 's#.*cpu_thread.\([0-9]*\).dat#\1#'`
79   cat <<EOF
80   '$file' using 1:2 with lines title '$id avg cpu', \\
81   '' using 1:3 with lines title '$id cur cpu', \\
82 EOF
83 done
84 cat <<EOF
85
86 EOF
87