Make util processor method a base class method
This commit is contained in:
parent
5eb175cfd4
commit
9b96bb1132
3 changed files with 17 additions and 18 deletions
|
@ -67,3 +67,16 @@ class EventHandler():
|
||||||
cpu_id = get_field(event, 'cpu_id')
|
cpu_id = get_field(event, 'cpu_id')
|
||||||
metadata = EventMetadata(event_name, pid, tid, timestamp, procname, cpu_id)
|
metadata = EventMetadata(event_name, pid, tid, timestamp, procname, cpu_id)
|
||||||
handler_function(event, metadata)
|
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
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
"""Module for trace events processor and ROS model creation."""
|
"""Module for trace events processor and ROS model creation."""
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from tracetools_read.utils import get_field
|
from tracetools_read.utils import get_field
|
||||||
|
|
||||||
|
@ -198,15 +197,3 @@ class Ros2Processor(EventHandler):
|
||||||
bool(is_intra_process))
|
bool(is_intra_process))
|
||||||
else:
|
else:
|
||||||
print(f'No matching callback start for callback object "{callback_object}"')
|
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
|
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from tracetools_analysis.analysis import cpu_time_processor
|
|
||||||
from tracetools_analysis.analysis import load
|
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():
|
def parse_args():
|
||||||
|
@ -37,9 +37,8 @@ def main():
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
events = load.load_pickle(pickle_filename)
|
events = load.load_pickle(pickle_filename)
|
||||||
processor = ros2_processor.ros2_process(events)
|
processor = Ros2Processor.process(events)
|
||||||
cpu_processor = cpu_time_processor.CpuTimeProcessor()
|
cpu_processor = CpuTimeProcessor.process(events)
|
||||||
cpu_processor.handle_events(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')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue