Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
| 3 # | |
| 4 # Use of this source code is governed by a BSD-style license | |
| 5 # that can be found in the LICENSE file in the root of the source | |
| 6 # tree. An additional intellectual property rights grant can be found | |
| 7 # in the file PATENTS. All contributing project authors may | |
| 8 # be found in the AUTHORS file in the root of the source tree. | |
| 9 | |
| 10 # This script is used to plot simulation dynamics. | |
| 11 # Able to plot each flow separately. Other plot boxes can be added, | |
| 12 # currently one for Throughput, one for Latency and one for Packet Loss. | |
| 13 | |
| 14 import matplotlib | |
| 15 import matplotlib.pyplot as plt | |
| 16 import math | |
| 17 import numpy | |
| 18 import re | |
| 19 import sys | |
| 20 import pprint | |
| 21 | |
| 22 | |
| 23 class Variable: | |
| 24 def __init__(self, variable): | |
| 25 self._ID = variable[0] | |
| 26 self._xlabel = variable[1] | |
| 27 self._ylabel = variable[2] | |
| 28 self._subplot = variable[3] | |
| 29 self._y_max = variable[4] | |
| 30 self._samples = dict() | |
| 31 | |
| 32 def getID(self): | |
| 33 return self._ID | |
| 34 | |
| 35 def getXLabel(self): | |
| 36 return self._xlabel | |
| 37 | |
| 38 def getYLabel(self): | |
| 39 return self._ylabel | |
| 40 | |
| 41 def getSubplot(self): | |
| 42 return self._subplot | |
| 43 | |
| 44 def getYMax(self): | |
| 45 return self._y_max | |
| 46 | |
| 47 def getNumberOfFlows(self): | |
| 48 return len(self._samples) | |
| 49 | |
| 50 | |
| 51 def addSample(self, line): | |
| 52 groups = re.search(r'/\d_(\w+)#\d@(\w*)', line) | |
| 53 var_name = groups.group(1) | |
| 54 alg_name = groups.group(2) | |
| 55 | |
| 56 if alg_name not in self._samples.keys(): | |
| 57 self._samples[alg_name] = {} | |
| 58 | |
| 59 if var_name not in self._samples[alg_name].keys(): | |
| 60 self._samples[alg_name][var_name] = [] | |
| 61 | |
| 62 sample = re.search(r'(\d+\.\d+)\t([-]?\d+\.\d+)', line) | |
| 63 s = (sample.group(1),sample.group(2)) | |
| 64 self._samples[alg_name][var_name].append(s) | |
| 65 | |
| 66 def plotVar(v, ax, show_legend, show_x_label): | |
| 67 if show_x_label: | |
| 68 ax.set_xlabel(v.getXLabel(), fontsize='large') | |
| 69 ax.set_ylabel(v.getYLabel(), fontsize='large') | |
| 70 | |
| 71 for alg in v._samples.keys(): | |
| 72 print "alg %s: %d" % (alg, len(v._samples[alg])) | |
|
stefan-webrtc
2015/07/21 12:16:37
Can probably be moved
magalhaesc
2015/07/21 17:05:03
Done.
| |
| 73 i = 1 | |
| 74 for series in v._samples[alg].keys(): | |
| 75 x = [sample[0] for sample in v._samples[alg][series]] | |
| 76 y = [sample[1] for sample in v._samples[alg][series]] | |
| 77 x = numpy.array(x) | |
| 78 y = numpy.array(y) | |
| 79 line = plt.plot(x, y, label=alg, linewidth=4.0) | |
| 80 colormap = {'Available1':'#AAAAAA', | |
| 81 'Available2':'#AAAAAA', | |
| 82 'GCC1':'#80D000', | |
| 83 'GCC2':'#008000', | |
| 84 'GCC3':'#00F000', | |
| 85 'GCC4':'#00B000', | |
| 86 'GCC5':'#70B020', | |
| 87 'NADA1':'#0000AA', | |
| 88 'NADA2':'#A0A0FF', | |
| 89 'NADA3':'#0000FF', | |
| 90 'NADA4':'#C0A0FF', | |
| 91 'NADA5':'#9060B0', | |
| 92 'TCP1':'#AAAAAA', | |
| 93 'TCP2':'#AAAAAA', | |
| 94 'TCP3':'#AAAAAA', | |
| 95 'TCP4':'#AAAAAA', | |
| 96 'TCP5':'#AAAAAA', | |
| 97 'TCP6':'#AAAAAA', | |
| 98 'TCP7':'#AAAAAA', | |
| 99 'TCP8':'#AAAAAA', | |
| 100 'TCP9':'#AAAAAA', | |
| 101 'TCP10':'#AAAAAA',} | |
| 102 | |
| 103 plt.setp(line, color=colormap[alg + str(i)]) | |
| 104 if alg.startswith('Available'): | |
| 105 plt.setp(line, linestyle='--') | |
| 106 plt.grid(True) | |
| 107 | |
| 108 x1, x2, y1, y2 = plt.axis() | |
| 109 if v.getYMax() >= 0: | |
| 110 y2 = v.getYMax() | |
| 111 plt.axis((0, x2, 0, y2)) | |
| 112 i += 1 | |
| 113 | |
| 114 if show_legend: | |
| 115 legend = plt.legend(loc='upper right', shadow=True, fontsize='large', ncol =len(v._samples)) | |
| 116 | |
| 117 if __name__ == '__main__': | |
| 118 | |
| 119 variables = [ | |
| 120 #id, xlabel, ylabel, subplot | |
| 121 #('Send_estimate', "Time (s)", "Throughput (kbps)", 1, 4000), | |
| 122 ('Throughput_kbps', "Time (s)", "Throughput (kbps)", 1, 4000), | |
| 123 ('Delay_ms', "Time (s)", "One-way Delay(ms)", 2, 500), | |
| 124 ('Packet_Loss', "Time (s)", "Packet Loss Ratio", 3, 1.0), | |
| 125 #('threshold', "Time (s)", "Threshold (ms)", 3), | |
| 126 #('offset', "Time (s)", "Offset (ms)", 3), | |
|
stefan-webrtc
2015/07/21 12:16:37
This should be cleaned up
magalhaesc
2015/07/21 17:05:03
Done.
| |
| 127 ] | |
| 128 | |
| 129 var = [] | |
| 130 | |
| 131 # Create objects. | |
| 132 for variable in variables: | |
| 133 var.append(Variable(variable)) | |
| 134 | |
| 135 # Add samples to the objects. | |
| 136 for line in sys.stdin: | |
| 137 if line.startswith("[ RUN ]"): | |
| 138 test_name = re.search('\.(\w+)', line).group(1) | |
| 139 if line.startswith("PLOT"): | |
| 140 for v in var: | |
| 141 if v.getID() in line: | |
| 142 v.addSample(line) | |
| 143 | |
| 144 matplotlib.rcParams.update({'font.size': 20}) | |
| 145 | |
| 146 # Plot variables. | |
| 147 fig = plt.figure() | |
| 148 #fig.suptitle(test_name) | |
|
stefan-webrtc
2015/07/21 12:16:37
Remove?
magalhaesc
2015/07/21 17:05:02
Done.
| |
| 149 | |
| 150 print "Plotting \"%s\"" % (test_name) | |
| 151 | |
| 152 # Offest and threshold on the same plot. | |
| 153 n = var[-1].getSubplot() | |
| 154 i = 0 | |
| 155 for v in var: | |
| 156 ax = fig.add_subplot(n, 1, v.getSubplot()) | |
| 157 plotVar(v, ax, i == 0, i == n - 1) | |
| 158 i += 1 | |
| 159 | |
| 160 #fig.savefig(test_name+".jpg") | |
| 161 plt.show() | |
| 162 | |
| OLD | NEW |