size_report: create a main() function
Refactor code and add main() function. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
de311407bd
commit
de713534b6
1 changed files with 48 additions and 41 deletions
|
@ -16,27 +16,6 @@ import operator
|
||||||
import platform
|
import platform
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
parser = OptionParser()
|
|
||||||
parser.add_option("-d", "--depth", dest="depth", type="int",
|
|
||||||
help="How deep should we go into the tree", metavar="DEPTH")
|
|
||||||
parser.add_option("-o", "--outdir", dest="outdir",
|
|
||||||
help="read files from directory OUT", metavar="OUT")
|
|
||||||
parser.add_option("-k", "--kernel-name", dest="binary", default="zephyr",
|
|
||||||
help="kernel binary name")
|
|
||||||
parser.add_option("-r", "--ram",
|
|
||||||
action="store_true", dest="ram", default=False,
|
|
||||||
help="print RAM statistics")
|
|
||||||
parser.add_option("-F", "--rom",
|
|
||||||
action="store_true", dest="rom", default=False,
|
|
||||||
help="print ROM statistics")
|
|
||||||
parser.add_option("-s", "--objdump", type="string", dest="bin_objdump",
|
|
||||||
help="Path to the GNU binary utility objdump")
|
|
||||||
parser.add_option("-c", "--objcopy", type="string", dest="bin_objcopy",
|
|
||||||
help="Path to the GNU binary utility objcopy")
|
|
||||||
parser.add_option("-n", "--nm", type="string", dest="bin_nm",
|
|
||||||
help="Path to the GNU binary utility nm")
|
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
# Return a dict containing {
|
# Return a dict containing {
|
||||||
# symbol_name: {:,path/to/file}/symbol
|
# symbol_name: {:,path/to/file}/symbol
|
||||||
|
@ -408,26 +387,54 @@ def print_tree(data, total, depth):
|
||||||
print('{:92d}'.format(total))
|
print('{:92d}'.format(total))
|
||||||
return totp
|
return totp
|
||||||
|
|
||||||
bin_file = os.path.join(options.outdir, options.binary + ".bin")
|
|
||||||
stat_file = os.path.join(options.outdir, options.binary + ".stat")
|
|
||||||
elf_file = os.path.join(options.outdir, options.binary + ".elf")
|
|
||||||
|
|
||||||
if not os.path.exists(bin_file):
|
def main():
|
||||||
FNULL = open(os.devnull, 'w')
|
parser = OptionParser()
|
||||||
subprocess.call([options.bin_objcopy,"-S", "-Obinary", "-R", ".comment", "-R",
|
parser.add_option("-d", "--depth", dest="depth", type="int",
|
||||||
"COMMON", "-R", ".eh_frame", elf_file, bin_file],
|
help="How deep should we go into the tree", metavar="DEPTH")
|
||||||
stdout=FNULL, stderr=subprocess.STDOUT)
|
parser.add_option("-o", "--outdir", dest="outdir",
|
||||||
|
help="read files from directory OUT", metavar="OUT")
|
||||||
|
parser.add_option("-k", "--kernel-name", dest="binary", default="zephyr",
|
||||||
|
help="kernel binary name")
|
||||||
|
parser.add_option("-r", "--ram",
|
||||||
|
action="store_true", dest="ram", default=False,
|
||||||
|
help="print RAM statistics")
|
||||||
|
parser.add_option("-F", "--rom",
|
||||||
|
action="store_true", dest="rom", default=False,
|
||||||
|
help="print ROM statistics")
|
||||||
|
parser.add_option("-s", "--objdump", type="string", dest="bin_objdump",
|
||||||
|
help="Path to the GNU binary utility objdump")
|
||||||
|
parser.add_option("-c", "--objcopy", type="string", dest="bin_objcopy",
|
||||||
|
help="Path to the GNU binary utility objcopy")
|
||||||
|
parser.add_option("-n", "--nm", type="string", dest="bin_nm",
|
||||||
|
help="Path to the GNU binary utility nm")
|
||||||
|
|
||||||
if options.outdir and os.path.exists(elf_file):
|
(options, args) = parser.parse_args()
|
||||||
fp = get_footprint_from_bin_and_statfile(bin_file, stat_file, 0, 0)
|
|
||||||
base = os.environ['ZEPHYR_BASE']
|
|
||||||
ram, data = generate_target_memory_section(
|
|
||||||
options.bin_objdump, options.bin_nm, options.outdir, options.binary,
|
|
||||||
base + '/', None)
|
|
||||||
if options.rom:
|
|
||||||
print_tree(data, fp['total_flash'], options.depth)
|
|
||||||
if options.ram:
|
|
||||||
print_tree(ram, fp['total_ram'], options.depth)
|
|
||||||
|
|
||||||
else:
|
bin_file = os.path.join(options.outdir, options.binary + ".bin")
|
||||||
print("%s does not exist." % (elf_file))
|
stat_file = os.path.join(options.outdir, options.binary + ".stat")
|
||||||
|
elf_file = os.path.join(options.outdir, options.binary + ".elf")
|
||||||
|
|
||||||
|
if not os.path.exists(bin_file):
|
||||||
|
FNULL = open(os.devnull, 'w')
|
||||||
|
subprocess.call([options.bin_objcopy,"-S", "-Obinary", "-R", ".comment", "-R",
|
||||||
|
"COMMON", "-R", ".eh_frame", elf_file, bin_file],
|
||||||
|
stdout=FNULL, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
if options.outdir and os.path.exists(elf_file):
|
||||||
|
fp = get_footprint_from_bin_and_statfile(bin_file, stat_file, 0, 0)
|
||||||
|
base = os.environ['ZEPHYR_BASE']
|
||||||
|
ram, data = generate_target_memory_section(
|
||||||
|
options.bin_objdump, options.bin_nm, options.outdir, options.binary,
|
||||||
|
base + '/', None)
|
||||||
|
if options.rom:
|
||||||
|
print_tree(data, fp['total_flash'], options.depth)
|
||||||
|
if options.ram:
|
||||||
|
print_tree(ram, fp['total_ram'], options.depth)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("%s does not exist." % (elf_file))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue