Abstract: Understand’s Python API makes it a great platform for creating quick tools to explore exactly what you are interested in. In this case, I was curious if a default parameter was ever set to a non-default value or if a given parameter is always the same value. Check out these two custom interactive reports that show parameter values for each call.
[Editor’s note: The original version of this article was lost last week due to a server crash and backup issues. The offending parties were punished by being denied caffeine for
12 4 hours.]
Hmm, I can’t remember how this article originally started. It’s probably revenge for when I erased Kevin’s whiteboard and told him that if he drew it once he could draw it again. But I’m sure it was something along the lines of me wanting to detect parameters whose value is always the same and why it mattered. Parameter lists seem to get long enough without cluttering them with a bunch of constant values.
So, how do you know if a parameter is always the same? Well, I check by visiting every call reference listed in the information browser to see what value was passed in.
But, the great thing about Understand is it can automate tasks like this. An interactive report (ireport) is a Python or Perl script run through the Understand GUI. It allows you to not only use our API to generate the information you want but also display the information in a way that syncs with other Understand windows.
I want to know the parameters at each call reference. So, my ireport will have parameter names as the columns and a call reference for each row. Unfortunately, the ireport view is designed for trees and not tables, so my columns don’t line up. But the separator is configurable. The default value is tab separated for easy copy-pasting into Microsoft Excel. I’ll test it with a function from the sample project GitAhead, git::Commit::diff.
It looks like none of the parameters are dead. The second call changes the commit, the first call changes the context lines, and all the calls use a non-default value for ignoring whitespace. Because the display is through Understand, I can right-click on the blue links to get the entity context menu and I can click on line numbers to open the location in the editor.
Calls by Parameter Value
Still, the non-aligned columns aren’t ideal. If I copy the values into a spreadsheet then I lose the links. So, I’ll make a second interactive report to look at a specific parameter. Then I can group the calls by the value of my selected parameter.
In the display, ignoreWhitespace appears three times because it’s a different entity each time. As before, I can right-click on entities to get more information and left-click on line numbers to jump to the reference. I can also see when the default value was used. For example, with git::Commit::summary(), the options parameter:
Looking for more awesome scripts? Check out our plugins repository.