Profiling ROS Nodes
Here is a guide for one effective method for profiling the performance of ROS nodes. It uses valgrind to count the number of calls to every function and the amount of time spent in each call, and uses KCacheGrind to visualize and explore this data in a nice GUI.
Note: any usage of profilers and code analysis tools like valgrind, gdb, etc require building with debug symbols.
catkin_make in default configuration (DEBUG) has debug symbols but also has many optimizations turned off.
sudo apt install valgrind kcachegrind
Usage with rosrun:
valgrind --tool=callgrind --callgrind-out-file=/path/to/file rosrun pkg node kcachegrind /path/to/file
Usage with roslaunch:
<node pkg="pkg" type="type" name="name" launch-prefix="valgrind --tool=callgrind --callgrind-out-file='/path/to/file'"/>