I've wanted to play with B::Utils for a while, so I wrote a little op code counter. I'm not drawing any conclusions from their counts, though:
#!/usr/bin/perl -w
use strict;
require B::Utils;
die "Specify some modules on the command line\n" unless @ARGV;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Load the modules
my %Modules = ();
foreach my $module ( @ARGV )
{
$Modules{ $module }++;
eval "require $module";
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Get all the roots, but delete the ones not under our namespaces
my %op_roots = B::Utils::all_roots();
# there may be sub-modules, so match on their root name
my $regex =
'^('.
join( "|", map quotemeta($_), keys %Modules ).
')';
foreach my $key ( keys %op_roots )
{
next if $key =~/$regex/;
delete $op_roots{ $key };
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Count the opcodes in the remaining roots
my %op_codes = ();
foreach my $key ( keys %op_roots )
{
B::Utils::walkoptree_simple(
$op_roots{ $key },
sub { $op_codes{ $key }++ }
);
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Display the reports
print "Reporting for @ARGV\n\n";
print " OpCodes | Function\n";
print "-" x 9, "|", "-" x 63, "\n";
foreach( sort { $op_codes{$b} <=> $op_codes{$a} } keys %op_roots )
{
printf " %7d | %s\n", $op_codes{$_}, $_;
}
print "-" x 73, "\n";
Counting Op Codes 0 Comments More | Login | Reply /