Git Product home page Git Product logo

Comments (3)

christophebedard avatar christophebedard commented on July 22, 2024

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.

Seangottarun avatar Seangottarun commented on July 22, 2024

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.

christophebedard avatar christophebedard commented on July 22, 2024

Sounds good!

from ros2_tracing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.