Complete basic callback duration processing
This commit is contained in:
parent
7e99bcb0ab
commit
02f5eb339a
4 changed files with 52 additions and 18 deletions
|
@ -6,11 +6,11 @@ def ros_process(events):
|
|||
"""
|
||||
Process unpickled events and create ROS model
|
||||
:param events (list(dict(str:str:))): the list of events
|
||||
:return the processor object
|
||||
"""
|
||||
processor = RosProcessor()
|
||||
for event in events:
|
||||
print(f'event: {str(event)}')
|
||||
processor.handle(event)
|
||||
processor.process_events(events)
|
||||
return processor
|
||||
|
||||
class RosProcessor():
|
||||
"""
|
||||
|
@ -19,7 +19,10 @@ class RosProcessor():
|
|||
"""
|
||||
def __init__(self):
|
||||
# TODO add other stuff
|
||||
self.callbacks = []
|
||||
# Instances of callback_start for eventual matching
|
||||
self._callback_starts = {}
|
||||
# Callback instances, callback_address: end - start
|
||||
self.callbacks_instances = {}
|
||||
|
||||
# Link a ROS trace event to its corresponding handling method
|
||||
self._handler_map = {
|
||||
|
@ -28,13 +31,17 @@ class RosProcessor():
|
|||
'ros2:rclcpp_subscription_callback_start': self._handle_subscription_callback_start,
|
||||
'ros2:rclcpp_subscription_callback_end': self._handle_subscription_callback_end,
|
||||
}
|
||||
|
||||
def handle(self, event):
|
||||
|
||||
def process_events(self, events):
|
||||
"""
|
||||
Handle an event
|
||||
:param event (dict(str:str)): the event to handle
|
||||
Process events
|
||||
:param events (list(dict(str:str))): the events to process
|
||||
"""
|
||||
handler_function = self._handler_map.get(get_name(event), d=None)
|
||||
for event in events:
|
||||
self._handle(event)
|
||||
|
||||
def _handle(self, event):
|
||||
handler_function = self._handler_map.get(get_name(event), None)
|
||||
if handler_function is not None:
|
||||
name = get_name(event)
|
||||
pid = get_field(event, 'vpid', default=get_field(event, 'pid'))
|
||||
|
@ -49,13 +56,17 @@ class RosProcessor():
|
|||
pass
|
||||
|
||||
def _handle_subscription_callback_added(self, event, metadata):
|
||||
# TODO
|
||||
pass
|
||||
# Add the callback address key and create an empty list
|
||||
callback_addr = get_field(event, 'callback')
|
||||
self.callbacks_instances[callback_addr] = []
|
||||
|
||||
def _handle_subscription_callback_start(self, event, metadata):
|
||||
# TODO
|
||||
pass
|
||||
callback_addr = get_field(event, 'callback')
|
||||
self._callback_starts[callback_addr] = metadata.timestamp
|
||||
|
||||
def _handle_subscription_callback_end(self, event, metadata):
|
||||
# TODO
|
||||
pass
|
||||
callback_addr = get_field(event, 'callback')
|
||||
start_timestamp = self._callback_starts.pop(callback_addr, None)
|
||||
if start_timestamp is not None:
|
||||
duration = metadata.timestamp - start_timestamp
|
||||
self.callbacks_instances[callback_addr].append(duration)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue