How to debug High CPU utilization in RoboRio running Java

When looking at the CPU utilization trace in the we are running, once teleop starts, we are running at 85-95% and often getting pegged at 100%. I was able to trace the day that this problem started occurring. Logs, prior to March 6th at 1:00pm show the CPU running 25-35% range. I looked at the code we introduced back around then from our github logs (https://github.com/LakerRobotics/FRC2016Stronghold/commits/DriveTrainNavigation?page=2) I found one oddity, corrected that but still the problem remains.

Normally at this point I would use a java profiling tool (jProfile or JVM Monitor are two I am currently looking at for this problem) but before I go figuring out how to install and get those working on the roborio, I was wondering if anybody else had any suggestions on how to track the issue down.

We are, for the most part, using Robot Builder generated code. The one unique thing is some custom Motion control PIDs. The motion Control PIDS is done by some awkward wrapping of the PIDSource, but this code was working before Feb 6th, and was not changed around Feb 6th.

Again any suggestions on how to proceed would be appreciated.

Thanks

The camera was added Feb 7. I bet that’s it.

We don’t use Java, but the camera adds some decent cpu usage. Try and lower the frame rate and resolution, or better yet, run it without the camera and see if it drops.

Thanks for pointing me the the camera, it helped.

We took the image to it’s smallest size and 1 Frame per second, and CPU dropped slightly. Now it is at about 90% to 100%, but importantly the driver control lag dropped and the functionality that was failing to work is now working again (e.g. the drive straight button). So it seems that there is something other then the camera still hogging the CPU.

We have Image processing code we hope to turn on to align to the goal, but I don’t see anyway that the images could possibly be processed if we are always at 90% to 100% CPU.

One thing that has improved or become obvious is that the CPU only goes high while in Teleop, otherwise it is around 35%.

We had to spend time tuning the controls and other things today at day 1 of the tournament, but this is going to be the number one thing to work on very soon.

Are you guys displaying a lot of values on SmartDashboard? I’ve heard from a few other teams that displaying many values (75+) can peg your CPU at 90%+
If you are, try reducing the number of values and see if that helps.

Are any of your functions running in a separate thread? If you have many threads running at once, or threads running quickly, you can get CPU problems. We had a CPU problem at our last competition that was solved by removing a thread that no longer had any code running within it, so it was running over and over again within the main operator control loop, moving very quickly and using lots of CPU, but without carrying out any useful robot function.

*Load the code that was running prior to the appearance of the problem to confirm that the problem goes away.