cb77f0d623ff3 (Kamil Rytarowski 2017-05-07 23:25:26 +0200 1) #!/usr/bin/env perl
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 2) # SPDX-License-Identifier: GPL-2.0
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 3)
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 4) # Read two files produced by the stackusage script, and show the
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 5) # delta between them.
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 6) #
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 7) # Currently, only shows changes for functions listed in both files. We
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 8) # could add an option to show also functions which have vanished or
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 9) # appeared (which would often be due to gcc making other inlining
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 10) # decisions).
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 11) #
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 12) # Another possible option would be a minimum absolute value for the
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 13) # delta.
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 14) #
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 15) # A third possibility is for sorting by delta, but that can be
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 16) # achieved by piping to sort -k5,5g.
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 17)
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 18) sub read_stack_usage_file {
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 19) my %su;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 20) my $f = shift;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 21) open(my $fh, '<', $f)
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 22) or die "cannot open $f: $!";
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 23) while (<$fh>) {
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 24) chomp;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 25) my ($file, $func, $size, $type) = split;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 26) # Old versions of gcc (at least 4.7) have an annoying quirk in
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 27) # that a (static) function whose name has been changed into
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 28) # for example ext4_find_unwritten_pgoff.isra.11 will show up
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 29) # in the .su file with a name of just "11". Since such a
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 30) # numeric suffix is likely to change across different
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 31) # commits/compilers/.configs or whatever else we're trying to
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 32) # tweak, we can't really track those functions, so we just
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 33) # silently skip them.
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 34) #
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 35) # Newer gcc (at least 5.0) report the full name, so again,
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 36) # since the suffix is likely to change, we strip it.
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 37) next if $func =~ m/^[0-9]+$/;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 38) $func =~ s/\..*$//;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 39) # Line numbers are likely to change; strip those.
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 40) $file =~ s/:[0-9]+$//;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 41) $su{"${file}\t${func}"} = {size => $size, type => $type};
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 42) }
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 43) close($fh);
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 44) return \%su;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 45) }
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 46)
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 47) @ARGV == 2
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 48) or die "usage: $0 <old> <new>";
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 49)
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 50) my $old = read_stack_usage_file($ARGV[0]);
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 51) my $new = read_stack_usage_file($ARGV[1]);
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 52) my @common = sort grep {exists $new->{$_}} keys %$old;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 53) for (@common) {
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 54) my $x = $old->{$_}{size};
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 55) my $y = $new->{$_}{size};
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 56) my $delta = $y - $x;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 57) if ($delta) {
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 58) printf "%s\t%d\t%d\t%+d\n", $_, $x, $y, $delta;
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 59) }
5bbb9f753afe2 (Rasmus Villemoes 2015-08-20 11:53:30 +0200 60) }