|
| 1 | +.. redirect-from:: |
| 2 | + |
| 3 | + How-To-Guides/Building-ROS-2-with-Tracing-Instrumentation |
| 4 | + |
| 5 | +Building ROS 2 with tracing |
| 6 | +=========================== |
| 7 | + |
| 8 | +.. contents:: Table of Contents |
| 9 | + :depth: 2 |
| 10 | + :local: |
| 11 | + |
| 12 | +Tracing instrumentation is included in the ROS 2 source code, and Linux installations of ROS 2 include the LTTng tracer as a dependency. |
| 13 | +Therefore, ROS 2 can be traced out-of-the-box on Linux. |
| 14 | + |
| 15 | +However, ROS 2 can be built from source to remove the tracepoints or completely remove the instrumentation. |
| 16 | +This guide shows how to do that. |
| 17 | +For more information, see `the repository <https://github.com/ros2/ros2_tracing>`__. |
| 18 | + |
| 19 | +.. note:: |
| 20 | + |
| 21 | + This guide only applies to Linux systems. |
| 22 | + |
| 23 | +Prerequisites |
| 24 | +------------- |
| 25 | + |
| 26 | +Set up your system to build ROS 2 from source. |
| 27 | +See :doc:`the source installation page <../Installation/Alternatives/Ubuntu-Development-Setup>` for more information. |
| 28 | + |
| 29 | +Build configurations |
| 30 | +-------------------- |
| 31 | + |
| 32 | +The ROS 2 tracing instrumentation is split into two components: function instrumentation and tracepoints. |
| 33 | +First, a ROS 2 core package (e.g., ``rclcpp``) calls a function provided by the ``tracetools`` package. |
| 34 | +Then, that function triggers a tracepoint, which records data if the tracepoint is enabled at runtime. |
| 35 | + |
| 36 | +By default, if the tracer is not `configured to trace or if the tracepoints are not enabled <https://github.com/ros2/ros2_tracing#tracing>`__, they will have virtually no impact on the execution. |
| 37 | +However, the tracepoints can still be removed through a CMake option. |
| 38 | +Furthermore, the functions can be completely removed through a CMake option, which implies that tracepoints are also removed. |
| 39 | + |
| 40 | +Building without tracepoints |
| 41 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 42 | + |
| 43 | +This step depends on whether you are :doc:`building ROS 2 from source <../Installation/Alternatives/Ubuntu-Development-Setup>` or using ROS 2 binaries (:doc:`Debian packages <../Installation/Ubuntu-Install-Debians>` or :doc:`"fat" archive <../Installation/Alternatives/Ubuntu-Install-Binary>`). |
| 44 | +To remove the tracepoints, (re)build ``tracetools`` and set the ``TRACETOOLS_TRACEPOINTS_EXCLUDED`` CMake option to ``ON``: |
| 45 | + |
| 46 | +.. tabs:: |
| 47 | + |
| 48 | + .. group-tab:: Source installation |
| 49 | + |
| 50 | + .. code-block:: bash |
| 51 | +
|
| 52 | + cd ~/ros2_{DISTRO} |
| 53 | + colcon build --packages-select tracetools --cmake-clean-cache --cmake-args -DTRACETOOLS_TRACEPOINTS_EXCLUDED=ON |
| 54 | +
|
| 55 | + .. group-tab:: Binary installation |
| 56 | + |
| 57 | + Clone the ``ros2_tracing`` repository into your workspace and build: |
| 58 | + |
| 59 | + .. code-block:: bash |
| 60 | +
|
| 61 | + cd ~/ws |
| 62 | + git clone https://github.com/ros2/ros2_tracing.git -b {DISTRO} src/ros2_tracing |
| 63 | + colcon build --packages-select tracetools --cmake-args -DTRACETOOLS_TRACEPOINTS_EXCLUDED=ON |
| 64 | +
|
| 65 | +Building without instrumentation |
| 66 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 67 | + |
| 68 | +To completely remove both tracepoints and function calls, :doc:`build ROS 2 from source <../Installation/Alternatives/Ubuntu-Development-Setup>` and set the ``TRACETOOLS_DISABLED`` CMake option to ``ON``: |
| 69 | + |
| 70 | +.. code-block:: bash |
| 71 | +
|
| 72 | + cd ~/ros2_{DISTRO} |
| 73 | + colcon build --cmake-args -DTRACETOOLS_DISABLED=ON --no-warn-unused-cli |
| 74 | +
|
| 75 | +Validating |
| 76 | +---------- |
| 77 | + |
| 78 | +Validate that tracing is disabled: |
| 79 | + |
| 80 | +.. code-block:: bash |
| 81 | +
|
| 82 | + cd ~/ws |
| 83 | + source install/setup.bash |
| 84 | + ros2 run tracetools status |
| 85 | +
|
| 86 | +It should print out: |
| 87 | + |
| 88 | +.. tabs:: |
| 89 | + |
| 90 | + .. group-tab:: Without tracepoints |
| 91 | + |
| 92 | + .. code-block:: bash |
| 93 | +
|
| 94 | + Tracing disabled |
| 95 | +
|
| 96 | + .. group-tab:: Without instrumentation |
| 97 | + |
| 98 | + .. code-block:: bash |
| 99 | +
|
| 100 | + Tracing disabled through configuration |
| 101 | +
|
| 102 | +If something else is printed, then something went wrong. |
0 commit comments