1#! /bin/sh
2#
3# (C) 2002-2003 Intel Corporation
4# I�aky P�rez-Gonz�lez <inaky.perez-gonzalez@intel.com>
5#
6# Distributed under the FSF's GNU Public License v2 or later.
7#
8# Plot the output of priority inheritance tests.
9
10# Modifs by Sebastien Decugis:
11# -> plots linespoints instead of dots
12# -> legend is outside the graph.
13# -> Change axis names and graph title
14
15FILE=$1
16TMP=$(mktemp -d)
17
18function clean_up
19{
20    rm -rf $TMP
21}
22
23function error
24{
25    cat 1>&2
26    clean_up
27    exit 1
28}
29
30trap clean_up EXIT
31
32if ! cols=$(grep "#[ ]*COLUMNS" $FILE)
33then
34    error <<EOF
35E: $FILE: Cannot locate the COLUMNS descriptor
36EOF
37fi
38cols=$(echo $cols | sed 's/#//')
39columns=$(echo $cols | awk '{print $2;}')
40count=1
41while [ $count -le $columns ]
42do
43  column[$count]=$(echo $cols | awk -vcount=$count '{print $(2 + count);}')
44  if [ -z "${column[$count]}" ]
45      then
46      column[$count]=$count;
47  fi
48  count=$(($count + 1))
49done
50
51# Set up the plot area
52count=2
53with="with linespoints"
54cat > $TMP/gnuplot.script <<EOF
55set term png
56set output "scalable.png"
57set xlabel "${column[1]}"
58set ylabel "Duration (s)"
59set key below
60set title "pthread_create scalability"
61EOF
62
63# Plot the events
64height=15
65grep "#[ ]*EVENT" $FILE | sed 's/#//' > $TMP/events
66events=$(cat $TMP/events | wc -l)
67if [ $events -gt 0 ]
68then
69    step=$(((100 - $height) / $events))
70    if [ $step -lt 5 ]
71        then
72        step=5;
73    fi
74    cat $TMP/events | while read event x text
75      do
76      if ! [ $event = "EVENT" ]
77          then
78          cat 1>&2 <<EOF
79E: Unknown event type "$event", ignoring
80EOF
81          continue;
82      fi
83      height_text=$(($height + 2))
84      echo "set arrow from $x, graph 0 to $x, graph 0.$height" >> $TMP/gnuplot.script
85      echo "set label \"$text\" at $x, graph 0.$height_text center" >> $TMP/gnuplot.script
86      height=$(($height + $step))
87    done
88fi
89
90# Plot the data
91plot_cmd="plot '$FILE' using 1:2 title \"${column[$count]}\" $with"
92count=3
93while [ $count -le $columns ]
94do
95	plot_cmd=$plot_cmd",'$FILE' using 1:$count title \"${column[$count]}\" $with"
96	count=$(($count + 1))
97done
98
99echo $plot_cmd >> $TMP/gnuplot.script
100
101#cp $TMP/gnuplot.script .
102( cat $TMP/gnuplot.script; cat ) | gnuplot
103rm -rf $TMP
104