OLD | NEW |
---|---|
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license | 5 # Use of this source code is governed by a BSD-style license |
6 # that can be found in the LICENSE file in the root of the source | 6 # that can be found in the LICENSE file in the root of the source |
7 # tree. An additional intellectual property rights grant can be found | 7 # tree. An additional intellectual property rights grant can be found |
8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
10 | 10 |
11 # To set up in e.g. Eclipse, run a separate shell and pipe the output from the | 11 # To set up in e.g. Eclipse, run a separate shell and pipe the output from the |
12 # test into this script. | 12 # test into this script. |
13 # | 13 # |
14 # In Eclipse, that amounts to creating a Run Configuration which starts | 14 # In Eclipse, that amounts to creating a Run Configuration which starts |
15 # "/bin/bash" with the arguments "-c [trunk_path]/out/Debug/modules_unittests | 15 # "/bin/bash" with the arguments "-c [trunk_path]/out/Debug/modules_unittests |
16 # --gtest_filter=*BweTest* | [trunk_path]/webrtc/modules/ | 16 # --gtest_filter=*BweTest* | [trunk_path]/webrtc/modules/ |
17 # remote_bitrate_estimator/bwe_plot. | 17 # remote_bitrate_estimator/bwe_plot. |
18 | 18 |
19 # bwe_plot.sh supports multiple figures (windows), the figure is specified as an | 19 # bwe_plot.sh supports multiple figures (windows), the figure is specified as an |
20 # identifier at the first argument after the PLOT command. Each figure has a | 20 # identifier at the first argument after the PLOT command. Each figure has a |
21 # single y axis and a dual y axis mode. If any line specifies an axis by ending | 21 # single y axis and a dual y axis mode. If any line specifies an axis by ending |
22 # with "#<axis number (1 or 2)>" two y axis will be used, the first will be | 22 # with "#<axis number (1 or 2)>" two y axis will be used, the first will be |
23 # assumed to represent bitrate (in kbps) and the second will be assumed to | 23 # assumed to represent bitrate (in kbps) and the second will be assumed to |
24 # represent time deltas (in ms). | 24 # represent time deltas (in ms). |
25 | 25 |
26 log=$(</dev/stdin) | 26 log=$(</dev/stdin) |
27 | 27 |
28 # Plot dynamics. | |
28 function gen_gnuplot_input { | 29 function gen_gnuplot_input { |
29 colors=(a7001f 0a60c2 b2582b 21a66c d6604d 4393c3 f4a582 92c5de edcbb7 b1c5d0) | 30 colors=(a7001f 0a60c2 b2582b 21a66c d6604d 4393c3 f4a582 92c5de edcbb7 b1c5d0) |
30 plots=$(echo "$log" | grep "^PLOT") | 31 plots=$(echo "$log" | grep "^PLOT") |
31 figures=($(echo "$plots" | cut -f 2 | sort | uniq)) | 32 figures=($(echo "$plots" | cut -f 2 | sort | uniq)) |
32 | 33 |
33 for figure in "${figures[@]}" ; do | 34 for figure in "${figures[@]}" ; do |
34 data_sets=$(echo "$plots" | grep "^PLOT.$figure" | cut -f 3 | sort | uniq) | 35 data_sets=$(echo "$plots" | grep "^PLOT.$figure" | cut -f 3 | sort | uniq) |
35 linetypes=($(echo "$data_sets" | grep "#" | cut -d '#' -f 2 | \ | 36 linetypes=($(echo "$data_sets" | grep "#" | cut -d '#' -f 2 | \ |
36 cut -d ' ' -f 1)) | 37 cut -d ' ' -f 1)) |
37 echo -n "reset; " | 38 echo -n "reset; " |
38 echo -n "set terminal wxt $figure size 1440,900 font \"Arial,9\"; " | 39 echo -n "set terminal wxt $figure size 1440,900 font \"Arial,9\"; " |
39 echo -n "set xlabel \"Seconds\"; " | 40 echo -n "set xlabel \"Seconds\"; " |
(...skipping 22 matching lines...) Expand all Loading... | |
62 fi | 63 fi |
63 echo -n "title \"$set\" " | 64 echo -n "title \"$set\" " |
64 done | 65 done |
65 echo | 66 echo |
66 for set in $data_sets ; do | 67 for set in $data_sets ; do |
67 echo "$log" | grep "^PLOT.$figure.$set" | cut -f 4,5 | 68 echo "$log" | grep "^PLOT.$figure.$set" | cut -f 4,5 |
68 echo "e" | 69 echo "e" |
69 done | 70 done |
70 done | 71 done |
71 } | 72 } |
72 | |
73 gen_gnuplot_input | gnuplot -persist | 73 gen_gnuplot_input | gnuplot -persist |
74 | |
75 | |
76 # Plot histograms. | |
77 function gen_gnuplot_bar_input { | |
78 x_start=1 | |
79 x_end=3.75 | |
80 bars=$(echo "$log" | grep "BAR") | |
81 | |
82 labels=$(echo "$log" | grep "^LABEL") | |
83 figures=($(echo "$bars" | cut -f 2 | sort | uniq)) | |
84 | |
85 echo "reset" | |
86 | |
87 echo "set title font 'Verdana,22'" | |
88 echo "set xtics font 'Verdana,24'" | |
89 echo "set ytics font 'Verdana,14'" | |
90 echo "set ylabel font 'Verdana,16'" | |
91 | |
92 echo "set xrange[$x_start:$x_end]" | |
93 echo "set style fill solid 0.5" | |
94 echo "set style fill solid border -1" | |
95 | |
96 ydist=11 # Used to correctly offset the y label. | |
97 for figure in "${figures[@]}" ; do | |
98 | |
99 echo "set terminal wxt $figure size 440,440 dashed" | |
100 echo "set ylabel offset $ydist, -3" | |
101 ((ydist--)) | |
102 | |
103 title=$(echo "$labels" | grep "^LABEL.$figure" | cut -f 3 | \ | |
104 head -n 1 | sed 's/_/ /g') | |
105 y_label=$(echo "$labels" | grep "^LABEL.$figure" | cut -f 4 | \ | |
106 head -n 1 | sed 's/_/ /g') | |
107 | |
108 # RMCAT flows. | |
109 num_flows=$(echo "$labels" | grep "^LABEL.$figure" | cut -f 5 | \ | |
110 head -n 1) | |
111 | |
112 # RMCAT algorithm 1. | |
113 x_label_1=$(echo "$log" | grep "BAR.$figure" | cut -f 3 | sed 's/_/\t/g' \ | |
114 | cut -f 1 | sort | uniq | head -n 1 ) | |
115 | |
116 # RMCAT algorithm 2. | |
117 x_label_2=$(echo "$log" | grep "BAR.$figure" | cut -f 3 | sed 's/_/\t/g' \ | |
118 | cut -f 1 | sort | uniq | sed -n 2p) | |
119 | |
120 x_labels="('$x_label_1' 2, '$x_label_2' 3)" | |
121 tcp_flow=false | |
122 | |
123 tcp_space=0.2 # Extra horizontal space between bars. | |
124 | |
125 # Parse labels if there are other flows in addition to RMCAT ones. | |
126 IFS='x' read -ra split_label_1 <<< "$x_label_1" | |
127 | |
128 if (( ${#split_label_1[@]} > "1" )); then | |
129 tcp_flow=true | |
130 box_width=$(echo "(1.0-$tcp_space/2)/$num_flows" | bc -l) | |
131 echo "set xtics font 'Verdana,16'" | |
132 x_labels="(" | |
133 delimiter="" | |
134 abscissa=$(echo $x_start + 0.5 + 0.5*$box_width | bc) | |
135 for label in "${split_label_1[@]}" ; do | |
136 x_labels+="$delimiter'$label' $abscissa" | |
137 abscissa=$(echo $abscissa + $box_width | bc) | |
138 delimiter=", " | |
139 done | |
140 abscissa=$(echo $abscissa + $tcp_space | bc) | |
141 IFS='x' read -ra split_label_2 <<< "$x_label_2" | |
142 for label in "${split_label_2[@]}" ; do | |
143 x_labels+="$delimiter'$label' $abscissa" | |
144 abscissa=$(echo $abscissa + $box_width | bc) | |
145 done | |
146 x_labels="$x_labels)" | |
147 else | |
148 box_width=$(echo 1.0/$num_flows | bc -l) | |
149 fi | |
150 | |
151 echo "set boxwidth $box_width" | |
152 | |
153 # Plots can be directly exported to image files. | |
154 file_name=$(echo "$labels" | grep "^LABEL.$figure" | cut -f 5 | head -n 1) | |
155 | |
156 y_max=0 # Used to scale the plot properly. | |
157 | |
158 # Since only the optimal bitrate for the first flow is being ploted, | |
159 # consider only this one for scalling purposes. | |
160 data_sets=$(echo "$bars" | grep "LIMITERRORBAR.$figure" | cut -f 3 | \ | |
161 sed 's/_/\t/g' | cut -f 1 | sort | uniq) | |
162 | |
163 if (( ${#data_sets} > "0" )); then | |
164 for set in $data_sets ; do | |
165 y=$(echo "$bars" | grep "LIMITERRORBAR.$figure.$set" | cut -f 8 | \ | |
166 head -n 1) | |
167 if (( $(bc <<< "$y > $y_max") == 1 )); then | |
168 y_max=$y | |
169 fi | |
170 done | |
171 fi | |
172 | |
173 data_sets=$(echo "$bars" | grep "ERRORBAR.$figure" | cut -f 3 | sort | uniq) | |
174 if (( ${#data_sets} > "0" )); then | |
175 for set in $data_sets ; do | |
176 y=$(echo "$bars" | grep "ERRORBAR.$figure.$set" | cut -f 6 | head -n 1) | |
177 if (( $(bc <<< "$y > $y_max") == 1 )) ; then | |
178 y_max=$y | |
179 fi | |
180 done | |
181 fi | |
182 | |
183 data_sets=$(echo "$bars" | grep "BAR.$figure" | cut -f 3 | sort | uniq) | |
184 | |
185 for set in $data_sets ; do | |
186 y=$(echo "$bars" | grep "BAR.$figure.$set" | cut -f 4 | head -n 1) | |
187 if (( $(bc <<< "$y > $y_max") == 1 )) ; then | |
188 y_max=$y | |
189 fi | |
190 done | |
191 | |
192 y_max=$(echo $y_max*1.1 | bc) | |
193 | |
194 # Scale all latency plots with the same vertical scale. | |
195 delay_figure=5 | |
196 if (( $figure==$delay_figure )) ; then | |
197 y_max=250 | |
198 fi | |
199 | |
200 echo "set ylabel \"$y_label\"" | |
201 echo "set yrange[0:$y_max]" | |
202 | |
203 echo "set multiplot" | |
204 | |
205 # Plot bars. | |
206 data_sets=$(echo "$bars" | grep "BAR.$figure" | cut -f 3 | sort | uniq) | |
207 | |
208 echo "set xtics $x_labels" | |
209 echo "plot '-' using 1:4:2 with boxes lc variable notitle" | |
210 | |
211 echo | |
212 | |
213 color=11 # Green. | |
214 x_bar=$(echo $x_start + 0.5 + 0.5*$box_width | bc) | |
215 for set in $data_sets ; do | |
216 echo -n "$x_bar $color " | |
217 echo "$bars" | grep "BAR.$figure.$set" | cut -f 3,4 | |
218 | |
219 # Add extra space if TCP flows are being plotted. | |
220 if $tcp_flow && \ | |
221 (( $(bc <<< "$x_bar < $x_start + 1.5 - 0.5*$tcp_space") == 1 )) && \ | |
222 (( $(bc <<< "$x_bar + $box_width > $x_start + 1.5 + 0.5*$tcp_space") \ | |
223 == 1 )); then | |
224 x_bar=$(echo $x_bar + $tcp_space | bc) | |
225 fi | |
226 | |
227 x_bar=$(echo $x_bar + $box_width | bc) | |
228 | |
229 if (( $(bc <<< "$x_bar > 2.5") == 1 )) ; then | |
230 color=12 # Blue. | |
231 fi | |
232 # Different bar color for TCP flows: | |
233 if $tcp_flow && \ | |
234 (( $(bc <<< "(100*$x_bar)%100 < 50") == 1 )) | |
235 then | |
236 color=18 # Gray. | |
stefan-webrtc
2015/07/21 12:16:36
Two spaces before a comment. See other comments as
magalhaesc
2015/07/21 17:05:02
Done.
| |
237 fi | |
238 done | |
239 echo "e" | |
240 | |
241 # Plot Baseline bars, e.g. one-way path delay on latency plots. | |
242 data_sets=$(echo "$log" | grep "BASELINE.$figure" | cut -f 3 | sort | uniq) | |
243 | |
244 echo "set xtics $x_labels" | |
245 echo "plot '-' using 1:4:2 with boxes lc variable notitle" | |
246 | |
247 echo | |
248 | |
249 color=18 # Gray. | |
250 x_bar=$(echo $x_start + 0.5 + 0.5*$box_width | bc) | |
251 for set in $data_sets ; do | |
252 echo -n "$x_bar $color " | |
253 echo "$log" | grep "BASELINE.$figure.$set" | cut -f 3,4 | |
254 | |
255 # Add extra space if TCP flows are being plotted. | |
256 if $tcp_flow && \ | |
257 (( $(bc <<< "$x_bar < $x_start + 1.5 - 0.5*$tcp_space") == 1 )) && \ | |
258 (( $(bc <<< "$x_bar + $box_width > $x_start + 1.5 + 0.5*$tcp_space") \ | |
259 == 1 )); then | |
260 x_bar=$(echo $x_bar + $tcp_space | bc) | |
261 fi | |
262 | |
263 x_bar=$(echo $x_bar + $box_width | bc) | |
264 | |
265 done | |
266 echo "e" | |
267 | |
268 # Plot vertical error lines, e.g. y +- sigma. | |
269 data_sets=$(echo "$bars" | grep "ERRORBAR.$figure" | cut -f 3 | sort | uniq) | |
270 | |
271 if (( ${#data_sets} > "0" )); then | |
272 | |
273 echo "set key left" | |
274 error_title=$(echo "$bars" | grep "ERRORBAR.$figure" | cut -f 7 | \ | |
275 head -n 1 | sed 's/_/ /g') | |
276 | |
277 echo "set xtics $x_labels" | |
278 echo "plot '-' using 1:3:4:5 title '$error_title' with yerr" | |
279 | |
280 x_error_line=$(echo $x_start + 0.5 + 0.5*$box_width | bc) | |
281 for set in $data_sets ; do | |
282 echo -n "$x_error_line " | |
283 echo "$bars" | grep "ERRORBAR.$figure.$set" | cut -f 3,4,5,6 | |
284 | |
285 # Add extra space if TCP flows are being plotted. | |
286 if $tcp_flow && \ | |
287 (( $(bc <<< "$x_error_line<$x_start+1.5-0.5*$tcp_space") == 1 )) && \ | |
288 (( $(bc <<< "$x_error_line+$box_width>$x_start+1.5+0.5*$tcp_space") \ | |
stefan-webrtc
2015/07/21 12:16:36
Spaces infront of and after operators. If possible
magalhaesc
2015/07/21 17:05:02
Done.
| |
289 == 1 )); then | |
290 x_error_line=$(echo $x_error_line + $tcp_space | bc) | |
291 fi | |
292 | |
293 x_error_line=$(echo $x_error_line + $box_width | bc) | |
294 done | |
295 echo "e" | |
296 fi | |
297 | |
298 # Plot horizontal dashed lines, e.g. y = optimal bitrate. | |
299 data_sets=$(echo "$bars" | grep "LIMITERRORBAR.$figure" | cut -f 3 \ | |
300 | sort | uniq) | |
301 if (( ${#data_sets} > "0" )); then | |
302 | |
303 echo "set style line 1 lt 1 lw 3 pt 3 ps 0 linecolor rgb 'black'" | |
304 | |
305 limit_titles=$(echo "$bars" | grep "LIMITERRORBAR.$figure" | cut -f 9 \ | |
306 | sort | uniq) | |
307 | |
308 for title in $limit_titles ; do | |
309 y_max=$(echo "$bars" | grep "LIMITERRORBAR.$figure" | grep "$title" \ | |
310 | cut -f 8 | head -n 1) | |
311 | |
312 retouched_title=$(echo "$title" | sed 's/#/\t/g' | cut -f 1 \ | |
313 | sed 's/_/ /g') | |
314 | |
315 echo "set key right top" | |
316 echo "set xtics $x_labels" | |
317 echo "plot $y_max lt 7 lw 1 linecolor rgb 'black' \ | |
318 title '$retouched_title'" | |
319 done | |
320 | |
321 fi | |
322 | |
323 echo "unset multiplot" | |
324 done | |
325 } | |
326 gen_gnuplot_bar_input | gnuplot -persist | |
OLD | NEW |