Back to home page

LXR

 
 

    


0001 #!/usr/bin/perl
0002 
0003 # Read two files produced by the stackusage script, and show the
0004 # delta between them.
0005 #
0006 # Currently, only shows changes for functions listed in both files. We
0007 # could add an option to show also functions which have vanished or
0008 # appeared (which would often be due to gcc making other inlining
0009 # decisions).
0010 #
0011 # Another possible option would be a minimum absolute value for the
0012 # delta.
0013 #
0014 # A third possibility is for sorting by delta, but that can be
0015 # achieved by piping to sort -k5,5g.
0016 
0017 sub read_stack_usage_file {
0018     my %su;
0019     my $f = shift;
0020     open(my $fh, '<', $f)
0021     or die "cannot open $f: $!";
0022     while (<$fh>) {
0023     chomp;
0024     my ($file, $func, $size, $type) = split;
0025     # Old versions of gcc (at least 4.7) have an annoying quirk in
0026     # that a (static) function whose name has been changed into
0027     # for example ext4_find_unwritten_pgoff.isra.11 will show up
0028     # in the .su file with a name of just "11". Since such a
0029     # numeric suffix is likely to change across different
0030     # commits/compilers/.configs or whatever else we're trying to
0031     # tweak, we can't really track those functions, so we just
0032     # silently skip them.
0033     #
0034     # Newer gcc (at least 5.0) report the full name, so again,
0035     # since the suffix is likely to change, we strip it.
0036     next if $func =~ m/^[0-9]+$/;
0037     $func =~ s/\..*$//;
0038     # Line numbers are likely to change; strip those.
0039     $file =~ s/:[0-9]+$//;
0040     $su{"${file}\t${func}"} = {size => $size, type => $type};
0041     }
0042     close($fh);
0043     return \%su;
0044 }
0045 
0046 @ARGV == 2
0047     or die "usage: $0 <old> <new>";
0048 
0049 my $old = read_stack_usage_file($ARGV[0]);
0050 my $new = read_stack_usage_file($ARGV[1]);
0051 my @common = sort grep {exists $new->{$_}} keys %$old;
0052 for (@common) {
0053     my $x = $old->{$_}{size};
0054     my $y = $new->{$_}{size};
0055     my $delta = $y - $x;
0056     if ($delta) {
0057     printf "%s\t%d\t%d\t%+d\n", $_, $x, $y, $delta;
0058     }
0059 }