From patchwork Thu Jun 25 08:21:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 6672501 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 20FF09F39B for ; Thu, 25 Jun 2015 08:21:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 263FF206E3 for ; Thu, 25 Jun 2015 08:21:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EFA7206E5 for ; Thu, 25 Jun 2015 08:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751981AbbFYIVz (ORCPT ); Thu, 25 Jun 2015 04:21:55 -0400 Received: from mail-la0-f52.google.com ([209.85.215.52]:36744 "EHLO mail-la0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751975AbbFYIVw (ORCPT ); Thu, 25 Jun 2015 04:21:52 -0400 Received: by lacny3 with SMTP id ny3so40154653lac.3 for ; Thu, 25 Jun 2015 01:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ylCZtips7K6LlvyBdBzaKWxaUlzfEoBEYYoYUM894uc=; b=SNR7M8+QCycw6wK4g/gvTQNnaIr+pmBWVjgA9ah1Z0F4XXi7YwIRmfleL7/k+tVn/j /5tSiuhZDuLACN6SkT4slAyHRBAwSPhdzTJdGT9jpfsmTQ9TEvNbmsWoUqWwxysc8FlI fn0k2K4K0T58HRzUqLmCtcwSPZhVA3lsON07I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ylCZtips7K6LlvyBdBzaKWxaUlzfEoBEYYoYUM894uc=; b=XG1dFDaSzmhVEPHTEX4UCtaCgrVMkDwEJ17efBNciawfd8jqI1U5QpxQi8OzkDejEq aCArnLnfVoRq0nOo/GqbN3xI3l/s8jOMivBv4MNr2AOwhvdddmEyZlSzfRou1PvfWCim wFVf3JbBRBM14D62fQWPKwaiJORVswbth1rb/R50XdXfxyeKHkyY4OXtdbV5iILUOKLN 15utZbsynV0AGPrO94pykXD8SC3Gw3gNzAB+okcP9oioKl+dmR13Ff4/F0yULB7YrC9C E0svCfceOzS97yUKnTlGpxevsutxZ6E0+hk3dLRG7Mm0/h8pksVymcWOqfNPeaDOHP8Y Puuw== X-Gm-Message-State: ALoCoQnSdSFQiCEvlDNBjnbhnKWbJNsTL/qVKNjSXT0NX3WKtsxr6Xbtuebqi7j0Io8IP2xND7uO X-Received: by 10.112.48.68 with SMTP id j4mr43166990lbn.60.1435220511339; Thu, 25 Jun 2015 01:21:51 -0700 (PDT) Received: from spencer.imf.au.dk ([130.225.20.51]) by mx.google.com with ESMTPSA id j1sm7021891lbc.15.2015.06.25.01.21.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2015 01:21:50 -0700 (PDT) From: Rasmus Villemoes To: Michal Marek Cc: linux-kbuild@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [RFC v2 1/4] scripts: add stackusage script Date: Thu, 25 Jun 2015 10:21:29 +0200 Message-Id: <1435220492-15868-2-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1435220492-15868-1-git-send-email-linux@rasmusvillemoes.dk> References: <1434849046-19920-1-git-send-email-linux@rasmusvillemoes.dk> <1435220492-15868-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 --- scripts/stackusage | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 scripts/stackusage diff --git a/scripts/stackusage b/scripts/stackusage new file mode 100755 index 000000000000..b30dfa6b3a0a --- /dev/null +++ b/scripts/stackusage @@ -0,0 +1,33 @@ +#!/bin/sh + +outfile="" +now=`date +%s` + +while [ $# -gt 0 ] +do + case "$1" in + -o) + outfile="$2" + shift 2;; + -h) + echo "usage: $0 [-o outfile] " + exit 0;; + *) break;; + esac +done + +if [ -z "$outfile" ] +then + outfile=`mktemp --tmpdir stackusage.$$.XXXX` +fi + +KCFLAGS="${KCFLAGS} -fstack-usage" make "$@" + +# Prepend directory name to file names, remove column information, +# make file:column/function/size/type properly tab-separated. +find . -name '*.su' -newermt "@${now}" -print | \ + xargs perl -MFile::Basename -pe \ + '$d = dirname($ARGV); s#([^:]+:[0-9]+):[0-9]+:#$d/$1\t#;' | \ + sort -k3,3nr > "${outfile}" + +echo "$0: output written to ${outfile}"