Motivation: ros_ign_bridge is failing to build in the ROS 2 packaging farm because the memory usage of template instantiation is too high. Specifically, the ros_subscriber is problematic.
Approach: Use templight to debug how much cpu/memory template expansion is taking
Templight itself is hosted on github: https://github.com/mikael-s-persson/templight The issue is that it may not exactly line up with clang/llvm versions, and their patching seems to be hit or miss.
To make the installation easier, I followed the metashell instructions, as templight is a component of it. I followed: http://metashell.org/develop/build/index.html
Roughly:
git clone https://github.com/metashell/metashell
cd metashell
./install_build_dependencies.sh
mkdir -p "bin/$(tools/detect_platform.sh --id)"
cd bin/ubuntu20.04_x86_64/
mkdir templight
cd templight
cmake ../../../3rd/templight/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_PROJECTS=clang
make clang libclang templight
cd ..
mkdir metashell
cd metashell
cmake ../../..
make
sudo make install
This installs clang-12, metashell, and templight into /usr/local/bin
. Could potentially clobber other stuff, but oh well.
You need the converter to get their format into something digestable by other tools: https://github.com/mikael-s-persson/templight-tools
There is a broken regex that makes blacklist not work, I fixed that in my branch: https://github.com/mjcarroll/templight-tools
Roughly:
git clone https://github.com/mjcarroll/templight-tools
make
You should have bin/templight-converter
I use a colcon defaults.yaml file.
To use it with templight, I did:
{
"build": {
"merge-install": true,
"cmake-args": [
"--no-warn-unused-cli",
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
"-DCMAKE_CXX_COMPILER=templight++",
"-DCMAKE_CXX_FLAGS=-Xtemplight -profiler -Xtemplight -memory -Xtemplight -ignore-system",
"-DCMAKE_C_COMPILER=templight",
]
},
"test": {
"merge-install": true,
}
}
Do a normal colcon build. This expands the build time, so I would focus on what you are trying to diagnose.
At the end, you should get a pbf
file per translation unit
You probably want a blacklist file to filter out stuff you don't want, it's a regex based on context or identifier
What I used for ros_ign:
# Filter out anything coming from the std namespace:
context ^std(::|$)
# Filter out anything coming from gtest:
context ^testing(::|$)
context __gnu_cxx
identifier anonymous
There are also multiple filetypes supported, by kcachegrind makes the most sense.
Invocation:
./bin/templight-convert ~/workspaces/mbzirc/build/ros_ign_bridge/CMakeFiles/test_ros_subscriber.dir/test/subscribers/ros_subscriber.cpp.o.memory.trace.pbf --blacklist=./blacklist.txt -f callgrind > ros_subscriber.callgrind