Last night we were trying to debug some loop overrun issues in our code. Nothing we had written seemed egregiously slow, so I suggested using a profiler to get a better picture of what was happening. It turned out that this was actually possible for JVM languages on the roboRIO!
I did some searching and found async-profiler, which seemed like a reasonable choice. The Linux/ARM binary linked in its README does not work on the roboRIO, so I cross-compiled a working one. You can download it here.
To use the profiler…
- Unzip it and SCP the
profiler
directory into the~admin
directory on the roboRIO. - SSH into the
admin
account on the roboRIO. - Set the kernel settings as described in async-profiler’s README.
- Find the process ID of your robot code with
ps aux | grep java
. - Put the robot into whatever conditions you want to profile (for us, this meant enabling teleop and letting it sit).
- Run the profiler! For some reason it wouldn’t write any output to files, but I was able to get it to output to stdout. Our command looked something like
~/profiler/profiler.sh -i 100us -d 30 -g -o tree <java process id> > ~/profile.html
. - SCP
~admin/profile.html
back to your computer for inspection.
Here’s one of the profiles we captured. There’s already some interesting takeaways and items to optimize in there, so I figured this sort of procedure would be useful to share with other teams. Happy optimizing!