diff --git a/tracetools_analysis/tracetools_analysis/analysis/handler.py b/tracetools_analysis/tracetools_analysis/analysis/handler.py index 9f31d2d..5890c33 100644 --- a/tracetools_analysis/tracetools_analysis/analysis/handler.py +++ b/tracetools_analysis/tracetools_analysis/analysis/handler.py @@ -67,3 +67,16 @@ class EventHandler(): cpu_id = get_field(event, 'cpu_id') metadata = EventMetadata(event_name, pid, tid, timestamp, procname, cpu_id) handler_function(event, metadata) + + @classmethod + def process(cls, events: List[Dict[str, str]]) -> 'EventHandler': + """ + Create processor and process unpickled events to create model. + + :param events: the list of events + :return: the processor object after processing + """ + assert cls != EventHandler, 'only call process() from inheriting classes' + processor = cls() # pylint: disable=no-value-for-parameter + processor.handle_events(events) + return processor diff --git a/tracetools_analysis/tracetools_analysis/analysis/ros2_processor.py b/tracetools_analysis/tracetools_analysis/analysis/ros2_processor.py index 3944669..b600af2 100644 --- a/tracetools_analysis/tracetools_analysis/analysis/ros2_processor.py +++ b/tracetools_analysis/tracetools_analysis/analysis/ros2_processor.py @@ -15,7 +15,6 @@ """Module for trace events processor and ROS model creation.""" from typing import Dict -from typing import List from tracetools_read.utils import get_field @@ -198,15 +197,3 @@ class Ros2Processor(EventHandler): bool(is_intra_process)) else: print(f'No matching callback start for callback object "{callback_object}"') - - -def ros2_process(events: List[Dict[str, str]]) -> Ros2Processor: - """ - Process unpickled events and create ROS 2 model. - - :param events: the list of events - :return: the processor object - """ - processor = Ros2Processor() - processor.handle_events(events) - return processor diff --git a/tracetools_analysis/tracetools_analysis/process.py b/tracetools_analysis/tracetools_analysis/process.py index f2d76ca..370412e 100644 --- a/tracetools_analysis/tracetools_analysis/process.py +++ b/tracetools_analysis/tracetools_analysis/process.py @@ -18,9 +18,9 @@ import argparse import time -from tracetools_analysis.analysis import cpu_time_processor from tracetools_analysis.analysis import load -from tracetools_analysis.analysis import ros2_processor +from tracetools_analysis.analysis.cpu_time_processor import CpuTimeProcessor +from tracetools_analysis.analysis.ros2_processor import Ros2Processor def parse_args(): @@ -37,9 +37,8 @@ def main(): start_time = time.time() events = load.load_pickle(pickle_filename) - processor = ros2_processor.ros2_process(events) - cpu_processor = cpu_time_processor.CpuTimeProcessor() - cpu_processor.handle_events(events) + processor = Ros2Processor.process(events) + cpu_processor = CpuTimeProcessor.process(events) time_diff = time.time() - start_time print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms')