-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
141 lines (121 loc) · 4.65 KB
/
runner.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
import matplotlib.pyplot as plt
import os
import numpy as np
import time
class Parser:
def __init__(self, filepath="output.txt") -> None:
self.filepath = os.path.join(
os.path.dirname(__file__), 'client', filepath)
def check(self):
if not os.path.exists(self.filepath):
raise Exception(f"File {self.filepath} does not exits.")
def openigFile(self) -> list:
self.check()
file = open(self.filepath)
lines = file.readlines()
file.close()
return lines
def execute(self):
lines = self.openigFile()
lines = lines[1:]
windowSize, times = str(lines[-1]).split(',')
print('I*******************I')
print(times[:-2])
print('I*******************I')
return int(windowSize), float(times[:-2])
class Drawer:
def __init__(self) -> None:
self.XDATA = []
self.YDATA = []
def manageData(self):
self.XDATA = np.array([self.XDATA])
self.YDATA = np.array([self.YDATA])
return np.hstack([np.reshape(self.XDATA, (-1, 1)), np.reshape(self.YDATA, (-1, 1))])
def drawingBytes(self):
DATA = self.manageData()
DATA = DATA[DATA[:, 0].argsort()]
fig2 = plt.figure(2, figsize=(10, 8))
plt.plot(DATA[:, 0], DATA[:, 1], 'k-')
plt.scatter(DATA[:, 0], DATA[:, 1], c='r',
marker='o', s=100, alpha=0.6, zorder=100)
plt.bar(DATA[:, 0], DATA[:, 1], color="orange", width=2,
linewidth=1.5, edgecolor=np.random.random((255, 3)))
plt.xlabel(r'$Frame$ $Bytes$')
plt.ylabel(r'$Time$ $In$ $Milliseconds$')
# plt.xticks(DATA[:, 0])
print(np.argmin(DATA[:, 0]))
plt.axis([DATA[np.argmin(DATA[:, 0]), 0] - 10, DATA[np.argmax(DATA[:, 0]), 0] +
10, DATA[np.argmin(DATA[:, 1]), 1] - 5, DATA[np.argmax(DATA[:, 1]), 1] + 5])
# plt.yticks(DATA[:, 1])
# plt.yscale()
plt.grid(True)
fig2.savefig("DifferentBytes.png")
fig2.show()
def setDataForBytes(self):
import glob
parser = Parser()
files = glob.glob(os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'output_different_bytes', '*.txt'), recursive=True)
for file in files:
parser.filepath = file
b, times = parser.execute()
self.XDATA.append(b)
self.YDATA.append(times)
def drawWindowSizes(self):
DATA = self.manageData()
fig1 = plt.figure(1, figsize=(10, 8))
plt.plot(DATA[:, 0], DATA[:, 1], 'r-')
plt.scatter(DATA[:, 0], DATA[:, 1], c='b',
marker="o", s=100, zorder=100)
plt.bar(DATA[:, 0], DATA[:, 1], width=0.9, color="orange")
plt.xticks(DATA[:, 0])
plt.yticks(DATA[:, 1])
plt.xlabel(r"$Window Sizes$")
plt.ylabel(r"$Times$ $In$ $milliseconds$")
fig1.savefig("windows.png")
plt.grid(True)
fig1.show()
def execute(self):
self.drawWindowSizes()
self.XDATA, self.YDATA = [], []
# self.setDataForBytes()
# print(self.XDATA, self.YDATA)
self.drawingBytes()
plt.show()
class Executor:
def __init__(self, windowSizes=[8, 32, 64, 128]) -> None:
self.windowSizes = windowSizes
self.serverPath = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'server', 'server.go')
self.clientPath = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'client', 'client.go')
print(self.serverPath)
self.parser = Parser()
self.drawer = Drawer()
def executor(self, folderpath, filepath, windowSize=8):
import subprocess
proc = subprocess.Popen(
f"cd {folderpath} && go run {filepath} {windowSize}", shell=True)
return proc
def execute(self):
proc, proc1 = None, None
try:
for size in self.windowSizes:
print(f"starting the window size: {size}")
proc = self.executor(os.path.dirname(
self.serverPath), self.serverPath, size)
time.sleep(.5)
proc1 = self.executor(os.path.dirname(
self.clientPath), self.clientPath, size)
proc1.wait()
proc.wait()
print(f"end the window size: {size}")
windowsize, times = self.parser.execute()
self.drawer.XDATA.append(windowsize)
self.drawer.YDATA.append(times)
except:
proc.kill()
proc1.kill()
self.drawer.execute()
if __name__ == '__main__':
Executor().execute()