Profiling ROS Nodes

From RoboJackets Wiki
Revision as of 15:55, 19 September 2019 by Ebretl3 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.


Installation:

 sudo apt install valgrind kcachegrind


Profiling with rosrun:

 rosrun --prefix="valgrind --tool=callgrind --callgrind-out-file=outfile" pkg node
 kcachegrind outfile

Usage with roslaunch:

 foo.launch:
   <launch>
     <node pkg="a" type="a" name="a" launch-prefix="valgrind --tool=callgrind --callgrind-out-file=outfile"/>
   </launch>
 roslaunch foo.launch
 kcachegrind ~/.ros/outfile