forked from ros2/rmw_connextdds
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michael Carroll <[email protected]>
- Loading branch information
Showing
7 changed files
with
147 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import numpy as np | ||
|
||
from ros2profile.data.event_sequence import EventSequence | ||
|
||
def test_sequence(profile_event_graph): | ||
graph = profile_event_graph | ||
nodes = graph.nodes('arequipa') | ||
assert len(nodes) == 1 | ||
arequipa = nodes[0] | ||
|
||
subs = arequipa.subscriptions() | ||
assert len(subs) == 1 | ||
|
||
arkansas_sub = subs[0] | ||
|
||
sub_events = arkansas_sub.callback().events() | ||
assert len(sub_events) > 0 | ||
|
||
events = [] | ||
for event in sub_events: | ||
events.append(EventSequence(event)) | ||
|
||
# We are expecting 26 events in the chain | ||
# Depending on which tracepoints are available | ||
assert len(events[0].sequence) < 30 | ||
|
||
latencies = [e.latency() for e in events] | ||
|
||
# Normalize to seconds | ||
latencies = np.array(latencies)/1e9 | ||
|
||
# Assert mean latency is less than 1 ms | ||
assert np.mean(latencies) < 1e-3 | ||
|
||
# Assert jitter is less than 100 microseconds | ||
assert np.std(latencies) < 1e-4 | ||
|
||
# Assert max latency is less than 1 ms | ||
assert np.max(latencies) < 1e-3 | ||
|
||
# Assert median latency is less than 1 ms | ||
assert np.median(latencies) < 1e-3 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from typing import Any, List | ||
|
||
from .callback import CallbackEvent | ||
from .timer import Timer | ||
from .subscription import SubscriptionEvent | ||
from .publisher import PublishEvent | ||
|
||
class EventSequence(): | ||
def __init__(self, end_event, start_event=None): | ||
self.start_event = start_event | ||
self.end_event = end_event | ||
self.sequence: List[Any] = [] | ||
|
||
self._build_sequence(self.end_event, self.start_event) | ||
|
||
def latency(self): | ||
return self.sequence[0]['timestamp'] - self.sequence[-1]['timestamp'] | ||
|
||
def _build_sequence(self, end_event, start_event=None): | ||
event = end_event | ||
self.sequence = [] | ||
|
||
while event and event != start_event: | ||
if type(event) is CallbackEvent: | ||
if type(event.source()) is Timer: | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'callback_end', | ||
'topic': 'timer', | ||
'timestamp': event.end() | ||
}) | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'callback_start', | ||
'topic': 'timer', | ||
'timestamp': event.start() | ||
}) | ||
else: | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'callback_end', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event.end() | ||
}) | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'callback_start', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event.start() | ||
}) | ||
|
||
event = event.trigger() | ||
elif type(event) is SubscriptionEvent: | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'rclcpp_take', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event._rclcpp_init_time | ||
}) | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'rcl_take', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event._rcl_init_time | ||
}) | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'rmw_take', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event._rmw_init_time | ||
}) | ||
event = event.trigger() | ||
elif type(event) is PublishEvent: | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'rclcpp_pub', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event._rclcpp_init_time | ||
}) | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'rcl_pub', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event._rcl_init_time | ||
}) | ||
self.sequence.append({ | ||
'node': event.source().node().name(), | ||
'event': 'rmw_pub', | ||
'topic': event.source().topic_name(), | ||
'timestamp': event._rmw_init_time | ||
}) | ||
|
||
event = event.trigger() | ||
else: | ||
break |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.