Call ParseStruct() at most once per parsed line.
ParseStruct() is a relatively expensive call, and only needs to be done once per log entry. Using one of the 2015 logs, with a 13 signal plot_actions file, this patch reduces the time for processing the log from ~6 seconds to ~1.3 seconds.
Change-Id: I4831014de12b7ca60e51c71fb03f2ff38266cbfb
diff --git a/frc971/analysis/analysis.py b/frc971/analysis/analysis.py
index e477bdd..48cc8bc 100755
--- a/frc971/analysis/analysis.py
+++ b/frc971/analysis/analysis.py
@@ -44,6 +44,8 @@
None
"""
pline = ParseLine(line)
+ pline_data = None
+
for key in self.signal:
value = self.signal[key]
binary = key[0]
@@ -61,10 +63,12 @@
# Make sure that we're looking at the right binary structure instance.
if binary == pline.name:
if pline.msg.startswith(struct_instance_name + ': '):
- # Parse the structure and traverse it as specified in
- # `data_search_path`. This lets the user access very deeply nested
- # structures.
- _, _, data = pline.ParseStruct()
+ # Parse the structure once.
+ if pline_data is None:
+ _, _, pline_data = pline.ParseStruct()
+ # Traverse the structure as specified in `data_search_path`.
+ # This lets the user access very deeply nested structures.
+ data = pline_data
for path in data_search_path:
data = data[path]