Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752638AbdI1Dbi (ORCPT ); Wed, 27 Sep 2017 23:31:38 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:28462 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752160AbdI1Dbg (ORCPT ); Wed, 27 Sep 2017 23:31:36 -0400 X-AuditID: b6c32a49-99fff7000000104d-b5-59cc6d151384 From: Maninder Singh To: adobriyan@gmail.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, pankaj.m@samsung.com, a.sahrawat@samsung.com, lalit.mohan@samsung.com, Maninder Singh , Vaneet Narang Subject: [PATCH v2] bloat-o-meter: provide 3 different arguments for data, function and all Date: Thu, 28 Sep 2017 09:00:02 +0530 Message-Id: <1506569402-24787-1-git-send-email-maninder1.s@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGKsWRmVeSWpSXmKPExsWy7bCmuq5o7plIg8b3QhYXd6daTG/0spiz fg2bRf9iM4vLu+awWRye38Zice/NViaLQyfnMjpweOycdZfd48SM3ywefVtWMXp83iQXwBKV apORmpiSWqSQmpecn5KZl26r5B0c7xxvamZgqGtoaWGupJCXmJtqq+TiE6DrlpkDdIOSQlli TilQKCCxuFhJ386mKL+0JFUhI7+4xFYp2tDQSM/QwFzPyMhIz8Q01srIFKgkITXjz8x3TAVT dCpuTXnM3sD4Rq6LkZNDQsBEYsqXPywgtpDAbkaJXTvTuxi5gOxPjBKXJh5hhnC+MUqcOnGZ Gabj0N5LTBCJvYwSk4+fYYdwvjBKdH3ezQpSxSagJ7Fq1x6wuSICRhIdN2eDdTCD7Fh77SFj FyMHh7BArETX6myQGhYBVYnO//uYQMK8Au4STd08EMvkJE4em8wK0ioh0Mgm0X3zATtEwkXi +t7rjBC2sMSr41ug4lISL/vb2CEauhkllp1+wgThzGCUWHHvHtQP9hIPbhxlB9nGLKApsX6X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T+ +iZauS0naPvZU3qX5x65vVj8epnm7JWHn09+YGgzL0UlRHLCmeL+n+b1F4ofLz4kdWsGezKv /4GrftdkHsxiXNfLFXCN6fnOhxoXTBVmfg/m+nia44ESS3FGoqEWc1FxIgCXdQQAHAIAAA== X-CMS-MailID: 20170928033133epcas5p4ee2f704eddcaaabf87634c0eb0b53304 X-Msg-Generator: CA X-Sender-IP: 182.195.40.13 X-Local-Sender: =?UTF-8?B?TWFuaW5kZXIgU2luZ2gbU1JJLURlbGhpLVBsYXRmb3JtIFMv?= =?UTF-8?B?VyAxIFRlYW0b7IK87ISx7KCE7J6QG0xlYWQgRW5naW5lZXI=?= X-Global-Sender: =?UTF-8?B?TWFuaW5kZXIgU2luZ2gbU1JJLURlbGhpLVBsYXRmb3JtIFMv?= =?UTF-8?B?VyAxIFRlYW0bU2Ftc3VuZ8KgRWxlY3Ryb25pY3PCoBtMZWFkIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG1NXQUhRG0MxMElEMDJJRDAyODExNQ==?= Content-Type: text/plain; charset="utf-8" X-MTR: 20170928033133epcas5p4ee2f704eddcaaabf87634c0eb0b53304 CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20170928033133epcas5p4ee2f704eddcaaabf87634c0eb0b53304 X-RootMTR: 20170928033133epcas5p4ee2f704eddcaaabf87634c0eb0b53304 References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5493 Lines: 157 This patch provides 3 new arguments for bloat-o-meter: 1) -c -> for all (showing function and data differently). 2) -d -> data. 3) -t -> function. output:- ./scripts/bloat-o-meter -c "file1" "file2" add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-152 (-152) Function old new delta main 412 260 -152 Total: Before=548, After=396, chg -27.74% add/remove: 1/0 grow/shrink: 1/0 up/down: 84/0 (84) Data old new delta arr - 64 +64 backtrace 60 80 +20 Total: Before=109, After=193, chg +77.06% add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-64 (-64) RO Data old new delta arr 64 - -64 Total: Before=68, After=4, chg -94.12% Signed-off-by: Vaneet Narang Signed-off-by: Maninder Singh --- v1 -> v2 1) Incorporated missed changes between 4.1 and latest version. 2) Removed extra noise of "#####" after each section print. 3) Removed extra parentheses from if and else caluse. scripts/bloat-o-meter | 89 ++++++++++++++++++++++++++++++------------------- 1 files changed, 55 insertions(+), 34 deletions(-) diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index a276771..6f099f9 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -12,18 +12,22 @@ from signal import signal, SIGPIPE, SIG_DFL signal(SIGPIPE, SIG_DFL) -if len(sys.argv) != 3: - sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0]) +if len(sys.argv) < 3: + sys.stderr.write("usage: %s [option] file1 file2\n" % sys.argv[0]) + sys.stderr.write("The options are:\n") + sys.stderr.write("-c cateogrize output based on symbole type\n") + sys.stderr.write("-d Show delta of Data Section\n") + sys.stderr.write("-t Show delta of text Section\n") sys.exit(-1) re_NUMBER = re.compile(r'\.[0-9]+') -def getsizes(file): +def getsizes(file, format): sym = {} with os.popen("nm --size-sort " + file) as f: for line in f: size, type, name = line.split() - if type in "tTdDbBrR": + if type in format: # strip generated symbols if name.startswith("__mod_"): continue if name.startswith("SyS_"): continue @@ -34,44 +38,61 @@ def getsizes(file): sym[name] = sym.get(name, 0) + int(size, 16) return sym -old = getsizes(sys.argv[1]) -new = getsizes(sys.argv[2]) -grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 -delta, common = [], {} -otot, ntot = 0, 0 +def calc(oldfile, newfile, format): + old = getsizes(oldfile, format) + new = getsizes(newfile, format) + grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 + delta, common = [], {} + otot, ntot = 0, 0 -for a in old: - if a in new: - common[a] = 1 + for a in old: + if a in new: + common[a] = 1 -for name in old: - otot += old[name] - if name not in common: - remove += 1 - down += old[name] - delta.append((-old[name], name)) + for name in old: + otot += old[name] + if name not in common: + remove += 1 + down += old[name] + delta.append((-old[name], name)) -for name in new: - ntot += new[name] - if name not in common: - add += 1 - up += new[name] - delta.append((new[name], name)) + for name in new: + ntot += new[name] + if name not in common: + add += 1 + up += new[name] + delta.append((new[name], name)) -for name in common: + for name in common: d = new.get(name, 0) - old.get(name, 0) if d>0: grow, up = grow+1, up+d if d<0: shrink, down = shrink+1, down-d delta.append((d, name)) -delta.sort() -delta.reverse() + delta.sort() + delta.reverse() + return grow, shrink, add, remove, up, down, delta, old, new, otot, ntot -print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \ - (add, remove, grow, shrink, up, -down, up-down)) -print("%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")) -for d, n in delta: - if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)) +def print_result(symboltype, symbolformat, argc): + grow, shrink, add, remove, up, down, delta, old, new, otot, ntot = \ + calc(sys.argv[argc - 1], sys.argv[argc], symbolformat) -print("Total: Before=%d, After=%d, chg %+.2f%%" % \ - (otot, ntot, (ntot - otot)*100.0/otot)) + print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \ + (add, remove, grow, shrink, up, -down, up-down)) + print("%-40s %7s %7s %+7s" % (symboltype, "old", "new", "delta")) + for d, n in delta: + if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)) + + print("Total: Before=%d, After=%d, chg %+.2f%%" % \ + (otot, ntot, (ntot - otot)*100.0/otot)) + +if sys.argv[1] == "-c": + print_result("Function", "tT", 3) + print_result("Data", "dDbB", 3) + print_result("RO Data", "rR", 3) +elif sys.argv[1] == "-d": + print_result("Data", "dDbBrR", 3) +elif sys.argv[1] == "-t": + print_result("Function", "tT", 3) +else: + print_result("Function", "tTdDbBrR", 2) -- 1.7.1