Building ROS 2 with tracing
Tracing instrumentation is included in the ROS 2 source code, and Linux installations of ROS 2 include the LTTng tracer as a dependency. Therefore, ROS 2 can be traced out-of-the-box on Linux.
However, ROS 2 can be built from source to remove the tracepoints or completely remove the instrumentation. This guide shows how to do that. For more information, see the repository.
This guide only applies to Linux systems.
Set up your system to build ROS 2 from source. See the source installation page for more information.
The ROS 2 tracing instrumentation is split into two components: function instrumentation and tracepoints.
First, a ROS 2 core package (e.g.,
rclcpp) calls a function provided by the
Then, that function triggers a tracepoint, which records data if the tracepoint is enabled at runtime.
By default, if the tracer is not configured to trace or if the tracepoints are not enabled, they will have virtually no impact on the execution. However, the tracepoints can still be removed through a CMake option. Furthermore, the functions can be completely removed through a CMake option, which implies that tracepoints are also removed.
This step depends on whether you are building ROS 2 from source or using ROS 2 binaries (Debian packages or “fat” archive).
To remove the tracepoints, (re)build
tracetools and set the
TRACETOOLS_TRACEPOINTS_EXCLUDED CMake option to
colcon build --packages-select tracetools --cmake-clean-cache --cmake-args -DTRACETOOLS_TRACEPOINTS_EXCLUDED=ON
ros2_tracing repository into your workspace and build:
git clone https://github.com/ros2/ros2_tracing.git -b iron src/ros2_tracing
colcon build --packages-select tracetools --cmake-args -DTRACETOOLS_TRACEPOINTS_EXCLUDED=ON
To completely remove both tracepoints and function calls, build ROS 2 from source and set the
TRACETOOLS_DISABLED CMake option to
colcon build --cmake-args -DTRACETOOLS_DISABLED=ON --no-warn-unused-cli
Validate that tracing is disabled:
ros2 run tracetools status
It should print out:
Tracing disabled through configuration
If something else is printed, then something went wrong.