1#!/bin/bash
2
3# Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
4#
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
7# tree. An additional intellectual property rights grant can be found
8# in the file PATENTS.  All contributing project authors may
9# be found in the AUTHORS file in the root of the source tree.
10
11# To set up in e.g. Eclipse, run a separate shell and pipe the output from the
12# test into this script.
13#
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
16# --gtest_filter=*BweTest* | [trunk_path]/webrtc/modules/
17# remote_bitrate_estimator/bwe_plot.
18
19# bwe_plot.sh has a single y axis and a dual y axis mode. If any line specifies
20# a an axis by ending with "#<axis number (1 or 2)>" two y axis will be used,
21# the first will be assumed to represent bitrate (in kbps) and the second will
22# be assumed to represent time deltas (in ms).
23
24log=$(</dev/stdin)
25
26function gen_gnuplot_input {
27  colors=(a7001f 0a60c2 b2582b 21a66c d6604d 4393c3 f4a582 92c5de edcbb7 b1c5d0)
28  data_sets=$(echo "$log" | grep "^PLOT" | cut -f 2 | sort | uniq)
29  linetypes=($(echo "$data_sets" | cut -d '#' -f 2 | cut -d ' ' -f 1))
30  echo -n "reset; "
31  echo -n "set terminal wxt size 1440,900 font \"Arial,9\"; "
32  echo -n "set xlabel \"Seconds\"; "
33  if [ -n $linetypes ]; then
34    echo -n "set ylabel 'bitrate (kbps)';"
35    echo -n "set ytics nomirror;"
36    echo -n "set y2label 'time delta (ms)';"
37    echo -n "set y2tics nomirror;"
38  fi
39  echo -n "plot "
40  i=0
41  for set in $data_sets ; do
42    (( i++ )) && echo -n ","
43    echo -n "'-' with "
44    echo -n "linespoints "
45    echo -n "ps 0.5 "
46    echo -n "lc rgbcolor \"#${colors[$(($i % 10))]}\" "
47    if [ -n ${linetypes[$i - 1]} ]; then
48      echo -n "axes x1y${linetypes[$i - 1]} "
49    elif [ -n $linestypes ]; then
50      # If no line type is specified, but line types are used, we will default
51      # to the bitrate axis.
52      echo -n "axes x1y1 "
53    fi
54    echo -n "title \"$set\" "
55  done
56  echo
57  for set in $data_sets ; do
58    echo "$log" | grep "^PLOT.$set" | cut -f 3,4
59    echo "e"
60  done
61}
62
63gen_gnuplot_input "$log" | gnuplot -persist
64