Comments (3)
You can instrument your own code with LTTng and then use the ros2_tracing
tools to enable the tracepoints (Trace
action or ros2 trace
command).
If you want to get a flame graph or flame chart for your functions, I'd recommend using gcc
's function instrumentation feature (-finstrument-functions
). This adds function calls at the start and end of the instrumented functions if you build with this option. You can use the instrument-functions
mixin to do this with colcon (e.g., colcon build --packages-up-to your_package --mixin instrument-functions
). gcc
only allows you to instrument all functions and exclude individual functions or headers, so I'd recommend using this gcc
plugin I've created in order to only instrument the individual functions you want: https://github.com/christophebedard/instrument-attribute-gcc-plugin. Then you can add __attribute__((instrument_function))
to your helper functions (specifically their definitions IIRC). You'll need to provide the flag with the path to the plugin to gcc
through colcon
, like this I think: colcon build --packages-up-to your_package --cmake-args "-DCMAKE_C_FLAGS='-finstrument-functions,-fplugin=/abs/path/to/instrument_attribute.so'" "-DCMAKE_CXX_FLAGS='-finstrument-functions,-fplugin=/abs/path/o/instrument_attribute.so'"
(so you might as well skip using the mixin).
You can then use LTTng to trigger tracepoints inside the special functions that gcc
adds: https://lttng.org/docs/v2.13/#doc-liblttng-ust-cyg-profile. You'll need to enable those special tracepoints (lttng_ust_cyg_profile*
/lttng_ust_cyg_profile*:func_entry
) like this: https://gitlab.com/ros-tracing/tracetools_analysis/-/blob/9c853b27fc380d763317ce786f0588007db8f33b/tracetools_analysis/launch/profile.launch.py#L29-L30. You also need to LD_PRELOAD
LTTng's liblttng-ust-cyg-profile.so
library (or liblttng-ust-cyg-profile-fast.so
), but the Trace
action or ros2 trace
command should do that for you automatically when you tell it to enable the lttng_ust_cyg_profile*:func_*
tracepoints.
Then you can import the trace into Trace Compass, and it should be able to display the information as a flame chart/graph, see: https://archive.eclipse.org/tracecompass/doc/stable/org.eclipse.tracecompass.doc.user/LTTng-UST-Analyses.html#Flame_Chart_View.
I've written code to use trace data generated from the standard ROS 2 instrumentation (i.e., from ros2_tracing
) in Trace Compass (like Figures 4 and 5 in this paper). You could then compare the flame charts of your functions to your subscription/timer callbacks, etc., e.g., by looking at the results side by side in Trace Compass. However, this is not all easily available yet. You could try to build Trace Compass yourself if you (really) wanted to, see: https://github.com/christophebedard/ros2-message-flow-analysis#analysis. Eventually you'll be able to download Trace Compass and install this feature, though.
Otherwise, if you create your own instrumentation, then you'll need to do the data analysis yourself (using tracetools_anlaysis
or by writing a custom Trace Compass plugin). This is why I recommend going the -finstrument-functions
way for your use-case here.
Hope that's useful. Let me know if you have any questions!
from ros2_tracing.
Thanks for the detailed reply Christophe! Looks really useful.
It will take me some time to familiarize myself with the tools and try this out. I'll let you know if I have any questions, but feel free to close this issue in the meantime.
from ros2_tracing.
Sounds good!
from ros2_tracing.
Related Issues (20)
- Clang warning
- Fix mypy test failures HOT 2
- Replace distutils.version.StrictVersion since distutils is deprecated
- Memory leak with tracetools::get_symbol()
- Process trace events into intermediate storage format HOT 4
- Destroy tracing session if it exists when tracing configuration fails
- Remove context_names parameter in Rolling
- Mention needing to start tracing before starting application
- Find solution to allow starting to trace from any point in time
- regression in build on macos HOT 1
- Provide non-interactive 'ros2 trace start/pause/resume/stop' commands HOT 1
- Proposal: move dds tracepoints to RWM layers HOT 1
- test_tracetools_launch tests causing GitHub CI to hang HOT 1
- Colcon build error after installation of ros2_tracing HOT 2
- rcl_init miss HOT 11
- Empty and partially-filled metadata files from trace HOT 4
- lttngpy fails to build on Windows Debug HOT 3
- Allow tracing tests to be run in parallel with tracing tests & normal tests
- Fix LTTng issue with `test_ros2trace` and `test_tracetools_launch` so that they can run tracing tests in parallel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ros2_tracing.