VI Analyzer Enthusiasts Documents

Showing results for 
Search instead for 
Did you mean: 

Test - Duplicate Code

VI Analyzer test to find duplicated code

Will search through VIs and find ones that "look the same"  (basically you copied the VI and then made little to no changes to it)

Duplicate Code utility:

First, a few disclaimers.

Written in LV2012.  Expect it would work fine in newer versions, but have not tried.

This is very much a proof of concept and a work in progress.  It is by no means optimized, or well architected, or anything like that.  But it does mostly work, and it is useful.

That being said, I very much do want suggestions, ideas, thoughts, criticism, etc.

This is intended to flag code that is similar or duplicated and alert the user.  stuff that is called "100" duplicate may not exactly be 100% identical -- it is just very highly similar.  If you are concerned about exactness, use LabVIEWs built in diff utilities. 

This tool is written to concentrate on code that looks functionally similar that could be consolidated for reuse.... not specifically exactly identical. In industry terminology, this is really "Clone Detection", but clone means other stuff with respect to reentrant executions in LabVIEW, so terminology was changed to similar or duplicate code.

Right now this will detect duplicated code at the VI level.  (how similar is this VI to any other).  There are beginnings of ability to analyze subsets within a VI to subsets within another VI, but those are not completed yet. 

There are some limitations when used within VI Analyzer that only allow duplication to be found in one direction ( is similar to, but it will not flag as similar to -- argue whether this is a bug or feature)

Yes, there are issues with finding lots of "accessor" method VIs that are all almost identical.  you can exception these out in your VI analyzer configuration file.  Or let me know if you have good ideas of how to programatically understand this situation and remove them from the list.

Yes there are issues with UI sucks and not optimized, but before spending a lot of time making it nice, I wanted to find out exactly how useful this will be, and then spend time as appropriate.  Or if you are interested in volunteering effort.....

What is included:


This contains all the code needed to run as a VI Analyzer test, and a separate standalone UI. is the VI Analyzer entrypoint (as per the VI Analyzer API definition). is the "hack" of a UI for this utility.  It is NOT a top level VI because that would break VI Analyzer integration (and I wanted everything together in one llb) is a test case setup to validate the VI Analyzer stuff.

For using as VI Analyzer, just add DuplicateCode.lvlib in place like any other VI Analyzer test.

For configuration-

SimilarityRank is the threshold for when it calls 2 items duplicated or similar.  100 is "exact", 0 is completly different.  In use, something around 97 or 98 seems to work well.

Ignore items larger than # nodes, ignore items larger than # bytes:  negative or 0 values turn these off.  In general we found that it is best (for performance purposes) to ignore code that is "large".  It is likely not a good candidate for being useful as consolidating to reuse library, and huge VIs are less likely to be copied and left alone

Other locations to compare against: what other files/folders we want to check for duplicates against.  We will always check for duplicates within the analyzer target files, but we will also find duplicates between our analyzer target files and items in the "other locations to compare against"  (duplicate items in the other locations to comapare against will not be found unless they duplicate items in the analylsis targets)

For using as a standalone item -- Open/run

In the configure tab, things should follow pretty similar to configuration as specified in VI Analyzer usage.  Remember that we have compare within and compare against lists.  We will find duplicates internal to the "compare within" and between "compare within" and "compare against", but will ignore duplicates within the "compare against" locations.

Execute tab: click go, and wait and watch.

Will switch over to results tab and allow you to sort, and then select VIs to open.

Thoughts/ideas/comments/future considerations welcome.