Skip to content

Commit

Permalink
Add a launch description wrapper (ros2#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Feb 27, 2023
1 parent 81fe2ce commit 015896b
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 209 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ Then launch the demonstration system with the specified configuration:


```
ros2 profile launch ~/safe_ros/src/ros2_profiling/ros2_profiling_demo/config/reference_system.yaml
ros2 profile launch \
--launch-file ./src/reference_system/launch/reference_system.launch.py \
--config-file ./src/ros2_profiling/ros2_profiling_demo/config/reference_system.yaml
```

The `topnode` uses ROS 2 lifecycle states to determine when to start/stop recording, so we can begin the recording via:
Expand Down
97 changes: 9 additions & 88 deletions ros2_profiling_demo/config/reference_system.yaml
Original file line number Diff line number Diff line change
@@ -1,90 +1,11 @@
nodes:
- name: cordoba
package: reference_system
plugin: reference_system::Cordoba
- name: freeport
package: reference_system
plugin: reference_system::Freeport
- name: medellin
package: reference_system
plugin: reference_system::Medellin
- name: portsmouth
package: reference_system
plugin: reference_system::Portsmouth
- name: delhi
package: reference_system
plugin: reference_system::Delhi
- name: taipei
package: reference_system
plugin: reference_system::Taipei
- name: lyon
package: reference_system
plugin: reference_system::Lyon
- name: hebron
package: reference_system
plugin: reference_system::Hebron
- name: kingston
package: reference_system
plugin: reference_system::Kingston
- name: hamburg
package: reference_system
plugin: reference_system::Hamburg
- name: osaka
package: reference_system
plugin: reference_system::Osaka
- name: tripoli
package: reference_system
plugin: reference_system::Tripoli
- name: mandalay
package: reference_system
plugin: reference_system::Mandalay
- name: ponce
package: reference_system
plugin: reference_system::Ponce
- name: geneva
package: reference_system
plugin: reference_system::Geneva
- name: monaco
package: reference_system
plugin: reference_system::Monaco
- name: rotterdam
package: reference_system
plugin: reference_system::Rotterdam
- name: barcelona
package: reference_system
plugin: reference_system::Barcelona
- name: arequipa
package: reference_system
plugin: reference_system::Arequipa
- name: georgetown
package: reference_system
plugin: reference_system::Georgetown
record_path: ~/.ros/profile

containers:
- name: reference_system_robot
type: component_container_isolated
nodes:
- cordoba
- freeport
- medellin
- portsmouth
- delhi
- taipei
- lyon
- hebron
- kingston
- hamburg
- osaka
- tripoli
- mandalay
- ponce
tracing:
session_name: ros2profile-tracing-session
kernel:
events: []

- name: reference_system_control
type: component_container_isolated
nodes:
- geneva
- monaco
- rotterdam
- barcelona
- arequipa
- georgetown
topnode:
nodes:
- "/reference_system_robot"
- "/reference_system_control"
6 changes: 3 additions & 3 deletions ros2_profiling_demo/test/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

def test_graph(profile_event_graph):
graph = profile_event_graph
assert len(graph.nodes()) == 24
assert len(graph.topics()) == 25
assert len(graph.publishers()) == 25
assert len(graph.nodes()) == 31
assert len(graph.topics()) == 29
assert len(graph.publishers()) == 29
assert len(graph.subscriptions()) == 36


Expand Down
84 changes: 70 additions & 14 deletions ros2_profiling_demo/test/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,70 @@
def test_nodes(profile_data):
assert len(profile_data.nodes()) == 20

# Assert that all of the nodes under test are available
# in the tracing data
for node in profile_data.nodes():
handle = profile_data.node_handle(node['name'])
assert handle

def test_cpu(profile_data):
containers = profile_data.containers()
for container in containers:
usage = profile_data.cpu_memory_usage(container)
assert (usage['cpu_percent'] < 50).all()
import numpy as np

def check_diff(field, tol=1e-6):
check = np.abs(field.max() - field.min())

if check >= tol:
print(field.max(), field.min())
return check < tol

def test_reference_system_control(profile_data):
'''
Demonstrate asserting based on topnode-collected profiling data
'''
data = None
for key in profile_data.keys():
if key.find('reference_system_control') >= 0:
data = profile_data[key]
assert data is not None

# By default:
# Topnode data should have 4 message types:
assert '~/cpu_memory_usage' in data
assert '~/memory_state' in data
assert '~/io_stats' in data
assert '~/stat' in data

cpu_memory_usage = data['~/cpu_memory_usage']
memory_state = data['~/memory_state']
io_stats = data['~/io_stats']
stat = data['~/stat']

# CPU should never exceed 5%
assert np.all(cpu_memory_usage['cpu_percent'] < 5)

# Memory usage should stay constant
assert check_diff(cpu_memory_usage.max_resident_set_size)
assert check_diff(cpu_memory_usage.shared_size)
assert check_diff(cpu_memory_usage.virtual_size)
assert check_diff(cpu_memory_usage.memory_percent)
assert check_diff(memory_state.resident_size, 100)


def test_reference_system_robot(profile_data):
data = None
for key in profile_data.keys():
if key.find('reference_system_control') >= 0:
data = profile_data[key]
assert data is not None

# By default:
# Topnode data should have 4 message types:
assert '~/cpu_memory_usage' in data
assert '~/memory_state' in data
assert '~/io_stats' in data
assert '~/stat' in data

cpu_memory_usage = data['~/cpu_memory_usage']
memory_state = data['~/memory_state']
io_stats = data['~/io_stats']
stat = data['~/stat']

# CPU should never exceed 5%
assert np.all(cpu_memory_usage['cpu_percent'] < 5)

# Memory usage should stay constant
assert check_diff(cpu_memory_usage.max_resident_set_size)
assert check_diff(cpu_memory_usage.shared_size)
assert check_diff(cpu_memory_usage.virtual_size)
assert check_diff(cpu_memory_usage.memory_percent)
assert check_diff(memory_state.resident_size, 100)
90 changes: 0 additions & 90 deletions ros2profile/config/reference_system.yaml

This file was deleted.

20 changes: 13 additions & 7 deletions ros2profile/ros2profile/api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,28 @@ def process_one(input_file):

def process(input_path):
mcap_files = glob.glob(input_path + '*.mcap')
print(f'Processing {len(mcap_files)} topnode files')

to_process = []
for mcap_file in mcap_files:
base = os.path.splitext(mcap_file)[0]
if not os.path.exists(base + '.converted'):
to_process.append(base)
print(f'Processing {len(to_process)} topnode files ({len(mcap_files)} cached)')

for mcap_file in to_process:
base = os.path.splitext(mcap_file)[0]
data = process_one(mcap_file)

with open(base + '.converted', 'wb') as f:
p = pickle.Pickler(f, protocol=4)
p.dump(data)

events = load_ctf(input_path)
graph = build_graph(events)

with open(os.path.join(input_path, 'event_graph'), 'wb') as f:
p = pickle.Pickler(f, protocol=4)
p.dump(graph)
if not os.path.exists(os.path.join(input_path, 'event_graph')):
events = load_ctf(input_path)
graph = build_graph(events)
with open(os.path.join(input_path, 'event_graph'), 'wb') as f:
p = pickle.Pickler(f, protocol=4)
p.dump(graph)


def load_mcap_data(input_path):
Expand Down
4 changes: 4 additions & 0 deletions ros2profile/ros2profile/data/convert/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
'rmw_publisher_handle': int,
'rmw_subscription_handle': int,
'rmw_service_handle': int,
'rmw_client_handle': int,
'subscription_handle': int,
'publisher_handle': int,
'service_handle': int,
'client_handle': int,
'timer_handle': int,
'rmw_handle': int,
'node_name': str,
'start_label': str,
'goal_label': str,
'namespace': str,
'version': str,
'vpid': int,
Expand Down
Loading

0 comments on commit 015896b

Please sign in to comment.