08-13-2012 03:06 PM
Hi all -
I've been working on a tool to analyze the compiled code complexity for VIs in a project/directory. (this is a new feature in LabVIEW 2012) I've attached the tool below. There are two steps to use it:
The front panel of "analyze complexities.vi" looks something like this:
On the bottom is a histogram of code complexities. Above that are some statistics (the most interesting being how many VIs were only compiled with partial optimizations), and to the right are all the VIs sorted in descending order of code complexity, so you can easily see the biggest ones. It also finds VIs that could be inlined and have a low complexity, and shows them under "VIs to consider inlining".
I think this will be useful for larger projects for informational purposes, to find VIs that are "too big" and not being compiled with full optimizations, and finding VIs that are good candidates for inlining.
I'd be happy to answer any questions about the tool!
Greg Stoll
LabVIEW R&D
National Instruments
08-14-2012 10:01 AM
A user noticed some errors when closing VIs in the gather phase. Here's a new version of the code.
Greg Stoll
LabVIEW R&D
08-14-2012 10:51 AM
@gregstoll wrote:
...
Greg Stoll
LabVIEW R&D
Hi Greg,
No traffic on posts like this generally means we don't get it.
I'll play along.
If I have been writting code for years that works fine and runs fast, why is this of any interest to me?
What is my motivation?
Ben
08-14-2012 11:03 AM
Fair enough - I'll do my best to motivate it 🙂
If you have VI's with code complexity greater than 5, then that means
- they're not being compiled with full compiler optimizations, so they'll run slower than they could
- they're big and probably good candidates for refactoring
If you have VI's with very small code complexity, they're probably good candidates for inlining, which will make them run faster.
This project will help you find VI's in both categories. (I'm into numbers, so I love the graph of the frequency of code complexities, but it's not that useful)
08-23-2012 04:53 AM
Greg,
while i appreciate your effort, i would expect such features to be part of the VI Analyzer. In fact, inlinability (does this word exist at all?) is already tested with VI Analyzer:
So do you think it will be possible to integrate your effort for the compiler optimization analysis into VI Analyzer for e.g. 2012 SP1?
Norbert
08-23-2012 11:10 AM
Hi Norbert -
I chatted with Darren about this, and we decided that the tests that already exist in VI Analyzer make more sense, especially the "Complexity Metrics" ones since they call out specific things you can do to simplify your VI. I will admit I didn't know there was an "Inlinable VIs" test...somehow I missed that.
08-24-2012 02:21 AM
Greg,
but VI Analyzer does not (at least, i am not aware of it) tell you what compiler optimization level was used for the individual VI. I think this could be valuable information, too. And i understand that your tool does test this 😉
Norbert
04-12-2017 06:21 AM
Hi Greg,
Very late to the party here, we're going to be discussing this at our next user group.
I'm interested in what LabVIEW considers complex (rather than the VI Analyzer metrics). Is there a white paper on how this number is calculated?
Many thanks for the tool.
Steve
Steve
Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop
04-12-2017 09:56 AM
Well here's several links a google search turned up.
http://www.ni.com/white-paper/3324/en/
http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/code_complexity/
http://www.ni.com/white-paper/3588/en/
http://zone.ni.com/reference/en-XX/help/371361K-01/lvvianalyzerhelp/complexity_metrics_tests/
http://zone.ni.com/reference/en-XX/help/371361K-01/lvvianalyzerhelp/vi_metrics_tests/
I don't think LabVIEW determines what is complex, only how complex is some code. Only a human can determine what is too complex, or possibly a human setting some limit for software. Does it have code smell? Its probably too complex. But since it is a subjective test, two developers may disagree on what is too complex, which is why counting the number of nodes, or number of branches, can put a value on the complexity of software.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-12-2017 10:07 AM
Thanks Matey,
I'm not so much interested in code complexity from a VI analyzer, or even a human point of view. I'm interested in the algorithm used to calculate it from the compilers point of view. Or maybe they're the same.
So it's specifically how this number is calculated.
I'll do some tests with VI Analyzer too.
Steve
Steve
Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop