LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiled Code Complexity analyzer tool for LV 2012

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:

  • Gathering the complexities: under gather complexities.lvlib, run one of "gather from directory or llb.vi", "gather from project.vi", or "gather from projects.vi" and specify where to read the VIs from and where to put the output.  This will generate a series of text files, one per subdirectory.
  • Analyzing the complexities: under analyze complexities.lvlib, run "analyze complexities.vi" and point it at the directory with the text files in it.

The front panel of "analyze complexities.vi" looks something like this:

analyze complexities front panel.png

 

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

Greg Stoll
LabVIEW R&D
Message 1 of 18
(5,840 Views)

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

Greg Stoll
LabVIEW R&D
Message 2 of 18
(5,754 Views)

@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

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 18
(5,735 Views)

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)

Greg Stoll
LabVIEW R&D
Message 4 of 18
(5,725 Views)

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:

VIAnalyzer_Inline.PNG 

 

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 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 5 of 18
(5,586 Views)

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.

Greg Stoll
LabVIEW R&D
0 Kudos
Message 6 of 18
(5,567 Views)

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 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 7 of 18
(5,545 Views)

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


Random Ramblings Index
My Profile

0 Kudos
Message 8 of 18
(4,734 Views)

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.

0 Kudos
Message 9 of 18
(4,724 Views)

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.

 

CompiledCodeComplexity.png

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


Random Ramblings Index
My Profile

0 Kudos
Message 10 of 18
(4,721 Views)