Skip to content

Commit b62eb27

Browse files
lorddoskiasakpm00
authored andcommitted
scripts/bloat-o-meter: switch argument parsing to using argparse
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 Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Nikolay Borisov <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a16ceb1 commit b62eb27

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

scripts/bloat-o-meter

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
# This software may be used and distributed according to the terms
88
# of the GNU General Public License, incorporated herein by reference.
99

10-
import sys, os, re
10+
import sys, os, re, argparse
1111
from signal import signal, SIGPIPE, SIG_DFL
1212

1313
signal(SIGPIPE, SIG_DFL)
1414

15-
if len(sys.argv) < 3:
16-
sys.stderr.write("usage: %s [option] file1 file2\n" % sys.argv[0])
17-
sys.stderr.write("The options are:\n")
18-
sys.stderr.write("-c categorize output based on symbol type\n")
19-
sys.stderr.write("-d Show delta of Data Section\n")
20-
sys.stderr.write("-t Show delta of text Section\n")
21-
sys.exit(-1)
15+
parser = argparse.ArgumentParser(description="Simple script used to compare the symbol sizes of 2 object files")
16+
group = parser.add_mutually_exclusive_group()
17+
group.add_argument('-c', help='categorize output based on symbol type', action='store_true')
18+
group.add_argument('-d', help='Show delta of Data Section', action='store_true')
19+
group.add_argument('-t', help='Show delta of text Section', action='store_true')
20+
parser.add_argument('file1', help='First file to compare')
21+
parser.add_argument('file2', help='Second file to compare')
22+
23+
args = parser.parse_args()
2224

2325
re_NUMBER = re.compile(r'\.[0-9]+')
2426

@@ -77,9 +79,9 @@ def calc(oldfile, newfile, format):
7779
delta.reverse()
7880
return grow, shrink, add, remove, up, down, delta, old, new, otot, ntot
7981

80-
def print_result(symboltype, symbolformat, argc):
82+
def print_result(symboltype, symbolformat):
8183
grow, shrink, add, remove, up, down, delta, old, new, otot, ntot = \
82-
calc(sys.argv[argc - 1], sys.argv[argc], symbolformat)
84+
calc(args.file1, args.file2, symbolformat)
8385

8486
print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
8587
(add, remove, grow, shrink, up, -down, up-down))
@@ -93,13 +95,13 @@ def print_result(symboltype, symbolformat, argc):
9395
percent = 0
9496
print("Total: Before=%d, After=%d, chg %+.2f%%" % (otot, ntot, percent))
9597

96-
if sys.argv[1] == "-c":
97-
print_result("Function", "tT", 3)
98-
print_result("Data", "dDbB", 3)
99-
print_result("RO Data", "rR", 3)
100-
elif sys.argv[1] == "-d":
101-
print_result("Data", "dDbBrR", 3)
102-
elif sys.argv[1] == "-t":
103-
print_result("Function", "tT", 3)
98+
if args.c:
99+
print_result("Function", "tT")
100+
print_result("Data", "dDbB")
101+
print_result("RO Data", "rR")
102+
elif args.d:
103+
print_result("Data", "dDbBrR")
104+
elif args.t:
105+
print_result("Function", "tT")
104106
else:
105-
print_result("Function", "tTdDbBrR", 2)
107+
print_result("Function", "tTdDbBrR")

0 commit comments

Comments
 (0)