summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2015-08-20 05:53:27 -0400
committerMichal Marek <mmarek@suse.com>2015-08-28 11:04:40 -0400
commit56d4a3814690a62a3fd9724844e23ea152ce938c (patch)
treeebd67a96993449571e753b4cb145e4c95fa29834
parenta9dd941d840714b96b0a60451f6a3aa3a9be8fc6 (diff)
scripts: add stackusage script
The current checkstack.pl script has a few problems, stemming from the overly simplistic attempt at parsing objdump output with regular expressions: 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 KCFLAGS set to -fstack-usage. Example use is scripts/stackusage -o out.su -j8 lib/ The script understands "-o foo" for writing to 'foo' and -h for a trivial help text; anything else is passed to make. Afterwards, we find all newly created .su files, massage them a little, sort by stack use and write the result to a single output file. Note that the function names printed by (at least) gcc 4.7 are sometimes useless. For example, the first three lines of out.su generated above are ./lib/decompress_bunzip2.c:155 get_next_block 448 static ./lib/decompress_unlzma.c:537 unlzma 336 static ./lib/vsprintf.c:616 8 304 static That function '8' is really the static symbol_string(), but it has been subject to 'interprocedural scalar replacement of aggregates', so its name in the object file is 'symbol_string.isra.8'. gcc 5.0 doesn't have this problem; it uses the full name as seen in the object 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> Signed-off-by: Michal Marek <mmarek@suse.com>
-rwxr-xr-xscripts/stackusage33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/stackusage b/scripts/stackusage
new file mode 100755
index 000000000000..8cf26640ef8a
--- /dev/null
+++ b/scripts/stackusage
@@ -0,0 +1,33 @@
1#!/bin/sh
2
3outfile=""
4now=`date +%s`
5
6while [ $# -gt 0 ]
7do
8 case "$1" in
9 -o)
10 outfile="$2"
11 shift 2;;
12 -h)
13 echo "usage: $0 [-o outfile] <make options/args>"
14 exit 0;;
15 *) break;;
16 esac
17done
18
19if [ -z "$outfile" ]
20then
21 outfile=`mktemp --tmpdir stackusage.$$.XXXX`
22fi
23
24KCFLAGS="${KCFLAGS} -fstack-usage" make "$@"
25
26# Prepend directory name to file names, remove column information,
27# make file:line/function/size/type properly tab-separated.
28find . -name '*.su' -newermt "@${now}" -print | \
29 xargs perl -MFile::Basename -pe \
30 '$d = dirname($ARGV); s#([^:]+:[0-9]+):[0-9]+:#$d/$1\t#;' | \
31 sort -k3,3nr > "${outfile}"
32
33echo "$0: output written to ${outfile}"