-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_nav2d_times.py
286 lines (256 loc) · 11.8 KB
/
plot_nav2d_times.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# THIS SCRIPT PLOTS THE CI FOR ALL NODES, TPUT FOR NC Nodes.
import sys
import matplotlib.pyplot as plt
import numpy as np
import random
import json
fname_pre_str = sys.argv[1]
fname_post_str = sys.argv[2]
start_t = float(sys.argv[3])
end_t = float(sys.argv[4])
start_run_ind = int(sys.argv[5])
end_run_ind = int(sys.argv[6])
data_fname = sys.argv[7]
def aggregate_over_time(m_arr, ts_arr, start_t, slot, end_t):
new_m_arr = []
new_ts_arr = []
start_arr = []
# start from startt, any reading
i = 0
curr_ts = start_t
print "#### Func aggregate_over_time called with params: ", slot, start_t, end_t
print "Len of array to be aggregated: ", len(m_arr), " 0th TS:", ts_arr[0]
# aggregate until TS > curr_ts + slot.
while (curr_ts + slot) < end_t:
# collect all those in this slot.
this_slot = []
this_slot_ts = []
while i < len(m_arr):
if ts_arr[i] < curr_ts:
i += 1
elif ts_arr[i] <= (curr_ts + slot):
this_slot.append(m_arr[i])
this_slot_ts.append(ts_arr[i])
#print "Adding ind ", i, " TS: ", ts_arr[i], " to slot from ", curr_ts
i += 1
else:
break
#print "Done with this slot, moving to next, i=", i
curr_ts += slot
start_arr.append(curr_ts)
new_m_arr.append(this_slot)
new_ts_arr.append(this_slot_ts)
return new_m_arr, start_arr, new_ts_arr
def plot_agg(x,y,start,slot,end, nm, node):
agg1_y, agg_end, agg1_ts = aggregate_over_time(y,x,start, slot, end)
agg_avg = []
# need 25%ile
# need 75%ile
agg_25p = []
agg_75p = []
agg_end1 = []
ind = 0
for i in agg1_y:
if len(i) > 0:
arr = sorted(i)
agg_25p.append( arr[(25*len(i))/100] )
agg_75p.append( arr[(75*len(i))/100] )
agg_avg.append ( sum(i)/len(i) )
agg_end1.append(agg_end[ind])
ind += 1
plt.plot(agg_end1, agg_avg, 'b*:', markersize=8, label="Avg " + nm)
plt.plot(agg_end1, agg_25p, 'g^-.', markersize=8, label="25p " + nm)
plt.plot(agg_end1, agg_75p, 'ro:', markersize=8, label="75p " + nm)
plt.xlabel('Time')
plt.ylabel(nm + " in s")
plt.title('Aggregate %s for subchain %s over %fs period'%( nm, node, slot) )
plt.legend()
plt.show()
def print_arr(a,s):
sa = sorted(a)
la = len(a)
def get_rel_ts_arr(ts):
rel_ts = []
start_ts = ts[0]
for i in ts:
rel_ts.append(round(i - ts[0], 2))
return rel_ts
per_run_scan_ct = []
per_run_mapupd_ts = []
per_run_mapu_time = []
per_run_navp_time = []
per_run_navp_ts = []
per_run_drops_ratio = []
per_run_scan_lat = []
aggregate_navc_tput = []
per_run_navc_ts = []
node_tputs = {} # node name -> array
runs = range(start_run_ind,end_run_ind+1)
for br in [3,10,13,17,21]:
if br in runs:
runs.remove(br)
print(runs, len(runs))
runs_final_data = {}
for fname in ["operator_loop", "yolo", "local_map", "navigator_cmd", "mapper_scanCB", "mapper_mapUpdate", "navigator_plan"]:
node_tputs[fname] = []
for run in runs: #range(start_run_ind,end_run_ind+1):#[52,53,54,56,57]:
print("################## DOING RUN %i"%(run) )
times = []
ts = []
scan_count = []
tputs = []
drops_ts = []
drops_times = []
scan_pose_ts = []
lats = [] # lat wrt sensor inputs
wallts = []
try:
with open(fname_pre_str + fname + fname_post_str + "_run" + str(run) + ".txt", 'r') as f:
for fl in f.readlines():
if ("times:" in fl) or ("local_map Times" in fl):
times += [ round(float(x),4) for x in fl.split(" ")[2:-1] ]
elif "ts:" in fl:
ts += [ float(x) for x in fl.split(" ")[2:-1] ]
elif "ScanCOunt" in fl:
scan_count += [ int(x) for x in fl.split(" ")[2:-1] ]
elif "tput:" in fl:
tputs += [ float(x) for x in fl.split(" ")[2:-1] ]
#print("Added to tputs len: %i"%(len(tputs)))
elif "scanDrop" in fl:
drops_ts += [ float(x) for x in fl.split(" ")[2:-1] ]
elif "scanPoseTS" in fl:
scan_pose_ts += [ int(x) for x in fl.split(" ")[2:-1] ]
elif "scanDropExecTimes" in fl:
drops_times += [ float(x) for x in fl.split(" ")[2:-1] ]
elif "lat:" in fl:
lats += [ float(x) for x in fl.split(" ")[2:-1] ]
elif "wallTimeScanCB" in fl:
wallts += [ float(x) for x in fl.split(" ")[2:-1] ]
except Exception as e:
print("ERROR READING FOR ", fname, run, e)
# plot times,ts and scan_count.
print("Starting node ", fname, "Lengths of all arrs: times: %i, ts: %i, tputs: %i"%(len(times), len(ts), len(tputs) ) )
if len(drops_ts) > 0:
per_run_drops_ratio.append( len(tputs)/float(len(drops_ts)) )
drops_times_large = filter(lambda x: x[0] > 0.0015, zip(drops_times, drops_ts))
print("DROPS ci >1.5ms: ", drops_times_large)
#print("NODE %s TPUT: %s \n \n "%(fname, str(tputs) ) )
#print("NODE %s CI: %s \n \n"%(fname, str(times) ) )
if len(scan_pose_ts) > 0:
good_scan_pose = filter( lambda x: x > 0, scan_pose_ts )
print("Good scan pose : %i, total : %i"%( len(good_scan_pose), len(scan_pose_ts) ) )
'''
plt.plot(ts, times, 'bo-', label=fname + " compute time")
plt.title("Nav2d Node : %s"%(fname) )
plt.legend()
plt.show()
'''
#plot_agg(ts, times, start_t, 2.0, end_t, "ComputeTime", fname)
#plot_agg(ts, times, start_t, 10.0, end_t, "ComputeTime", fname)
sorted_times = sorted(times)
ltimes = len(sorted_times)
if ltimes>0:
print("For node %s, ci best case: %f, 10p: %f, 25p: %f, median: %f, mean %f, 75ile %f, 90ile %f, 95ile %f, worst case: %f" % ( fname, sorted_times[0], sorted_times[ltimes/10], sorted_times[(25*ltimes)/100], sorted_times[ltimes/2], sum(sorted_times)/ltimes, sorted_times[(75*ltimes)/100], sorted_times[(90*ltimes)/100], sorted_times[(95*ltimes)/100], sorted_times[-1] ) )
if ltimes>0:
filtered_times = filter(lambda x: x[1] < end_t, zip(times,ts) )
sorted_ftimes = sorted([x[0] for x in filtered_times])
lft = len(filtered_times)
if lft>0:
print("For node %s, [len: %i] ci best case: %f, 10p: %f, 25p: %f, median: %f, mean %f, 75ile %f, 90ile %f, 95ile %f, worst case: %f" % ( fname, lft, sorted_ftimes[0], sorted_ftimes[lft/10], sorted_ftimes[lft/4], sorted_ftimes[lft/2], sum(sorted_ftimes)/lft, sorted_ftimes[(3*lft)/4], sorted_ftimes[(9*lft)/10], sorted_ftimes[(95*lft)/100], sorted_ftimes[-1] ) )
if len(drops_ts) > 0:
filt_Drops_ts = filter(lambda x: x < end_t and x > start_t, drops_ts)
print("#SCAN Drops until end_t: ", len(filt_Drops_ts), len(drops_ts))
if "oper" in fname:
for i in range(len(times)):
if (times[i] > 0.01) or (ts[i] > 114586.8 and ts[i] < 114588):
print i, times[i], ts[i]
if len(lats) > 0:
large_lats = filter(lambda x: x[0] > 1.0 , zip(lats, ts, wallts, times) )
print("NODE ", fname, " VERY HIGH LATS: ", large_lats, " LARGEST Lat: ", sorted(zip(lats, ts, wallts, times), key=lambda x: x[0])[-1] )
zip_ar = zip(lats, wallts, times)
random.shuffle(zip_ar)
per_run_scan_lat += zip_ar[:100]
if len(tputs) > 0:
if "cmd" in fname:
aggregate_navc_tput += tputs
for i in range(len(tputs)):
if tputs[i] > 0.93:
print("FOR NAVC , LARGE tput: %f, ts: %f"%(tputs[i], ts[i]) )
sorted_tput = sorted(tputs)
ltimest = len(tputs)
print("For node %s, Tput: 10p: %f, 25p %f, median %f, mean %f, 75ile %f, 90ile %f, 95ile %f"%( fname, sorted_tput[(10*ltimest)/100], sorted_tput[(25*ltimest)/100], sorted_tput[ltimest/2], sum(sorted_tput)/ltimest, sorted_tput[(75*ltimest)/100], sorted_tput[(90*ltimest)/100], sorted_tput[(95*ltimest)/100] ) )
print("Len tputs: %i, Len TS: %i"%(len(tputs), len(ts)) )
if "plan" in fname or ("scanCB" in fname):
thresh = 2.0 if "plan" in fname else 1.5
large_tput_navp = filter(lambda x: x[0] > thresh, zip(tputs, ts[1:]) )
print("NNODE LARGE TPUT: ", fname, large_tput_navp)
'''
plt.plot(ts[19:], tputs[18:], 'r*-.', label=fname + " Inter-arrival Time")
plt.xlabel("Time")
if "cmd" in fname:
plt.ylim(0.0, 1.0)
plt.ylabel(fname+" Inter-arrival Time (s)")
plt.title("nav2d Node : %s Inter-arrival"%(fname) )
plt.legend()
#plt.show()
'''
if ("_plan" in fname and (len(ts) > 0) ):
per_run_navp_ts.append(get_rel_ts_arr(ts))
per_run_navp_time.append(times)
if ("_cmd" in fname and (len(ts) > 0) ):
print(ts[9803:9974])
per_run_navc_ts.append(get_rel_ts_arr(ts))
if len(scan_count) > 0:
msc = max(scan_count)
# scan_count = [ (x*0.1/msc) for x in scan_count]
print("Scan ct 1st: %i, last: %i"%(scan_count[0], scan_count[-1]) )
#plt.plot(ts, scan_count, 'g^:', label=fname + " Scan Count")
#plt.title("Nav2d NOde : %s #Scans"%(fname))
#plt.legend()
#plt.show()
print("Len tputs: %i, Len TS: %i"%(len(tputs), len(ts)) )
#plt.plot(ts[1:], tputs, 'r*-.', label=fname + " Inter-arrival Time")
#plt.title("nav2d Node : %s Inter-arrival"%(fname) )
#plt.legend()
#plt.show()
per_run_scan_ct.append(scan_count)
per_run_mapupd_ts.append(get_rel_ts_arr(ts))
per_run_mapu_time.append(times)
#print("SCAN COUNTS : ", scan_count, ", TS: ", ts, "\n \n")
random.shuffle(tputs)
node_tputs[fname] += tputs[:100]
'''
plot_agg(ts[1:], tputs, start_t, 2.0, end_t, "Inter-arrival Time", fname)
sorted_tput = sorted(tputs)
ltimest = len(tputs)
print("For node %s, Tput: median %f, mean %f, 75ile %f, 90ile %f"%( fname, sorted_tput[ltimest/2], sum(sorted_tput)/ltimest, sorted_tput[(75*ltimest)/100], sorted_tput[(90*ltimest)/100] ) )
#plot_agg(ts[1:], tputs, start_t, 10.0, end_t, "Inter-arrival Time", fname)
'''
print("Aggregate NC: median: %f, 75ile: %f, 95ile: %f"%(np.median(aggregate_navc_tput), np.percentile(aggregate_navc_tput, 75), np.percentile(aggregate_navc_tput, 95) ) )
for k in node_tputs:
print(node_tputs[k], k)
print("-")
print("-")
'''
print("\n \n PER RUN SCAN CT : ", per_run_scan_ct)
print("-")
print("-")
print("\n \n per_run_mapupd_ts : ", per_run_mapupd_ts)
print("-")
print("-")
print("\n \n PER RUN MAPUPD CI : ", per_run_mapu_time)
print("-")
print("-")
print("\n \n PER RUN NAVP CI : ", per_run_navp_time, '\n')
print("-")
print("-")
print("-")
print("-")
print("PER RUN DROPS RATIO: , avg ratio : %f, median ratio : %f", per_run_drops_ratio, sum(per_run_drops_ratio)/len(per_run_drops_ratio), np.median(per_run_drops_ratio) )
'''
#print("\n \n PER RUN NAVP TS: ", per_run_navp_ts)
#print("\n \n PER RUN NAVC TS: ", per_run_navc_ts)
runs_final_data["Odom_NC_TS"] = per_run_navc_ts
with open(data_fname+'.txt','w') as ffff:
json.dump(runs_final_data, ffff)
print("\n \n PER RUN SCAN LATENCY AT MAPCB : ", len(per_run_scan_lat), per_run_scan_lat)