Our team noticed an issue this year where our cpu percentage throughout matches or even normal driving are all 95+% which we think is bad. Is there any way to check in labview which threads are taking up the most cpu. We think that there’s a loop somewhere without a wait block so that’s taking up all the cpu or our code is not optimized very well…
In a way. With the default project NI supplies a vi called Elapsed Times.vi found under the Support Code folder in your project.
It displays the amount of time any loop you choose to measure takes to execute.
Just drop that vi into each of your loops, each occurrence will take an input of a unique name so you can tell them apart.
Open the front panel of Elapsed Times.vi, then open Robot Main to run in debug mode and you can see the times each loop takes.
See attached example where the Teleop loop is running too slowly, e.g., 21ms when it should always complete faster than 20ms.
That said, often the cause of maxed CPU is due to unconstrained loops.
Elapsed Times won’t highlight that particular problem without a little understanding, essentially look for loops that are executing with close to 1ms timing (way too fast for most code).
Every loop left to itself, will execute as fast and as often as physically possible unless you actively prevent it.
That’s why in the default Periodic Tasks.vi loops, they are each constrained using a Wait call.
You must have a wait call in each of your loops if they go on a long time or execute often.