15bbb9f75SRasmus Villemoes#!/usr/bin/perl 25bbb9f75SRasmus Villemoes 35bbb9f75SRasmus Villemoes# Read two files produced by the stackusage script, and show the 45bbb9f75SRasmus Villemoes# delta between them. 55bbb9f75SRasmus Villemoes# 65bbb9f75SRasmus Villemoes# Currently, only shows changes for functions listed in both files. We 75bbb9f75SRasmus Villemoes# could add an option to show also functions which have vanished or 85bbb9f75SRasmus Villemoes# appeared (which would often be due to gcc making other inlining 95bbb9f75SRasmus Villemoes# decisions). 105bbb9f75SRasmus Villemoes# 115bbb9f75SRasmus Villemoes# Another possible option would be a minimum absolute value for the 125bbb9f75SRasmus Villemoes# delta. 135bbb9f75SRasmus Villemoes# 145bbb9f75SRasmus Villemoes# A third possibility is for sorting by delta, but that can be 155bbb9f75SRasmus Villemoes# achieved by piping to sort -k5,5g. 165bbb9f75SRasmus Villemoes 175bbb9f75SRasmus Villemoessub read_stack_usage_file { 185bbb9f75SRasmus Villemoes my %su; 195bbb9f75SRasmus Villemoes my $f = shift; 205bbb9f75SRasmus Villemoes open(my $fh, '<', $f) 215bbb9f75SRasmus Villemoes or die "cannot open $f: $!"; 225bbb9f75SRasmus Villemoes while (<$fh>) { 235bbb9f75SRasmus Villemoes chomp; 245bbb9f75SRasmus Villemoes my ($file, $func, $size, $type) = split; 255bbb9f75SRasmus Villemoes # Old versions of gcc (at least 4.7) have an annoying quirk in 265bbb9f75SRasmus Villemoes # that a (static) function whose name has been changed into 275bbb9f75SRasmus Villemoes # for example ext4_find_unwritten_pgoff.isra.11 will show up 285bbb9f75SRasmus Villemoes # in the .su file with a name of just "11". Since such a 295bbb9f75SRasmus Villemoes # numeric suffix is likely to change across different 305bbb9f75SRasmus Villemoes # commits/compilers/.configs or whatever else we're trying to 315bbb9f75SRasmus Villemoes # tweak, we can't really track those functions, so we just 325bbb9f75SRasmus Villemoes # silently skip them. 335bbb9f75SRasmus Villemoes # 345bbb9f75SRasmus Villemoes # Newer gcc (at least 5.0) report the full name, so again, 355bbb9f75SRasmus Villemoes # since the suffix is likely to change, we strip it. 365bbb9f75SRasmus Villemoes next if $func =~ m/^[0-9]+$/; 375bbb9f75SRasmus Villemoes $func =~ s/\..*$//; 385bbb9f75SRasmus Villemoes # Line numbers are likely to change; strip those. 395bbb9f75SRasmus Villemoes $file =~ s/:[0-9]+$//; 405bbb9f75SRasmus Villemoes $su{"${file}\t${func}"} = {size => $size, type => $type}; 415bbb9f75SRasmus Villemoes } 425bbb9f75SRasmus Villemoes close($fh); 435bbb9f75SRasmus Villemoes return \%su; 445bbb9f75SRasmus Villemoes} 455bbb9f75SRasmus Villemoes 465bbb9f75SRasmus Villemoes@ARGV == 2 475bbb9f75SRasmus Villemoes or die "usage: $0 <old> <new>"; 485bbb9f75SRasmus Villemoes 495bbb9f75SRasmus Villemoesmy $old = read_stack_usage_file($ARGV[0]); 505bbb9f75SRasmus Villemoesmy $new = read_stack_usage_file($ARGV[1]); 515bbb9f75SRasmus Villemoesmy @common = sort grep {exists $new->{$_}} keys %$old; 525bbb9f75SRasmus Villemoesfor (@common) { 535bbb9f75SRasmus Villemoes my $x = $old->{$_}{size}; 545bbb9f75SRasmus Villemoes my $y = $new->{$_}{size}; 555bbb9f75SRasmus Villemoes my $delta = $y - $x; 565bbb9f75SRasmus Villemoes if ($delta) { 575bbb9f75SRasmus Villemoes printf "%s\t%d\t%d\t%+d\n", $_, $x, $y, $delta; 585bbb9f75SRasmus Villemoes } 595bbb9f75SRasmus Villemoes} 60