• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tracing tools for ROS 2.

ros2_tracing

GitHub CI codecov

Tracing tools for ROS 2.

Overview

ros2_tracing provides tracing instrumentation for the core ROS 2 packages. It also provides tools to configure tracing through a launch action and a ros2 CLI command.

ros2_tracing currently only supports the LTTng tracer. Consequently, it currently only supports Linux.

Note: make sure to use the right branch, depending on the ROS 2 distro: use rolling for Rolling, galactic for Galactic, etc.

Publications & presentations

Read the ros2_tracing paper! If you use or refer to ros2_tracing, please cite:

  • C. Bédard, I. Lütkebohle, and M. Dagenais, "ros2_tracing: Multipurpose Low-Overhead Framework for Real-Time Tracing of ROS 2," IEEE Robotics and Automation Letters, vol. 7, no. 3, pp. 6511–6518, 2022.

    BibTeX
    @article{bedard2022ros2tracing,
      title={ros2\_tracing: Multipurpose Low-Overhead Framework for Real-Time Tracing of ROS 2},
      author={B{\'e}dard, Christophe and L{\"u}tkebohle, Ingo and Dagenais, Michel},
      journal={IEEE Robotics and Automation Letters},
      year={2022},
      volume={7},
      number={3},
      pages={6511--6518},
      doi={10.1109/LRA.2022.3174346}
    }

This other paper leverages ros2_tracing to analyze and visualize the flow of messages across distributed ROS 2 systems:

  • C. Bédard, P.-Y. Lajoie, G. Beltrame, and M. Dagenais, "Message Flow Analysis with Complex Causal Links for Distributed ROS 2 Systems," Robotics and Autonomous Systems, vol. 161, p. 104361, 2023.

    BibTeX
    @article{bedard2023messageflow,
      title={Message flow analysis with complex causal links for distributed {ROS} 2 systems},
      author={B{\'e}dard, Christophe and Lajoie, Pierre-Yves and Beltrame, Giovanni and Dagenais, Michel},
      journal={Robotics and Autonomous Systems},
      year={2023},
      volume={161},
      pages={104361},
      doi={10.1016/j.robot.2022.104361}
    }

Finally, check out the following presentations:

  • ROSCon 2023: "Improving Your Application's Algorithms and Optimizing Performance Using Trace Data" (video, slides)
  • ROS World 2021: "Tracing ROS 2 with ros2_tracing" (video, slides)

Tutorials & demos

Building

As of Iron, the LTTng tracer is a ROS 2 dependency. Therefore, ROS 2 can be traced out-of-the-box on Linux; this package does not need to be re-built.

To make sure that the instrumentation and tracepoints are available:

$ source /opt/ros/rolling/setup.bash  # With a binary install
$ source ./install/setup.bash  # When building from source
$ ros2 run tracetools status
Tracing enabled

A ROS 2 installation only includes the LTTng userspace tracer (LTTng-UST), which is all that is needed to trace ROS 2. To trace the Linux kernel, the LTTng kernel tracer must be installed separately:

$ sudo apt-get update
$ sudo apt-get install lttng-modules-dkms

For more information about LTTng, refer to its documentation.

Removing the instrumentation

To build and remove all instrumentation, use TRACETOOLS_DISABLED:

$ colcon build --cmake-args -DTRACETOOLS_DISABLED=ON

This will remove all instrumentation from the core ROS 2 packages, and thus they will not depend on or link against the shared library provided by the tracetools package. This also means that LTTng is not required at build-time or at runtime.

Excluding tracepoints

Alternatively, to only exclude the actual tracepoints, use TRACETOOLS_TRACEPOINTS_EXCLUDED:

$ colcon build --packages-select tracetools --cmake-clean-cache --cmake-args -DTRACETOOLS_TRACEPOINTS_EXCLUDED=ON

This will keep the instrumentation but remove all tracepoints. This also means that LTTng is not required at build-time or at runtime. This option can be useful, since tracepoints can be added back in or removed by simply replacing/re-building the shared library provided by the tracetools package.

Tracing

By default, trace data will not be generated, and thus these packages will have virtually no impact on execution. LTTng has to be configured for tracing. The packages in this repo provide two options: a command and a launch file action.

Note: tracing must be started before the application is launched. Metadata is recorded during the initialization phase of the application. This metadata is needed to understand the rest of the trace data, so if tracing is started after the application started executing, then the trace data might be unusable. For more information, refer to the design document. The launch file action is designed to automatically start tracing before the application launches.

The tracing directory can be configured using command/launch action parameters, or through environment variables with the following logic:

  • Use $ROS_TRACE_DIR if ROS_TRACE_DIR is set and not empty.
  • Otherwise, use $ROS_HOME/tracing, using ~/.ros for ROS_HOME if not set or if empty.

Additionally, if you're using kernel tracing with a non-root user, make sure that the tracing group exists and that your user is added to it.

# Create group if it doesn't exist
$ sudo groupadd -r tracing
# Add user to the group
$ sudo usermod -aG tracing $USER

Trace command

The first option is to use the ros2 trace command.

$ ros2 trace

By default, it will enable all ROS 2 tracepoints. The trace will be written to ~/.ros/tracing/session-YYYYMMDDHHMMSS. Run the command with -h for more information.

The ros2 trace command requires user interaction to start and then stop tracing. To trace without user interaction (e.g., in scripts), or for finer-grained tracing control, the following sub-commands can be used:

$ ros2 trace start session_name   # Configure tracing session and start tracing
$ ros2 trace pause session_name   # Pause tracing after starting
$ ros2 trace resume session_name  # Resume tracing after pausing
$ ros2 trace stop session_name    # Stop tracing after starting or resuming

Run each command with -h for more information.

You must install the kernel tracer if you want to enable kernel events (using the -k/--kernel-events option). If you have installed the kernel tracer, use kernel tracing, and still encounter an error here, make sure to add your user to the tracing group.

Launch file trace action

Another option is to use the Trace action in a Python, XML, or YAML launch file along with your Node action(s). This way, tracing automatically starts when launching the launch file and ends when it exits or when terminated.

$ ros2 launch tracetools_launch example.launch.py

The Trace action will also set the LD_PRELOAD environment to preload LTTng's userspace tracing helper(s) if the corresponding event(s) are enabled. For more information, see this example launch file and the Trace action.

You must install the kernel tracer if you want to enable kernel events (events_kernel in Python, events-kernel in XML or YAML). If you have installed the kernel tracer, use kernel tracing, and still encounter an error here, make sure to add your user to the tracing group.

Design

See the design document.

Real-time

LTTng-UST, the current default userspace tracer used for tracing ROS 2, was designed for real-time production applications. It is a low-overhead tracer with many important real-time compatible features:

  • userspace tracer completely implemented in userspace, independent from the kernel
  • reentrant, thread-safe, signal-safe, non-blocking
  • no system calls in the fast path
  • no copies of the trace data

However, some settings need to be tuned for it to be fully real-time safe and for performance to be optimal for your use-case:

  • timers1: use read timer to avoid a write(2) call
  • sub-buffer1 count and size:
    • see documentation for sub-buffer count and size tuning tips based on your use-case
    • minimize sub-buffer count to minimize sub-buffer switching overhead
  • one-time memory allocation/lock/syscall per thread:
    • usually done the first time a tracepoint is executed within a thread for URCU thread registration, but registration can be manually performed to force it to be done during your application's initialization
    • see this LTTng mailing list message

For further reading:

The LTTng kernel tracer has a similar implementation, but is separate from the userspace tracer.

Packages

lttngpy

Package containing liblttng-ctl Python bindings.

ros2trace

Package containing a ros2cli extension to enable tracing.

tracetools

Library to support instrumenting ROS packages, including core packages.

This package claims to be in the Quality Level 1 category, see the Quality Declaration for more details.

See the API documentation.

tracetools_launch

Package containing tools to enable tracing through launch files.

tracetools_read

Package containing tools to read traces.

tracetools_test

Package containing tools for tracing-related tests.

tracetools_trace

Package containing tools to enable tracing.

test_ros2trace

Package containing system tests for ros2trace.

test_tracetools

Package containing unit and system tests for tracetools.

test_tracetools_launch

Package containing system tests for tracetools_launch.

Analysis

See tracetools_analysis.

Footnotes

  1. this setting cannot currently be set through the Trace launch file action or the ros2 trace command, see #20 ↩ ↩2

More Repositories

1

ros2

The Robot Operating System, is a meta operating system for robots.
3,426
star
2

examples

Example packages for ROS 2
C++
683
star
3

ros2_documentation

ROS 2 docs repository
Python
541
star
4

rclcpp

rclcpp (ROS Client Library for C++)
C++
536
star
5

demos

C++
491
star
6

ros1_bridge

ROS 2 package that provides bidirectional communication between ROS 1 and ROS 2
C++
435
star
7

rclpy

rclpy (ROS Client Library for Python)
Python
288
star
8

rviz

ROS 3D Robot Visualizer
C++
287
star
9

rosbag2

C++
272
star
10

design

Design documentation for ROS 2.0 effort
JavaScript
224
star
11

common_interfaces

A set of packages which contain common interface files (.msg and .srv).
C++
220
star
12

ros2cli

ROS 2 command line interface tools
Python
173
star
13

rmw_zenoh

RMW for ROS 2 using Zenoh as the middleware
C++
171
star
14

rmw_fastrtps

Implementation of the ROS Middleware (rmw) Interface using eProsima's Fast RTPS.
C++
155
star
15

rmw_iceoryx

rmw implementation for iceoryx
C++
153
star
16

rcl

Library to support implementation of language specific ROS Client Libraries.
C++
128
star
17

launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Python
123
star
18

geometry2

A set of ROS packages for keeping track of coordinate transforms.
C++
120
star
19

rclc

ROS Client Library for the C language.
C
113
star
20

rmw_cyclonedds

ROS 2 RMW layer for Eclipse Cyclone DDS
C++
112
star
21

turtlebot2_demo

C++
95
star
22

rmw

The ROS Middleware (rmw) Interface.
C
95
star
23

sros2

tools to generate and distribute keys for SROS 2
Python
89
star
24

freertps

a free, portable, minimalist, work-in-progress RTPS implementation
C
89
star
25

rosidl

Packages which provide the ROS IDL (.msg) definition and code generation.
C++
74
star
26

ros2_embedded_nuttx

This repository isn't actively being worked on. If you would like to take over maintainership please open a ticket on https://github.com/ros2/ros2
C
72
star
27

message_filters

C++
70
star
28

realtime_support

Minimal real-time testing utility for measuring jitter and latency.
C++
61
star
29

rcutils

Common C functions and data structures used in ROS 2
C
56
star
30

launch_ros

Tools for launching ROS nodes and for writing tests involving ROS nodes.
Python
55
star
31

domain_bridge

Bridge communication across different ROS 2 domains.
C++
52
star
32

ci

ROS 2 CI Infrastructure
Python
48
star
33

rmw_connextdds

ROS 2 RMW layer for RTI Connext DDS Professional and RTI Connext DDS Micro.
C++
47
star
34

example_interfaces

Msg, Srv, etc. ROS interfaces used in examples
CMake
47
star
35

system_tests

C++
38
star
36

rcl_interfaces

A repository for messages and services used by the ROS client libraries
C++
38
star
37

rcpputils

C++
31
star
38

tutorials

C++
30
star
39

ros2_embedded_freertos

This repository isn't actively being worked on. If you would like to take over maintainership please open a ticket on https://github.com/ros2/ros2 -- ROS 2 for embedded devices.
C
29
star
40

rmw_connext

Implementation of the ROS Middleware (rmw) Interface using RTI's Connext DDS.
C++
26
star
41

choco-packages

Chocolatey package configurations for upstream dependencies
PowerShell
25
star
42

rosbag2_bag_v2

rosbag2 plugin for replaying ros1 version2 bag files
C++
24
star
43

rmw_dps

Implementation of the ROS Middleware (rmw) Interface using Intel's Distributed Publish & Subscribe.
C++
23
star
44

buildfarm_perf_tests

Performance tests which run regularly on the buildfarm
C++
23
star
45

rmw_implementation

CMake infrastructure and dependencies for rmw implementations
C++
21
star
46

openrobotics_darknet_ros

ROS 2 interface to darknet, an open source neural network library.
C++
20
star
47

rosidl_python

rosidl support for Python
EmberScript
19
star
48

ros_core_documentation

Documentation for the Core ROS 2 packages which does not fit into one of the individual packages' documentation.
Python
17
star
49

ros_network_viz

Python
17
star
50

rcl_logging

Logging implementations for ROS 2.
C++
16
star
51

rmw_gurumdds

Implementation of the ROS middleware interface using GurumNetworks GurumDDS.
C++
13
star
52

ros_testing

Single point of entry for writing tests which involve Nodes in ROS 2.
Python
13
star
53

rosidl_typesupport

Packages which provide the typesupport for ROS messages and services
C++
13
star
54

eigen3_cmake_module

Adds a custom find module for Eigen3
CMake
12
star
55

rmw_dds_common

C++
11
star
56

rmw_opensplice

Implementation of the ROS Middleware (rmw) interface using PrismTech's OpenSplice DDS.
C++
11
star
57

variants

Variants for ROS 2 (implemented as ament packages)
CMake
9
star
58

cookbook

A set of recipes for doing common tasks in ROS 2
C++
9
star
59

ros_workspace

Package to set ROS environment and configuration variables for ROS 2.
CMake
7
star
60

performance_test_fixture

Test fixture and CMake macro for using osrf_testing_tools_cpp with Google Benchmark
C++
7
star
61

tsc_working_group_governance_template

7
star
62

unique_identifier_msgs

CMake
6
star
63

rosidl_dds

Python
6
star
64

tlsf

Snapshot of TLSF allocator
C
6
star
65

detection_visualizer

ROS 2 package with a node that draws bound boxes for debugging computer vision nodes.
Python
6
star
66

rosidl_runtime_py

Runtime utilities for working with generated ROS interfaces in Python
Python
5
star
67

ros2_dds_profiles_examples

Example dds profiles to configure DDS correctly for different use cases
Python
5
star
68

rosidl_typesupport_gurumdds

Typesupport package which generates interfaces used by rmw_gurumdds.
EmberScript
4
star
69

python_cmake_module

CMake module for finding Python in a consistent way for all ROS 2 packages.
CMake
4
star
70

ament_cmake_ros

Python
4
star
71

darknet_vendor

CMake wrapper around darknet, an open source neural network framework.
CMake
4
star
72

ros2_generate_interface_docs

Python
4
star
73

middleware_working_group

Working group focused on functionality provided by the communication middleware and the language specific client libraries.
4
star
74

test_interface_files

CMake
3
star
75

rosidl_typesupport_opensplice

rosidl typesupport for PrismTech's OpenSplice DDS.
EmberScript
3
star
76

pybind11_vendor

Vendor package for pybind11.
CMake
3
star
77

tinyxml_vendor

Vendor package for providing tinyxml within a cmake package
CMake
2
star
78

rosidl_typesupport_fastrtps

rosidl typesupport for eProsima's FastRTPS
EmberScript
2
star
79

spdlog_vendor

Vendor package for spdlog
CMake
2
star
80

rosidl_dynamic_typesupport

Unified Interface for Dynamic (Runtime) Typesupport and Serialization
C
2
star
81

tinyxml2_vendor

temporary vendor package for tinyxml2
CMake
2
star
82

libyaml_vendor

CMake wrapper downloading and building libyaml
C++
2
star
83

orocos_kdl_vendor

CMake
2
star
84

unique_identifier

ROS 2 support for Universally Unique Identifiers
C++
1
star
85

rmw_freertps

rmw implementation using freertps
C++
1
star
86

netperf

C++
1
star
87

ros2.github.io

website for ros2.org
HTML
1
star
88

mimick_vendor

CMake
1
star
89

yaml_cpp_vendor

Vendor package for providing yaml cpp within a cmake package
CMake
1
star
90

ros2doc

i can haz docs?
Python
1
star
91

ros2cli_common_extensions

CMake
1
star
92

poco_vendor

CMake shim over the poco library: https://github.com/pocoproject/poco
CMake
1
star
93

rosidl_typesupport_connext

rosidl typesupport for RTI's Connext DDS.
EmberScript
1
star
94

docs.ros2.org

HTML
1
star