All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Michal Marek <mmarek@suse.cz>
Cc: linux-kbuild@vger.kernel.org,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-kernel@vger.kernel.org
Subject: [RFC v2 4/4] scripts: add stackdelta script
Date: Thu, 25 Jun 2015 10:21:32 +0200	[thread overview]
Message-ID: <1435220492-15868-5-git-send-email-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <1435220492-15868-1-git-send-email-linux@rasmusvillemoes.dk>

This adds a simple perl script for reading two files as produced by
the stackusage script and computing the changes in stack usage. For
example:

$ scripts/stackusage -o /tmp/old.su CC=gcc-4.7 -j8 fs/ext4/
$ scripts/stackusage -o /tmp/new.su CC=gcc-5.0 -j8 fs/ext4/
$ scripts/stackdelta /tmp/{old,new}.su | sort -k5,5g

shows that gcc 5.0 generally produces less stack-hungry code than gcc
4.7. Obviously, the script can also be used for measuring the effect
of commits, .config tweaks or whatnot.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 scripts/stackdelta | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 scripts/stackdelta

diff --git a/scripts/stackdelta b/scripts/stackdelta
new file mode 100755
index 000000000000..4730dfa7780f
--- /dev/null
+++ b/scripts/stackdelta
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+# Read two files producesd by the stackusage script, and show the
+# delta between them.
+#
+# Currently, only shows changes for functions listed in both files. We
+# could add an option to show also functions which have vanished or
+# appeared (which would often be due to gcc making other inlining
+# decisions).
+#
+# Another possible option would be a minimum absolute value for the
+# delta.
+#
+# A third possibility is for sorting by delta, but that can be
+# achieved by piping to sort -k5,5g.
+
+sub read_stack_usage_file {
+    my %su;
+    my $f = shift;
+    open(my $fh, '<', $f)
+	or die "cannot open $f: $!";
+    while (<$fh>) {
+	chomp;
+	my ($file, $func, $size, $type) = split;
+	# Old versions of gcc (at least 4.7) have an annoying quirk in
+	# that a (static) function whose name has been changed into
+	# for example ext4_find_unwritten_pgoff.isra.11 will show up
+	# in the .su file with a name of just "11". Since such a
+	# numeric suffix is likely to change across different
+	# commits/compilers/.configs or whatever else we're trying to
+	# tweak, we can't really track those functions, so we just
+	# silently skip them.
+	#
+	# Newer gcc (at least 5.0) report the full name, so again,
+	# since the suffix is likely to change, we strip it.
+	next if $func =~ m/^[0-9]+$/;
+	$func =~ s/\..*$//;
+	# Line numbers are likely to change; strip those.
+	$file =~ s/:[0-9]+$//;
+	$su{"${file}\t${func}"} = {size => $size, type => $type};
+    }
+    close($fh);
+    return \%su;
+}
+
+@ARGV == 2
+    or die "usage: $0 <old> <new>";
+
+my $old = read_stack_usage_file($ARGV[0]);
+my $new = read_stack_usage_file($ARGV[1]);
+my @common = sort grep {exists $new->{$_}} keys %$old;
+for (@common) {
+    my $x = $old->{$_}{size};
+    my $y = $new->{$_}{size};
+    my $delta = $y - $x;
+    if ($delta) {
+	printf "%s\t%d\t%d\t%+d\n", $_, $x, $y, $delta;
+    }
+}
-- 
2.1.3


  parent reply	other threads:[~2015-06-25  8:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-21  1:10 [RFC 0/4] scripts: add stack{usage,delta} scripts Rasmus Villemoes
2015-06-21  1:10 ` [RFC 1/4] scripts: add stackusage script Rasmus Villemoes
2015-06-21  1:10   ` Rasmus Villemoes
2015-06-23 13:53   ` Michal Marek
2015-06-25  8:04     ` Rasmus Villemoes
2015-06-21  1:10 ` [RFC 2/4] .gitignore: add *.su pattern Rasmus Villemoes
2015-06-21  1:10   ` Rasmus Villemoes
2015-06-21  1:10 ` [RFC 3/4] kbuild: remove *.su files generated by -fstack-usage Rasmus Villemoes
2015-06-21  1:10   ` Rasmus Villemoes
2015-06-21  1:10 ` [RFC 4/4] scripts: add stackdelta script Rasmus Villemoes
2015-06-21  1:10   ` Rasmus Villemoes
2015-06-22  7:39   ` Rasmus Villemoes
2015-06-22  7:39     ` Rasmus Villemoes
2015-06-25  8:21 ` [RFC v2 0/4] scripts: add stack{usage,delta} scripts Rasmus Villemoes
2015-06-25  8:21   ` [RFC v2 1/4] scripts: add stackusage script Rasmus Villemoes
2015-06-25  8:21   ` [RFC v2 2/4] .gitignore: add *.su pattern Rasmus Villemoes
2015-06-25  8:21   ` [RFC v2 3/4] kbuild: remove *.su files generated by -fstack-usage Rasmus Villemoes
2015-06-25  8:21   ` Rasmus Villemoes [this message]
2015-08-19 14:16   ` [RFC v2 0/4] scripts: add stack{usage,delta} scripts Michal Marek
2015-08-20  9:53     ` [PATCH v3 " Rasmus Villemoes
2015-08-20  9:53       ` [PATCH v3 1/4] scripts: add stackusage script Rasmus Villemoes
2015-08-20  9:53       ` [PATCH v3 2/4] .gitignore: add *.su pattern Rasmus Villemoes
2015-08-20  9:53       ` [PATCH v3 3/4] kbuild: remove *.su files generated by -fstack-usage Rasmus Villemoes
2015-08-20  9:53       ` [PATCH v3 4/4] scripts: add stackdelta script Rasmus Villemoes
2015-08-28 15:05       ` [PATCH v3 0/4] scripts: add stack{usage,delta} scripts Michal Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435220492-15868-5-git-send-email-linux@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.