-
Notifications
You must be signed in to change notification settings - Fork 2
Profiling
Sebastian Mai edited this page Apr 28, 2021
·
1 revision
If you want to measure the performance of a ROS2 python node you can use the following procedure.
- Create a profile and save it in a file
- Visualise the profile with
snakeviz
(which you can install with pip3)
To gather the performance of a node you can use cProfile: https://docs.python.org/3/library/profile.html You can either create a profile within your code like this:
import cProfile
profile = cProfile()
profile.enable()
# do stuff
profile.disable()
profile.dump_stats("FILENAME")
or by profiling the whole execution of the node by including the following line in the launch file:
Node(
package='...',
executable='...',
prefix=f"python3 -m cProfile -o FILENAME",
namespace=...,
...)
The profile can be viewed by calling snakeviz -s FILENAME
on the command line. The program will create a webserver and serve a website where the data is shown. To get to the website follow the link given in the command-line.