Make callback instance handling more generic
This commit is contained in:
parent
a58b4e841d
commit
6a8843f0f4
2 changed files with 29 additions and 23 deletions
|
@ -47,10 +47,10 @@ class DataModel():
|
||||||
def add_subscription(self, subscription_handle, timestamp, node_handle, rmw_handle, topic_name, depth):
|
def add_subscription(self, subscription_handle, timestamp, node_handle, rmw_handle, topic_name, depth):
|
||||||
self._subscriptions.loc[subscription_handle] = [timestamp, node_handle, rmw_handle, topic_name, depth]
|
self._subscriptions.loc[subscription_handle] = [timestamp, node_handle, rmw_handle, topic_name, depth]
|
||||||
|
|
||||||
def add_subscription_callback_object(self, subscription_handle, timestamp, callback_object):
|
def add_callback_object(self, handle, timestamp, callback_object):
|
||||||
self._callback_objects.loc[subscription_handle] = [timestamp, callback_object]
|
self._callback_objects.loc[handle] = [timestamp, callback_object]
|
||||||
|
|
||||||
def add_callback(self, callback_object, timestamp, symbol):
|
def add_callback_symbol(self, callback_object, timestamp, symbol):
|
||||||
self._callback_symbols.loc[callback_object] = [timestamp, symbol]
|
self._callback_symbols.loc[callback_object] = [timestamp, symbol]
|
||||||
|
|
||||||
def add_callback_instance(self, callback_object, timestamp, duration, intra_process):
|
def add_callback_instance(self, callback_object, timestamp, duration, intra_process):
|
||||||
|
@ -67,8 +67,6 @@ class DataModel():
|
||||||
print()
|
print()
|
||||||
print(f'Subscriptions:\n{self._subscriptions.to_string()}')
|
print(f'Subscriptions:\n{self._subscriptions.to_string()}')
|
||||||
print()
|
print()
|
||||||
print(f'Callback instances:\n{self._callbacks_instances.to_string()}')
|
|
||||||
print()
|
|
||||||
print(f'Services:\n{self._services.to_string()}')
|
print(f'Services:\n{self._services.to_string()}')
|
||||||
print()
|
print()
|
||||||
print(f'Clients:\n{self._clients.to_string()}')
|
print(f'Clients:\n{self._clients.to_string()}')
|
||||||
|
@ -78,4 +76,6 @@ class DataModel():
|
||||||
print(f'Callback objects:\n{self._callback_objects.to_string()}')
|
print(f'Callback objects:\n{self._callback_objects.to_string()}')
|
||||||
print()
|
print()
|
||||||
print(f'Callback symbols:\n{self._callback_symbols.to_string()}')
|
print(f'Callback symbols:\n{self._callback_symbols.to_string()}')
|
||||||
|
print()
|
||||||
|
print(f'Callback instances:\n{self._callbacks_instances.to_string()}')
|
||||||
print('==================================================')
|
print('==================================================')
|
||||||
|
|
|
@ -102,27 +102,13 @@ class RosProcessor(EventHandler):
|
||||||
def _handle_rclcpp_subscription_callback_added(self, event, metadata):
|
def _handle_rclcpp_subscription_callback_added(self, event, metadata):
|
||||||
subscription_handle = get_field(event, 'subscription_handle')
|
subscription_handle = get_field(event, 'subscription_handle')
|
||||||
callback_object = get_field(event, 'callback')
|
callback_object = get_field(event, 'callback')
|
||||||
self._data.add_subscription_callback_object(subscription_handle, metadata.timestamp, callback_object)
|
self._data.add_callback_object(subscription_handle, metadata.timestamp, callback_object)
|
||||||
|
|
||||||
def _handle_rclcpp_subscription_callback_start(self, event, metadata):
|
def _handle_rclcpp_subscription_callback_start(self, event, metadata):
|
||||||
# Add to dict
|
self.__handle_callback_start(event, metadata)
|
||||||
callback_addr = get_field(event, 'callback')
|
|
||||||
self._callback_instances[callback_addr] = (event, metadata)
|
|
||||||
|
|
||||||
def _handle_rclcpp_subscription_callback_end(self, event, metadata):
|
def _handle_rclcpp_subscription_callback_end(self, event, metadata):
|
||||||
# Fetch from dict
|
self.__handle_callback_end(event, metadata)
|
||||||
callback_object = get_field(event, 'callback')
|
|
||||||
(event_start, metadata_start) = self._callback_instances.get(callback_object)
|
|
||||||
if event_start is not None and metadata_start is not None:
|
|
||||||
del self._callback_instances[callback_object]
|
|
||||||
duration = metadata.timestamp - metadata_start.timestamp
|
|
||||||
is_intra_process = get_field(event_start, 'is_intra_process')
|
|
||||||
self._data.add_subscription_callback_instance(callback_object,
|
|
||||||
metadata_start.timestamp,
|
|
||||||
duration,
|
|
||||||
bool(is_intra_process))
|
|
||||||
else:
|
|
||||||
print(f'No matching callback start for callback object "{callback_object}"')
|
|
||||||
|
|
||||||
def _handle_rcl_service_init(self, event, metadata):
|
def _handle_rcl_service_init(self, event, metadata):
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -163,4 +149,24 @@ class RosProcessor(EventHandler):
|
||||||
def _handle_rclcpp_callback_register(self, event, metadata):
|
def _handle_rclcpp_callback_register(self, event, metadata):
|
||||||
callback_object = get_field(event, 'callback')
|
callback_object = get_field(event, 'callback')
|
||||||
symbol = get_field(event, 'symbol')
|
symbol = get_field(event, 'symbol')
|
||||||
self._data.add_callback(callback_object, metadata.timestamp, symbol)
|
self._data.add_callback_symbol(callback_object, metadata.timestamp, symbol)
|
||||||
|
|
||||||
|
def __handle_callback_start(self, event, metadata):
|
||||||
|
# Add to dict
|
||||||
|
callback_addr = get_field(event, 'callback')
|
||||||
|
self._callback_instances[callback_addr] = (event, metadata)
|
||||||
|
|
||||||
|
def __handle_callback_end(self, event, metadata):
|
||||||
|
# Fetch from dict
|
||||||
|
callback_object = get_field(event, 'callback')
|
||||||
|
(event_start, metadata_start) = self._callback_instances.get(callback_object)
|
||||||
|
if event_start is not None and metadata_start is not None:
|
||||||
|
del self._callback_instances[callback_object]
|
||||||
|
duration = metadata.timestamp - metadata_start.timestamp
|
||||||
|
is_intra_process = get_field(event_start, 'is_intra_process', raise_if_not_found=False)
|
||||||
|
self._data.add_callback_instance(callback_object,
|
||||||
|
metadata_start.timestamp,
|
||||||
|
duration,
|
||||||
|
bool(is_intra_process))
|
||||||
|
else:
|
||||||
|
print(f'No matching callback start for callback object "{callback_object}"')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue