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 4/4] scripts: add stackdelta script
Date: Sun, 21 Jun 2015 03:10:46 +0200 [thread overview]
Message-ID: <1434849046-19920-5-git-send-email-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <1434849046-19920-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 | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100755 scripts/stackdelta
diff --git a/scripts/stackdelta b/scripts/stackdelta
new file mode 100755
index 000000000000..18417098a378
--- /dev/null
+++ b/scripts/stackdelta
@@ -0,0 +1,55 @@
+#!/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.
+
+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/\..*$//;
+ $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 = grep {exists $new->{$_}} keys %$old;
+print join(",", keys %old) . "\n";
+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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2015-06-21 1:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1434849046-19920-1-git-send-email-linux@rasmusvillemoes.dk>
2015-06-21 1:10 ` [RFC 1/4] scripts: add stackusage script 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 ` [RFC 3/4] kbuild: remove *.su files generated by -fstack-usage Rasmus Villemoes
2015-06-21 1:10 ` Rasmus Villemoes [this message]
2015-06-22 7:39 ` [RFC 4/4] scripts: add stackdelta script Rasmus Villemoes
[not found] ` <1435220492-15868-1-git-send-email-linux@rasmusvillemoes.dk>
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 ` [RFC v2 4/4] scripts: add stackdelta script Rasmus Villemoes
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=1434849046-19920-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®