-
Notifications
You must be signed in to change notification settings - Fork 20
/
plot_queue.py
159 lines (134 loc) · 4.42 KB
/
plot_queue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'''
Plot queue occupancy over time
'''
from helper import *
import plot_defaults
plot_defaults.quarter_size()
from matplotlib.ticker import MaxNLocator
from pylab import figure
parser = argparse.ArgumentParser()
parser.add_argument('--files', '-f',
help="Queue timeseries output to one plot",
required=True,
action="store",
nargs='+',
dest="files")
parser.add_argument('--maxy',
help="Max mbps on y-axis..",
type=int,
default=1000,
action="store",
dest="maxy")
parser.add_argument('--miny',
help="Min mbps on y-axis..",
type=int,
default=0,
action="store",
dest="miny")
parser.add_argument('--legend', '-l',
help="Legend to use if there are multiple plots. File names used as default.",
action="store",
nargs="+",
default=None,
dest="legend")
parser.add_argument('--out', '-o',
help="Output png file for the plot.",
default=None, # Will show the plot
dest="out")
parser.add_argument('-s', '--summarise',
help="Summarise the time series plot (boxplot). First 10 and last 10 values are ignored.",
default=False,
dest="summarise",
action="store_true")
parser.add_argument('--cdf',
help="Plot CDF of queue timeseries (first 10 and last 10 values are ignored)",
default=False,
dest="cdf",
action="store_true")
parser.add_argument('--labels',
help="Labels for x-axis if summarising; defaults to file names",
required=False,
default=[],
nargs="+",
dest="labels")
parser.add_argument('--every',
help="If the plot has a lot of data points, plot one every EVERY (x,y) point (default 1).",
default=1,
type=int)
args = parser.parse_args()
if args.labels is None:
args.labels = args.files
if args.legend is None:
args.legend = []
for file in args.files:
args.legend.append(file)
to_plot=[]
def get_style(i):
if i == 0:
return {'color': 'red'}
else:
return {'color': 'black', 'ls': '-.'}
print args.files
fig = figure()
ax = fig.add_subplot(111)
for i, f in enumerate(args.files):
data = read_list(f)
xaxis = map(float, col(0, data))
start_time = xaxis[0]
xaxis = map(lambda x: x - start_time, xaxis)
qlens = map(float, col(1, data))
if args.summarise or args.cdf:
to_plot.append(qlens[10:-10])
else:
xaxis = xaxis[::args.every]
qlens = qlens[::args.every]
ax.plot(xaxis, qlens, label=args.legend[i], lw=2, **get_style(i))
ax.xaxis.set_major_locator(MaxNLocator(4))
#plt.title("Queue sizes")
plt.title("")
plt.ylabel("Packets")
plt.grid(True)
#yaxis = range(0, 1101, 50)
#ylabels = map(lambda y: str(y) if y%100==0 else '', yaxis)
#plt.yticks(yaxis, ylabels)
#plt.ylim((0,1100))
plt.ylim((args.miny,args.maxy))
if args.summarise:
plt.xlabel("Link Rates")
plt.boxplot(to_plot)
xaxis = range(1, 1+len(args.files))
plt.xticks(xaxis, args.labels)
for x in xaxis:
y = pc99(to_plot[x-1])
print x, y
if x == 1:
s = '99pc: %d' % y
offset = (-20,20)
else:
s = str(y)
offset = (-10, 20)
plt.annotate(s, (x,y+1), xycoords='data',
xytext=offset, textcoords='offset points',
arrowprops=dict(arrowstyle="->"))
elif args.cdf:
fig = figure()
ax = fig.add_subplot(111)
for i,data in enumerate(to_plot):
xs, ys = cdf(map(int, data))
ax.plot(xs, ys, label=args.legend[i], lw=2, **get_style(i))
plt.ylabel("Fraction")
plt.xlabel("Packets")
plt.ylim((0, 1.0))
plt.legend(args.legend, loc="upper left")
plt.title("")
ax.xaxis.set_major_locator(MaxNLocator(4))
else:
plt.xlabel("Seconds")
if args.legend:
plt.legend(args.legend, loc="upper left")
else:
plt.legend(args.files)
if args.out:
plt.savefig(args.out)
else:
plt.show()