-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotting.py
More file actions
124 lines (91 loc) · 3.52 KB
/
plotting.py
File metadata and controls
124 lines (91 loc) · 3.52 KB
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
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import NullFormatter
def latency_plot(filename, maxvalue=None):
data = np.genfromtxt(filename, delimiter='\n')
data = data[np.logical_not(np.isnan(data))]
if maxvalue is None:
maxvalue = max(data)
plt.figure()
H = plt.hist(data, bins=np.linspace(0, maxvalue, 250), color='darkslategray')
plt.xlabel("Latency (ms)")
plt.ylabel("# of Occurrences")
plt.title("Latency Histogram")
x = data.max()/2
y = H[0].max()/2
meanval = np.round(np.mean(data), 5)
meanfreq = np.round(1/meanval, 5)
# plt.text(x, y, "Mean Value: " + str(meanval) + "\nMean Freq (Hz): " + str(meanfreq), horizontalalignment='center', verticalalignment='center')
def latency_plot_log(filename, maxvalue=None):
data = np.genfromtxt(filename, delimiter='\n')
data = data[np.logical_not(np.isnan(data))] # remove nan entries
if maxvalue is None:
maxvalue = max(data)
data_range = (min(data), max(data))
y = np.linspace(data_range[0], data_range[1], 10000)
x = np.zeros(y.shape)
for i, val in enumerate(y):
x_mask = data <= val
count = np.sum(x_mask)
x[i] = count/data.size
plt.figure()
plt.title("Logit")
# plt.ylim([0, 0.01])
plt.xscale('logit')
plt.plot(x, y, color='darkslategray')
plt.gca().xaxis.set_minor_formatter(NullFormatter())
plt.xlabel("Percentage of Transfers")
plt.ylabel("Latency (ms)")
def throughput_plot(filename, maxvalue=None):
data = np.genfromtxt(filename, delimiter='\n')
data = data[np.logical_not(np.isnan(data))] # remove nan entries
if maxvalue is None:
maxvalue = max(data)
plt.figure()
H = plt.hist(data, bins=np.linspace(0, maxvalue, 1000), color='darkslategray')
plt.xlabel("Latency (s)")
plt.ylabel("# of Occurrences")
plt.title("Throughput")
x = np.max(data)/2
y = H[0].max()/2
meanval = np.round(np.mean(data), 5)
meanfreq = np.round(1/meanval, 5)
plt.text(x, y, "Mean Value: " + str(meanval) + "\nMean Freq (Hz): " + str(meanfreq), horizontalalignment='center', verticalalignment='center')
def throughput_plot_log(filename, maxvalue=None):
data = np.genfromtxt(filename, delimiter='\n')
data = data[np.logical_not(np.isnan(data))] # remove nan entries
if maxvalue is None:
maxvalue = max(data)
data_range = (min(data), max(data))
y = np.linspace(data_range[0], data_range[1], 10000)
x = np.zeros(y.shape)
for i, val in enumerate(y):
x_mask = data <= val
count = np.sum(x_mask)
x[i] = count/data.size
plt.figure()
plt.title("Throughput")
plt.xscale('logit')
plt.plot(x, y, color='darkslategray')
plt.gca().xaxis.set_minor_formatter(NullFormatter())
plt.xlabel("Percentage of Transfers")
plt.ylabel("Time (s)")
def time_series_plot(filename, maxvalue=None):
data = np.genfromtxt(filename, delimiter='\n')
data = data[np.logical_not(np.isnan(data))] # remove nan entries
if maxvalue is None:
maxvalue = max(data)
x = np.cumsum(data)
plt.figure()
plt.title("Time Series")
plt.plot(x, data, '.', markersize=2, color='darkslategray')
plt.xlabel("Time (ms)")
plt.ylabel("Latency (ms)")
meanval = np.round(np.mean(data), 5)
print("Average latency: " + str(meanval))
if __name__ == "__main__":
filename = r"data\TCP_latency_test_60s_1m.txt"
latency_plot(filename)
latency_plot_log(filename)
time_series_plot(filename)
plt.show()