08-17-2012 05:03 PM
Ok,
I have a problem. And, this problem seems to be persistent with almost every project at almost every company that I have ever worked at.
When it comes time for code clean up how do you check to see if elements in a cluster has ever been accessed?
Many times we have a typedef for a cluster, but as the project evolved we changed how we use some of the values in the cluster, or just don't use them at all.
The VI Analyzer has helped greatly in finding orphaned code and other issues, but I don't think it helps at all for elements never accessed in a cluster. Or, at least I've never seen a failed test indicating that it found an issue.
Some of these clusters are very large and used in many different VIs. I really don't want to use a check list to figure out if an element was accessed.
Any ideas????
08-19-2012 11:25 PM - edited 08-19-2012 11:27 PM
I'm totally guessing because frankly I am not sure. But if there is not a tool already available to do it you could possibly write your own with scripting. I don't know if the functionality is available that you'd need, but basically you could get references to all the "unbundles" in the project that have the cluster type you're looking for as the left node. Then check all the nodes coming out of the unbundle and check to see if they have a wire attached. If they do, get the name of the element that's unbundled and build an array of these names. Then compare it to the names of the elements in your cluster and see which ones in your cluster aren't found in the array of names you just built. This could get a bit trickier if you have clusters of clusters that you unbundle because you just want to grab the top level cluster, you don't care about the nested ones, even if those are the ones that are unbundled in your code.
Again, I don't know if this is possible, but it's just a thought on how you could do it. I know writing your own tools can be somewhat time consuming, especially if you aren't familiar with scripting. But, it sounds like you want to do this often enough that it makes taking the time to write a tool worth it (if one doesn't arleady exist).
08-20-2012 07:51 AM
@MrQuestion wrote:
Ok,
...
Some of these clusters are very large and used in many different VIs. I really don't want to use a check list to figure out if an element was accessed.
Any ideas????
You may have no choice.
One way of finding all refs to a cluster element is to edit the type def and change it's data type to something that ould break the code. String to numeric etc. Apply the changes and look to see if the code breaks. If it does it is used. If it does not break, then it is un-used.
There was a philosophy from back in the day of machine language programming that said "Never remove, only replace." You may be better off leaving the unused values as they are.
Ben
08-20-2012 09:09 AM
This seems like something that VI Analyzer should catch?
I could write a script and add it as a custom test to VI Analyzer, but I tend to get lost pretty fast when it comes to the many methods available.
Am I one of the few who ever wanted to do this?
08-20-2012 09:22 AM
@MrQuestion wrote:
Am I one of the few who ever wanted to do this?
Probably not. You should post something on the idea exchange.
08-20-2012 10:13 AM
I'd argue that if you have a cluster, then technically nothing in it is ever unused. Even if you never unbundle a particular element from it to use it individually, you are almost certainly passing a cluster in its entirety from one VI to another. So the cluster as a single entity is being used. There is no way you could write code that would allow LabVIEW to determine whether you use a particular element or not.
08-20-2012 11:20 AM
The script would have to be recursive to break down through all of the VIs to see if all particular elements are used. It is true that the cluster would be used, so the script would have to be smart enough to keep track of the read and writes of each element within a VI.
A dictonary function or relational database function would need to be implimented, and then post processed.
08-20-2012 11:41 AM
Why would you have to use a database? I'm sure you don't have so many instances that a simple build array in a recursive VI call would run you out of memory.
08-20-2012 12:12 PM
@MrQuestion wrote:
The script would have to be recursive to break down through all of the VIs to see if all particular elements are used. It is true that the cluster would be used, so the script would have to be smart enough to keep track of the read and writes of each element within a VI.
A dictonary function or relational database function would need to be implimented, and then post processed.
Yes. But I'm saying there could be circumstances where a particular element can be considered to be used by the programmer, but possibly is never written to or read from as an individual element. So how would the LV script be smart enough to make that distincition? I'm not sure if I've ever had that exact situation. But perhaps a case where you do a flatten to string to pass the cluster to file to be stored would qualify.
08-20-2012 12:22 PM
@for(imstuck) wrote:
Why would you have to use a database? I'm sure you don't have so many instances that a simple build array in a recursive VI call would run you out of memory.
You wouldn't have to. But, if such a feature was to be implemented in the VI Analyzer I can see where it would greatly benefit additional reporting capability. For example an element that is only written and never read, or an element that is read and never written. It would be easy to do a post analysis on a data set and extract names and locations from the data store.
The build array would work as well, but I would think that it would be limiting additional expandability when only a little additional more coding would open you up to more capabilities.