* [PATCH 1/2] scripts/bloat-o-meter: switch argument parsing to using argparse
@ 2022-07-01 11:35 Nikolay Borisov
2022-07-01 11:35 ` [PATCH 2/2] scripts/bloat-o-meter: add -p argument Nikolay Borisov
0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Borisov @ 2022-07-01 11:35 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, Nikolay Borisov
This will facilitate further extension to the arguments the script
takes. As an added benefit it also produces saner usage output, where
mutual exclusivity of the c|d|t parameters is clearly visible:
./scripts/bloat-o-meter -h
usage: bloat-o-meter [-h] [-c | -d | -t] file1 file2
Simple script used to compare the symbol sizes of 2 object files
positional arguments:
file1 First file to compare
file2 Second file to compare
optional arguments:
-h, --help show this help message and exit
-c categorize output based on symbol type
-d Show delta of Data Section
-t Show delta of text Section
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
scripts/bloat-o-meter | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index 4dd6a804ce41..2a360118710e 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -7,18 +7,20 @@
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
-import sys, os, re
+import sys, os, re, argparse
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
-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 categorize output based on symbol 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)
+parser = argparse.ArgumentParser(description="Simple script used to compare the symbol sizes of 2 object files")
+group = parser.add_mutually_exclusive_group()
+group.add_argument('-c', help='categorize output based on symbol type', action='store_true')
+group.add_argument('-d', help='Show delta of Data Section', action='store_true')
+group.add_argument('-t', help='Show delta of text Section', action='store_true')
+parser.add_argument('file1', help='First file to compare')
+parser.add_argument('file2', help='Second file to compare')
+
+args = parser.parse_args()
re_NUMBER = re.compile(r'\.[0-9]+')
@@ -77,9 +79,9 @@ re_NUMBER = re.compile(r'\.[0-9]+')
delta.reverse()
return grow, shrink, add, remove, up, down, delta, old, new, otot, ntot
-def print_result(symboltype, symbolformat, argc):
+def print_result(symboltype, symbolformat):
grow, shrink, add, remove, up, down, delta, old, new, otot, ntot = \
- calc(sys.argv[argc - 1], sys.argv[argc], symbolformat)
+ calc(args.file1, args.file2, symbolformat)
print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
(add, remove, grow, shrink, up, -down, up-down))
@@ -93,13 +95,13 @@ re_NUMBER = re.compile(r'\.[0-9]+')
percent = 0
print("Total: Before=%d, After=%d, chg %+.2f%%" % (otot, ntot, percent))
-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)
+if args.c:
+ print_result("Function", "tT")
+ print_result("Data", "dDbB")
+ print_result("RO Data", "rR")
+elif args.d:
+ print_result("Data", "dDbBrR")
+elif args.t:
+ print_result("Function", "tT")
else:
- print_result("Function", "tTdDbBrR", 2)
+ print_result("Function", "tTdDbBrR")
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] scripts/bloat-o-meter: add -p argument
2022-07-01 11:35 [PATCH 1/2] scripts/bloat-o-meter: switch argument parsing to using argparse Nikolay Borisov
@ 2022-07-01 11:35 ` Nikolay Borisov
0 siblings, 0 replies; 2+ messages in thread
From: Nikolay Borisov @ 2022-07-01 11:35 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, Nikolay Borisov
When doing cross platform development on a machine sometimes it might be
useful to invoke bloat-o-meter for files which haven't been build with
the native toolchain. In cases when the host nm doesn't support
the target one then a toolchain-specific nm could be used. Add this
ability by adding the -p allowing invocations as:
./scripts/bloat-o-meter -p riscv64-unknown-linux-gnu- file1.o file2.o
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
scripts/bloat-o-meter | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index 2a360118710e..f9553f60a14a 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -17,6 +17,7 @@ group = parser.add_mutually_exclusive_group()
group.add_argument('-c', help='categorize output based on symbol type', action='store_true')
group.add_argument('-d', help='Show delta of Data Section', action='store_true')
group.add_argument('-t', help='Show delta of text Section', action='store_true')
+parser.add_argument('-p', dest='prefix', help='Arch prefix for the tool being used. Useful in cross build scenarios')
parser.add_argument('file1', help='First file to compare')
parser.add_argument('file2', help='Second file to compare')
@@ -26,7 +27,11 @@ re_NUMBER = re.compile(r'\.[0-9]+')
def getsizes(file, format):
sym = {}
- with os.popen("nm --size-sort " + file) as f:
+ nm = "nm"
+ if args.prefix:
+ nm = "{}nm".format(args.prefix)
+
+ with os.popen("{} --size-sort {}".format(nm, file)) as f:
for line in f:
if line.startswith("\n") or ":" in line:
continue
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-01 11:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 11:35 [PATCH 1/2] scripts/bloat-o-meter: switch argument parsing to using argparse Nikolay Borisov
2022-07-01 11:35 ` [PATCH 2/2] scripts/bloat-o-meter: add -p argument Nikolay Borisov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).