-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIGenerator.py
130 lines (106 loc) · 4.46 KB
/
UIGenerator.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
import matplotlib.pyplot as plt
import numpy as np
import sys
from copy import deepcopy
def construct_lists_from_file(f):
server_to_start_connection = {}
server_to_done_connection = {}
if f:
line = f.readline()
servers = line.strip().split() # get all servers assuming are space-separate
lastTime = 0
server_to_start_connection = {server: [] for server in servers}
server_to_done_connection = {server: [] for server in servers}
while (f):
line = f.readline().split()
if (line == []):
break
server, time, direction = line
if direction == "start":
server_to_start_connection[server].append(float(time)*1000)
elif direction == "done":
server_to_done_connection[server].append(float(time)*1000)
lastTime = float(time)*1000
return server_to_start_connection, server_to_done_connection, lastTime
else:
exit()
# initialixe the dict
def server_to_num_request(server_to_start_connection):
# Extracting data for plotting
servers = list(server_to_start_connection.keys())
num_requests = list(server_to_start_connection.values())
# Number of requests for each server is the length of its response times
num_requests_per_server = [len(response_times) for response_times in num_requests]
# Creating a bar graph
plt.bar(servers, num_requests_per_server, color='blue')
plt.xlabel('Server')
plt.ylabel('Number of Requests')
plt.title('Number of Requests per Server')
plt.legend()
plt.savefig("num_req_per_server.png")
plt.clf()
def plot_req_over_time_count(server_to_start_connection, lastTime):
for server in sorted(server_to_start_connection):
x = [0] + server_to_start_connection[server]
y = list(range(len(x)))
if x[-1] != lastTime:
x.append(lastTime)
y.append(y[-1])
plt.plot(x, y, label = server, alpha=0.6)
plt.xlabel("time (ms)")
plt.ylabel("# of requests sent to Server over time")
plt.savefig("req_sent_over_time.png")
plt.legend()
plt.clf()
def plot_net_req_count(server_to_start_connection, server_to_done_connection, lastTime):
for server in sorted(server_to_start_connection):
sortedT = sorted(server_to_start_connection[server] + server_to_done_connection[server])
x = [0]
y = [0]
for i in range(0, len(sortedT)):
t = sortedT[i]
lastVal = y[-1]
#append the count if it's incoming and decrement for outgoing requests
if t in server_to_start_connection[server]:
x = x + [t, t]
y.append(lastVal)
y.append(lastVal + 1)
else:
x = x + [t, t]
y.append(lastVal)
y.append(lastVal - 1)
if x[-1] != lastTime:
x.append(lastTime)
y.append(y[-1])
plt.plot(x, y, label = server, alpha = 0.6, linewidth=1)
plt.xlabel("time (ms)")
plt.ylabel("number of active connection")
plt.legend()
plt.savefig("active_connection.png")
plt.clf()
def plot_average_response_time(server_to_start_connection, server_to_done_connection):
x = []
y = []
for server in sorted(server_to_start_connection):
if len(server_to_start_connection[server]) != 0:
average = (sum(server_to_done_connection[server]) - sum(server_to_start_connection[server])) / len(server_to_start_connection[server])
x.append(server)
y.append(average)
# This mean is a servr has large connection time its is slower
plt.bar(x, y, width = 0.3)
plt.xlabel("server")
plt.ylabel("Average Response time (ms)")
plt.legend(fontsize="x-large")
plt.savefig("average_response_time.png")
plt.clf()
if __name__ == '__main__':
if (len(sys.argv) < 2):
std.error("Please enter the log text file")
f = open(sys.argv[1], "r")
server_to_start_connection, server_to_done_connection, lastTime = construct_lists_from_file(f)
f.close()
fig = plt.figure(figsize= (10, 5))
server_to_num_request(server_to_start_connection)
plot_req_over_time_count(deepcopy(server_to_start_connection), lastTime)
plot_net_req_count(deepcopy(server_to_start_connection), deepcopy(server_to_done_connection), lastTime)
plot_average_response_time(deepcopy(server_to_start_connection), deepcopy(server_to_done_connection))