]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - wme_test/plot
Merge branch 'master' of rtime.felk.cvut.cz:frescor/fwp
[frescor/fwp.git] / wme_test / plot
1 #!/usr/bin/perl -w
2 use Getopt::Std;
3 use File::Basename;
4
5 # Default values
6 $SET_TERM_TEMPLATE='set term push; set term x11 enhanced; set term wxt enhanced; set term pop';
7 $DELAY_BOUND="[]";
8 $MULTIPDF_FILENAME="all.pdf";
9
10 # Process command line options
11 my %opt;
12 getopts('bd:emnso:pPt:', \%opt);
13 $PLOT_SINGLE_EXPERIMENT = $opt{'m'} ? 0 : 1;
14 $EXPERIMENT_TITLES = $opt{'t'};
15 $PLOT_BOTH_DIRECTIONS=1 if $opt{'b'};
16 $DELAY_BOUND="[0:".$opt{'d'}."]" if $opt{'d'};
17 $SET_TERM_TEMPLATE='set term postscript color eps enhanced; set output "${FILE}.eps"' if $opt{'e'};
18 $SET_TERM_TEMPLATE='set term png enhanced; set output "${FILE}.png"' if $opt{'n'};
19 $SET_TERM_TEMPLATE='set term svg enhanced; set output "${FILE}.svg"' if $opt{'s'};
20 $MULTIPDF_FILENAME=$opt{'o'} if $opt{'o'};
21 if ($opt{'p'}) {
22     $SET_TERM_TEMPLATE='set term postscript color landscape enhanced';
23     $PDF_OUTPUT=1;
24 }
25 if ($opt{'P'}) {
26     $SET_TERM_TEMPLATE='set term postscript color landscape enhanced';
27     $MULTIPLE_GRAPHS_IN_PDF=1;
28     $GNUPLOT_CMD_FILE="plot_commands.$$";
29     unlink ${GNUPLOT_CMD_FILE};
30 }
31
32 if ($#ARGV < 0 && -r "delay_stats.dat") {$ARGV[0]="delay_stats.dat";}
33
34 # Process the data files and plot graph(s)
35 foreach $dat_file (@ARGV) {
36     ($FILE, , ) = fileparse($dat_file, (".dat"));
37
38     # Get labels from data file
39     $COMMAND="";
40     $STREAMS="";
41     open F, $dat_file;
42     while (<F>) {
43         if (/wclient.*/) {
44             $_=$&;
45             s/ -o [^ ]*//g;
46             $COMMAND="Results of: $_";
47             #$COMMAND="Results of: grep -o 'wclient.*'|sed -e 's/ -o [^ ]*//' -e 's/ [^ ]* ?$//')"
48         } elsif (/^#[^#] */) {
49             $STREAMS .= "$'";
50         }
51         
52         
53     }
54     close F;
55     $STREAMS =~ s/\n/\\n/g;
56
57     if ($MULTIPLE_GRAPHS_IN_PDF) {
58         open CMD, ">>$GNUPLOT_CMD_FILE";
59     } elsif ($PDF_OUTPUT) {
60         open CMD, "| gnuplot | ps2pdf - ${FILE}.pdf";
61     } else {
62         open CMD, "| gnuplot -persist";
63     }
64 #     close CMD;
65 #     open CMD, ">&STDOUT";
66     $SET_TERM = $SET_TERM_TEMPLATE;
67     $SET_TERM =~ s/\${FILE}/$FILE/;
68
69     print CMD qq/
70 ${SET_TERM}
71 set xlabel "Response-Time [ms]"
72 set ylabel "Cumulative % of packets"
73 set key right bottom nobox
74 set style data linespoints
75 #set logscale x
76 set grid
77 set size 1,0.8
78 unset label
79 set label "${COMMAND}" noenhanced at graph 0,1.3
80 set label "${STREAMS}" noenhanced at graph 0,1.2 font "Helvetica,9"
81 /;
82     if ($PLOT_SINGLE_EXPERIMENT) {
83         print CMD qq/
84 set style line 1  lt 1 lc rgb "red"
85 set style line 2  lt 1 lc rgb "green"
86 set style line 3  lt 1 lc rgb "blue"
87 set style line 4  lt 1 lc rgb "magenta"
88 set style line 5  lt 2 lc rgb "red" lw 2
89 set style line 6  lt 2 lc rgb "green" lw 2
90 set style line 7  lt 2 lc rgb "blue" lw 2
91 set style line 8  lt 2 lc rgb "magenta" lw 2
92 set style line 9  lt 3 lc rgb "red" lw 2
93 set style line 10 lt 3 lc rgb "green" lw 2
94 set style line 11 lt 3 lc rgb "blue" lw 2
95 set style line 12 lt 3 lc rgb "magenta" lw 2
96 /;
97         print CMD qq/plot $DELAY_BOUND [0.01:100]\\
98      "${FILE}.dat" index 0 using 1:2 with linespoints ls 1 title "AC\\\\_VO",\\
99      "${FILE}.dat" index 1 using 1:2 with linespoints ls 2 title "AC\\\\_VI",\\
100      "${FILE}.dat" index 2 using 1:2 with linespoints ls 3 title "AC\\\\_BE",\\
101      "${FILE}.dat" index 3 using 1:2 with linespoints ls 4 title "AC\\\\_BK"/;
102
103         if ($PLOT_BOTH_DIRECTIONS) {
104             print CMD qq/,\\
105      "${FILE}.dat" index 0 using 1:3 with lines ls 5  title "AC\\\\_VO cs",\\
106      "${FILE}.dat" index 1 using 1:3 with lines ls 6  title "AC\\\\_VI cs",\\
107      "${FILE}.dat" index 2 using 1:3 with lines ls 7  title "AC\\\\_BE cs",\\
108      "${FILE}.dat" index 3 using 1:3 with lines ls 8  title "AC\\\\_BK cs",\\
109      "${FILE}.dat" index 0 using 1:4 with lines ls 9  title "AC\\\\_VO sc",\\
110      "${FILE}.dat" index 1 using 1:4 with lines ls 10 title "AC\\\\_VI sc",\\
111      "${FILE}.dat" index 2 using 1:4 with lines ls 11 title "AC\\\\_BE sc",\\
112      "${FILE}.dat" index 3 using 1:4 with lines ls 12 title "AC\\\\_BK sc"
113 /;
114         } else {
115             print CMD "\n";
116         }
117     } else {
118         # Multiple experiments in a single plot
119         print CMD qq/
120 set style line 1  lt 1 lc rgb "red" lw 2
121 set style line 2  lt 1 lc rgb "green" lw 2
122 set style line 3  lt 1 lc rgb "blue" lw 2
123 set style line 4  lt 1 lc rgb "magenta" lw 2
124 set style line 5  lt 2 lc rgb "red" lw 2
125 set style line 6  lt 2 lc rgb "green" lw 2
126 set style line 7  lt 2 lc rgb "blue" lw 2
127 set style line 8  lt 2 lc rgb "magenta" lw 2
128 set style line 9  lt 3 lc rgb "red" lw 2
129 set style line 10 lt 3 lc rgb "green" lw 2
130 set style line 11 lt 3 lc rgb "blue" lw 2
131 set style line 12 lt 3 lc rgb "magenta" lw 2
132 /;
133         my ($ls1, $ls2, $ls3, $ls4) = (1,2,3,4);
134         my @titles = split(/;/, $EXPERIMENT_TITLES);
135         my $experiment = 0;
136         my $t=$titles[$experiment];
137         $t = '' unless $t;
138         print CMD qq/plot $DELAY_BOUND [0.01:100]\\
139      "${FILE}.dat" index 0 using 1:2 with lines ls $ls1 title "AC\\\\_VO $t",\\
140      "${FILE}.dat" index 1 using 1:2 with lines ls $ls2 title "AC\\\\_VI $t",\\
141      "${FILE}.dat" index 2 using 1:2 with lines ls $ls3 title "AC\\\\_BE $t",\\
142      "${FILE}.dat" index 3 using 1:2 with lines ls $ls4 title "AC\\\\_BK $t"/;
143         foreach $dat_file (@ARGV[1,2]) {
144             last if (!defined $dat_file);
145             $experiment++;
146             $t=$titles[$experiment];
147             $t = '' unless $t;
148             ($FILE, , ) = fileparse($dat_file, (".dat"));
149             ($ls1, $ls2, $ls3, $ls4) = map($_+4, ($ls1, $ls2, $ls3, $ls4));
150             print CMD qq/,\\
151      "${FILE}.dat" index 0 using 1:2 with lines ls $ls1 title "AC\\\\_VO $t",\\
152      "${FILE}.dat" index 1 using 1:2 with lines ls $ls2 title "AC\\\\_VI $t",\\
153      "${FILE}.dat" index 2 using 1:2 with lines ls $ls3 title "AC\\\\_BE $t",\\
154      "${FILE}.dat" index 3 using 1:2 with lines ls $ls4 title "AC\\\\_BK $t"/;
155         }
156         print CMD "\n";
157         last;
158     }
159
160     close CMD;
161 }
162
163 if ($MULTIPLE_GRAPHS_IN_PDF) {
164     system("gnuplot $GNUPLOT_CMD_FILE|ps2pdf - $MULTIPDF_FILENAME");
165     unlink ${GNUPLOT_CMD_FILE};
166 }