forked from NeBula-Autonomy/LOCUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiler.py
47 lines (41 loc) · 1.32 KB
/
profiler.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
"""
Description:
- A script to profile Rate/Delay performance of a logged ROS topic
Author:
- Matteo Palieri, NASA Jet Propulsion Laboratory
"""
from matplotlib import pyplot as plt
plt.style.use('dark_background')
def plot_and_save_data(title, data):
fig = plt.figure()
plt.plot(data, linewidth=5)
plt.title(title)
plt.show()
fig.savefig(title)
def get_avg(data):
return reduce(lambda x,y: x+y, data)/len(data)
def save_report(hz_data, delay_data):
plot_and_save_data("Rate", hz_data)
plot_and_save_data("Delay", delay_data)
avg_hz_str = str(get_avg(hz_data))
avg_delay_str = str(get_avg(delay_data))
print("Rate avg: " + avg_hz_str)
print("Delay avg: " + avg_delay_str)
outfile = open("report.txt", "w")
outfile.write("Rate avg: " + avg_hz_str + "\n" + "Rate delay: " + avg_delay_str + "\n")
outfile.close()
def main():
hz = open("hz.txt")
delay = open("delay.txt")
hz_data, delay_data = [], []
for el in hz:
if "average rate:" in el:
splitted = el.split(": ")
hz_data.append(float(splitted[1]))
for el in delay:
if "average delay:" in el:
splitted = el.split(": ")
delay_data.append(float(splitted[1]))
save_report(hz_data, delay_data)
if __name__=="__main__":
main()