Extract pickle-loading function
This commit is contained in:
parent
ded341a59b
commit
dd402ed1ce
2 changed files with 26 additions and 18 deletions
20
tracetools_analysis/analysis/load.py
Normal file
20
tracetools_analysis/analysis/load.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
|
def load_pickle(pickle_file_path):
|
||||||
|
"""
|
||||||
|
Load pickle file containing converted trace events.
|
||||||
|
|
||||||
|
:param pickle_file_path (str): the path to the pickle file to load
|
||||||
|
:return list(dict): the list of events (dicts) read from the file
|
||||||
|
"""
|
||||||
|
events = []
|
||||||
|
with open(pickle_file_path, 'rb') as f:
|
||||||
|
p = pickle.Unpickler(f)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
events.append(p.load())
|
||||||
|
except EOFError:
|
||||||
|
break # we're done
|
||||||
|
|
||||||
|
return events
|
|
@ -2,9 +2,9 @@
|
||||||
# Entrypoint/script to process events from a pickle file to build a ROS model
|
# Entrypoint/script to process events from a pickle file to build a ROS model
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pickle
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from tracetools_analysis.analysis import load
|
||||||
from tracetools_analysis.analysis import ros2_processor
|
from tracetools_analysis.analysis import ros2_processor
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,21 +22,9 @@ def main():
|
||||||
pickle_filename = args.pickle_file
|
pickle_filename = args.pickle_file
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
with open(pickle_filename, 'rb') as f:
|
events = load.load_pickle(pickle_filename)
|
||||||
events = _get_events_from_pickled_file(f)
|
processor = ros2_processor.ros2_process(events)
|
||||||
p = ros2_processor.ros2_process(events)
|
|
||||||
time_diff = time.time() - start_time
|
time_diff = time.time() - start_time
|
||||||
print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms')
|
print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms')
|
||||||
|
|
||||||
p.get_data_model().print_model()
|
processor.get_data_model().print_model()
|
||||||
|
|
||||||
|
|
||||||
def _get_events_from_pickled_file(file):
|
|
||||||
p = pickle.Unpickler(file)
|
|
||||||
events = []
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
events.append(p.load())
|
|
||||||
except EOFError:
|
|
||||||
break # we're done
|
|
||||||
return events
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue