2Reads data from a serial port and saves it to a local file, then analyzes the data.
3Make sure to set COM_PORT to the correct value before running.
6from collections
import defaultdict
12MESSAGES_TO_SAMPLE = 1000
13LOCAL_FILENAME =
"debug_log.txt"
18 parity=serial.PARITY_NONE,
19 stopbits=serial.STOPBITS_ONE,
20 bytesize=serial.EIGHTBITS,
24print(
"Connected to: " + ser.portstr)
28 print(
"Closing connection")
32f = open(LOCAL_FILENAME,
"w")
33print(
"Starting to write to file...")
36while messages_counted < MESSAGES_TO_SAMPLE:
38 line = ser.readline().decode(
"utf-8").strip()
49section_current = defaultdict(int)
50section_times = defaultdict(list)
51with open(LOCAL_FILENAME,
"r")
as f:
52 lines = f.readlines()[1:]
54 segments = line.split()
55 if len(segments) != 3:
57 name, action, time = segments
59 section_current[name] = int(time)
61 if section_current[name] == 0:
63 section_times[name].append(int(time) - section_current[name])
67print(
"Average time per section:")
69for name
in sorted(section_times.keys()):
72 print(f
" * AVG : {np.mean(section_times[name]):>6.3f} microseconds")
73 print(f
" * STD : {np.std(section_times[name]):>6.3f} microseconds")
74 print(f
" * MIN : {np.min(section_times[name]):>6.0f} microseconds")
75 print(f
" * MAX : {np.max(section_times[name]):>6.0f} microseconds")
76 print(f
" * % : {np.percentile(section_times[name], [10, 25, 50, 75, 90])}")