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