diff options
author | Jeff Morriss <jeff.morriss@ulticom.com> | 2012-02-08 14:15:01 +0000 |
---|---|---|
committer | Jeff Morriss <jeff.morriss@ulticom.com> | 2012-02-08 14:15:01 +0000 |
commit | e8ff75961f65a92c50e1e8c9ed82355cb1db77ab (patch) | |
tree | 6a871f98d8da386bfeecde6771e67539852a05cb /tools/checkAPIs.pl | |
parent | 6a33236a0d8cd4e3c85be095930ce9259c93c419 (diff) |
As suggested by Joerg on the -dev list yesterday: count up the number of
proto_tree_add_text() calls and compare that to the number of
proto_tree_add_<something else>() calls and complain if more than 50%
of the calls are add_text()'s.
proto_tree_add_text() calls whose returned proto_item is used are not counted
as hanging a subtree off a text item is an appropriate use for text items.
I chose 50% because even at that level there are many dissectors with "too many"
proto_tree_add_text()'s.
The function to do all of this is commented out for now for the same reason
plus the fact that it's pretty slow.
svn path=/trunk/; revision=40930
Diffstat (limited to 'tools/checkAPIs.pl')
-rwxr-xr-x | tools/checkAPIs.pl | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index 6ba8736805..fd469eb5cb 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -1303,6 +1303,43 @@ sub findAPIinFile($$$) } } +sub checkAddTextCalls($$) +{ + my ($fileContentsRef, $filename) = @_; + my $add_text_count = 0; + my $okay_add_text_count = 0; + my $add_xxx_count = 0; + + # First count how many proto_tree_add_text() calls there are in total + while (${$fileContentsRef} =~ m/ \W* proto_tree_add_text \W* \( /gox) { + $add_text_count++; + } + # Then count how many of them are "okay" by virtue of their generate proto_item + # being used (e.g., to hang a subtree off of) + while (${$fileContentsRef} =~ m/ \W* [a-zA-Z0-9]+ \W* = \W* proto_tree_add_text \W* \( /gox) { + $okay_add_text_count++; + } + # Then count how many proto_tree_add_*() calls there are + while (${$fileContentsRef} =~ m/ \W proto_tree_add_[a-z]+ \W* \( /gox) { + $add_xxx_count++; + } + + #printf "add_text_count %d, okay_add_text_count %d\n", $add_text_count, $okay_add_text_count; + $add_xxx_count -= $add_text_count; + $add_text_count -= $okay_add_text_count; + + # Don't bother with files with small counts + if ($add_xxx_count < 10 || $add_text_count < 10) { + return; + } + + my $percentage = 100*$add_text_count/$add_xxx_count; + if ($percentage > 50) { + printf "%s: found %d useless add_text() vs. %d add_<something else>() calls (%.2f%%)\n", + $filename, $add_text_count, $add_xxx_count, $percentage; + } +} + # APIs which (generally) should not be called with an argument of tvb_get_ptr() my @TvbPtrAPIs = ( # Use NULL for the value_ptr instead of tvb_get_ptr() (only if the @@ -1668,11 +1705,12 @@ while ($_ = $ARGV[0]) } #checkAPIsCalledWithTvbGetPtr(\@TvbPtrAPIs, \$fileContents, \@foundAPIs); - #if (@foundAPIs) { # print STDERR "Found APIs with embedded tvb_get_ptr() calls in ".$filename.": ".join(',', @foundAPIs)."\n" #} + #checkAddTextCalls(\$fileContents, $filename); + # Brute force check for value_string arrays which are missing {0, NULL} as the final (terminating) array entry if ($check_value_string_array_null_termination) { # Assumption: definition is of form (pseudo-Regex): |