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 1/4] scripts: add stackusage script
Date: Sun, 21 Jun 2015 03:10:43 +0200	[thread overview]
Message-ID: <1434849046-19920-2-git-send-email-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <1434849046-19920-1-git-send-email-linux@rasmusvillemoes.dk>

The current checkstack.pl script has a few problems, stemming from the
overly simplistic attempt at parsing objdump output with regular
expresions: For example, on x86_64 it doesn't take the push
instruction into account, making it consistently underestimate the
real stack use, and it also doesn't capture stack pointer adjustments
of exactly 128 bytes [1].

Since newer gcc (>= 4.6) knows about -fstack-usage, we might as well
take the information straight from the horse's mouth. This patch
introduces scripts/stackusage, which is a simple wrapper for running
make with EXTRA_CFLAGS set to -fstack-usage. Example use is

scripts/stackusage -o out.su -- -j8 fs/ext4/

Arguments after -- are passed to make. Afterwards, we find all newly
created .su files, massage them a little, sort by stack use and
concatenate the result to a single output file.

[1] Since gcc encodes that by

48 83 c4 80             add    $0xffffffffffffff80,%rsp

and not

48 81 ec 80 00 00 00    sub    $0x80,%rsp

since -128 fits in an imm8.

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

diff --git a/scripts/stackusage b/scripts/stackusage
new file mode 100755
index 000000000000..d631af648ae7
--- /dev/null
+++ b/scripts/stackusage
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+outfile=""
+now=`date +%s`
+
+while [ $# -gt 0 ]
+do
+    case "$1" in
+        -o)
+	    outfile="$2"
+	    echo "$outfile"
+	    shift 2;;
+	-h)
+	    echo "usage: $0 [-o outfile] -- <make options/args>"
+	    exit 0;;
+	--)
+	    shift
+	    break;;
+	-*)
+            echo >&2 "usage: $0 [-o outfile] -- <make options/args>"
+	    exit 1;;
+	*)  break;;
+    esac
+done
+
+if [ -z "$outfile" ]
+then
+    outfile=`mktemp --tmpdir stackusage.$$.XXXX`
+fi
+
+make EXTRA_CFLAGS="-fstack-usage" "$@"
+
+# Prepend directory name to file names, remove line/column
+# information, make file/function/size/type properly tab-separated.
+find . -name '*.su' -newermt "@${now}" -print |                 \
+    xargs perl -MFile::Basename -pe                             \
+      '$d = dirname($ARGV); s#([^:]+):([0-9]+:){2}#$d/$1\t#;' | \
+    sort -k3,3nr > "${outfile}"
+
+echo "$0: output written to ${outfile}"
-- 
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/

WARNING: multiple messages have this Message-ID (diff)
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 1/4] scripts: add stackusage script
Date: Sun, 21 Jun 2015 03:10:43 +0200	[thread overview]
Message-ID: <1434849046-19920-2-git-send-email-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <1434849046-19920-1-git-send-email-linux@rasmusvillemoes.dk>

The current checkstack.pl script has a few problems, stemming from the
overly simplistic attempt at parsing objdump output with regular
expresions: For example, on x86_64 it doesn't take the push
instruction into account, making it consistently underestimate the
real stack use, and it also doesn't capture stack pointer adjustments
of exactly 128 bytes [1].

Since newer gcc (>= 4.6) knows about -fstack-usage, we might as well
take the information straight from the horse's mouth. This patch
introduces scripts/stackusage, which is a simple wrapper for running
make with EXTRA_CFLAGS set to -fstack-usage. Example use is

scripts/stackusage -o out.su -- -j8 fs/ext4/

Arguments after -- are passed to make. Afterwards, we find all newly
created .su files, massage them a little, sort by stack use and
concatenate the result to a single output file.

[1] Since gcc encodes that by

48 83 c4 80             add    $0xffffffffffffff80,%rsp

and not

48 81 ec 80 00 00 00    sub    $0x80,%rsp

since -128 fits in an imm8.

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

diff --git a/scripts/stackusage b/scripts/stackusage
new file mode 100755
index 000000000000..d631af648ae7
--- /dev/null
+++ b/scripts/stackusage
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+outfile=""
+now=`date +%s`
+
+while [ $# -gt 0 ]
+do
+    case "$1" in
+        -o)
+	    outfile="$2"
+	    echo "$outfile"
+	    shift 2;;
+	-h)
+	    echo "usage: $0 [-o outfile] -- <make options/args>"
+	    exit 0;;
+	--)
+	    shift
+	    break;;
+	-*)
+            echo >&2 "usage: $0 [-o outfile] -- <make options/args>"
+	    exit 1;;
+	*)  break;;
+    esac
+done
+
+if [ -z "$outfile" ]
+then
+    outfile=`mktemp --tmpdir stackusage.$$.XXXX`
+fi
+
+make EXTRA_CFLAGS="-fstack-usage" "$@"
+
+# Prepend directory name to file names, remove line/column
+# information, make file/function/size/type properly tab-separated.
+find . -name '*.su' -newermt "@${now}" -print |                 \
+    xargs perl -MFile::Basename -pe                             \
+      '$d = dirname($ARGV); s#([^:]+):([0-9]+:){2}#$d/$1\t#;' | \
+    sort -k3,3nr > "${outfile}"
+
+echo "$0: output written to ${outfile}"
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in

  reply	other threads:[~2015-06-21  1:11 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 ` Rasmus Villemoes [this message]
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   ` 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   ` [RFC v2 4/4] scripts: add stackdelta script Rasmus Villemoes
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=1434849046-19920-2-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.