stackdelta 1.8 KB

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