Improve OK bot's symbol counting
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
use IPC::Cmd qw[ run ];
|
||||||
|
|
||||||
(@ARGV == 1)
|
(@ARGV == 1)
|
||||||
or die "ERROR: no map file specified.\n";
|
or die "ERROR: no map file specified.\n";
|
||||||
open(my $file, $ARGV[0])
|
open(my $file, $ARGV[0])
|
||||||
@@ -7,7 +9,6 @@ open(my $file, $ARGV[0])
|
|||||||
|
|
||||||
my $src = 0;
|
my $src = 0;
|
||||||
my $asm = 0;
|
my $asm = 0;
|
||||||
my $undocumented = 0;
|
|
||||||
while (my $line = <$file>)
|
while (my $line = <$file>)
|
||||||
{
|
{
|
||||||
if ($line =~ /^ \.(\w+)\s+0x[0-9a-f]+\s+(0x[0-9a-f]+) (\w+)\/.+\.o/)
|
if ($line =~ /^ \.(\w+)\s+0x[0-9a-f]+\s+(0x[0-9a-f]+) (\w+)\/.+\.o/)
|
||||||
@@ -28,19 +29,49 @@ while (my $line = <$file>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($line =~ /^\s+0x([0-9A-f]+)\s+[A-z_]+([0-9A-f]+)/) {
|
|
||||||
my $thing1 = sprintf("%08X", hex($1));
|
|
||||||
my $thing2 = sprintf("%08X", hex($2));
|
|
||||||
if($thing1 eq $thing2) {
|
|
||||||
$undocumented += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# It sucks that we have to objdump twice, but I can't figure out how to get
|
||||||
|
# stdin working for subcommands in perl while still having a timeout.
|
||||||
|
my $total_syms_as_string;
|
||||||
|
(run (
|
||||||
|
command => "arm-none-eabi-nm pokeemerald.elf | wc -l",
|
||||||
|
buffer => \$total_syms_as_string,
|
||||||
|
timeout => 30
|
||||||
|
))
|
||||||
|
or die "ERROR: Error while getting all symbols: $?";
|
||||||
|
|
||||||
|
my $undocumented_as_string;
|
||||||
|
(run (
|
||||||
|
command => "arm-none-eabi-nm pokeemerald.elf | grep \"Unknown_\\|sub_\" | wc -l",
|
||||||
|
buffer => \$undocumented_as_string,
|
||||||
|
timeout => 30
|
||||||
|
))
|
||||||
|
or die "ERROR: Error while filtering for undocumented symbols: $?";
|
||||||
|
|
||||||
|
my $undocumented = $undocumented_as_string + 0;
|
||||||
|
(($undocumented != 0) and ($undocumented_as_string ne "0"))
|
||||||
|
or die "ERROR: Cannot convert string to num: '$undocumented_as_string'";
|
||||||
|
|
||||||
|
my $total_syms = $total_syms_as_string + 0;
|
||||||
|
(($total_syms != 0) and ($total_syms_as_string ne "0"))
|
||||||
|
or die "ERROR: Cannot convert string to num: '$total_syms_as_string'";
|
||||||
|
|
||||||
|
($total_syms != 0)
|
||||||
|
or die "ERROR: No symbols found.";
|
||||||
|
|
||||||
my $total = $src + $asm;
|
my $total = $src + $asm;
|
||||||
my $srcPct = sprintf("%.4f", 100 * $src / $total);
|
my $srcPct = sprintf("%.4f", 100 * $src / $total);
|
||||||
my $asmPct = sprintf("%.4f", 100 * $asm / $total);
|
my $asmPct = sprintf("%.4f", 100 * $asm / $total);
|
||||||
|
|
||||||
|
my $documented = $total_syms - $undocumented;
|
||||||
|
my $docPct = sprintf("%.4f", 100 * $documented / $total_syms);
|
||||||
|
my $undocPct = sprintf("%.4f", 100 * $undocumented / $total_syms);
|
||||||
|
|
||||||
print "$total total bytes of code\n";
|
print "$total total bytes of code\n";
|
||||||
print "$src bytes of code in src ($srcPct%)\n";
|
print "$src bytes of code in src ($srcPct%)\n";
|
||||||
print "$asm bytes of code in asm ($asmPct%)\n";
|
print "$asm bytes of code in asm ($asmPct%)\n";
|
||||||
print "$undocumented global symbols undocumented\n";
|
print "\n";
|
||||||
|
print "$total_syms total symbols\n";
|
||||||
|
print "$documented symbols documented ($docPct%)\n";
|
||||||
|
print "$undocumented symbols undocumented ($undocPct%)\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user