From 98adb88f12aa7941d819bce014bd773d68b52f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 4 Jan 2018 10:35:20 +0100 Subject: [PATCH] Add binary size to memanalyzer report --- code/build.sh | 2 +- code/memanalyzer.py | 81 +++++++++++++++++++++++++++++---------------- code/ota_flash.sh | 2 +- code/platformio.ini | 4 +-- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/code/build.sh b/code/build.sh index de85f451..7eed5290 100755 --- a/code/build.sh +++ b/code/build.sh @@ -45,7 +45,7 @@ echo "Building firmware images..." mkdir -p firmware/espurna-$version for environment in $environments; do echo "* espurna-$version-$environment.bin" - platformio run -s -e $environment || exit + platformio run --silent --environment $environment || exit mv .pioenvs/$environment/firmware.bin firmware/espurna-$version/espurna-$version-$environment.bin done echo "--------------------------------------------------------------" diff --git a/code/memanalyzer.py b/code/memanalyzer.py index a2903643..ee1f6a52 100644 --- a/code/memanalyzer.py +++ b/code/memanalyzer.py @@ -19,6 +19,7 @@ import shlex import commands import subprocess import sys +import os import re import argparse @@ -39,6 +40,12 @@ description = "ESPurna Memory Analyzer v0.1" #------------------------------------------------------------------------------- +def file_size(file): + try: + return os.stat(file).st_size + except: + return 0 + def analyse_memory(elf_file): command = "%s -t '%s' " % (objdump_binary, elf_file) @@ -107,7 +114,7 @@ try: # Parse command line options parser = argparse.ArgumentParser(description=description) - parser.add_argument("modules", nargs='*', help="Modules to test") + parser.add_argument("modules", nargs='*', help="Modules to test (use ALL to test them all)") parser.add_argument("-c", "--core", help="use core as base configuration instead of default", default=0, action='count') parser.add_argument("-l", "--list", help="list available modules", default=0, action='count') args = parser.parse_args() @@ -133,10 +140,12 @@ try: sys.exit(0) # Which modules to test? + test_modules = [] if len(args.modules) > 0: - test_modules = args.modules - else: - test_modules = available_modules.keys() + if "ALL" in args.modules: + test_modules = available_modules.keys() + else: + test_modules = args.modules # Check test modules exist for module in test_modules: @@ -153,20 +162,26 @@ try: modules = available_modules # Show init message - print "Analyzing module(s) %s on top of %s configuration\n" % (", ".join(test_modules), "CORE" if args.core > 0 else "DEFAULT") - output_format="{:<20}|{:<11}|{:<11}|{:<11}|{:<11}|{:<11}" + if len(test_modules) > 0: + print "Analyzing module(s) %s on top of %s configuration\n" % (", ".join(test_modules), "CORE" if args.core > 0 else "DEFAULT") + else: + print "Analyzing %s configuration\n" % ("CORE" if args.core > 0 else "DEFAULT") + + output_format="{:<20}|{:<11}|{:<11}|{:<11}|{:<11}|{:<11}|{:<12}" print(output_format.format( "Module", "Cache IRAM", "Init RAM", "R.O. RAM", "Uninit RAM", - "Flash ROM" + "Flash ROM", + "Binary size" )) # Build the core without modules to get base memory usage run(env, modules) - base = analyse_memory(".pioenvs/"+env+"/firmware.elf") + base = analyse_memory(".pioenvs/%s/firmware.elf" % env) + base['size'] = file_size(".pioenvs/%s/firmware.bin" % env) print(output_format.format( "CORE" if args.core == 1 else "DEFAULT", base['text'], @@ -174,6 +189,7 @@ try: base['rodata'], base['bss'], base['irom0_text'], + base['size'], )) # Test each module @@ -182,7 +198,8 @@ try: modules[module] = 1 run(env, modules) - results[module]=analyse_memory(".pioenvs/"+env+"/firmware.elf") + results[module]=analyse_memory(".pioenvs/%s/firmware.elf" % env) + results[module]['size'] = file_size(".pioenvs/%s/firmware.bin" % env) modules[module] = 0 print(output_format.format( @@ -192,33 +209,39 @@ try: results[module]['rodata'] - base['rodata'], results[module]['bss'] - base['bss'], results[module]['irom0_text'] - base['irom0_text'], + results[module]['size'] - base['size'], )) # Test all modules - for module in test_modules: - modules[module] = 1 - run(env, modules) - total = analyse_memory(".pioenvs/"+env+"/firmware.elf") + if len(test_modules) > 0: + + for module in test_modules: + modules[module] = 1 + run(env, modules) + total = analyse_memory(".pioenvs/%s/firmware.elf" % env) + total['size'] = file_size(".pioenvs/%s/firmware.bin" % env) + + if len(test_modules) > 1: + print(output_format.format( + "ALL MODULES", + total['text'] - base['text'], + total['data'] - base['data'], + total['rodata'] - base['rodata'], + total['bss'] - base['bss'], + total['irom0_text'] - base['irom0_text'], + total['size'] - base['size'], + )) - if len(test_modules) > 1: print(output_format.format( - "ALL MODULES", - total['text'] - base['text'], - total['data'] - base['data'], - total['rodata'] - base['rodata'], - total['bss'] - base['bss'], - total['irom0_text'] - base['irom0_text'], + "TOTAL", + total['text'], + total['data'], + total['rodata'], + total['bss'], + total['irom0_text'], + total['size'], )) - print(output_format.format( - "TOTAL", - total['text'], - total['data'], - total['rodata'], - total['bss'], - total['irom0_text'], - )) - except: raise diff --git a/code/ota_flash.sh b/code/ota_flash.sh index aef002cf..b217f0a4 100755 --- a/code/ota_flash.sh +++ b/code/ota_flash.sh @@ -222,4 +222,4 @@ export ESPURNA_BOARD=$board export ESPURNA_AUTH=$auth export ESPURNA_FLAGS=$flags -pio run -e $env -t upload +platformio run --silent --environment $env -t upload diff --git a/code/platformio.ini b/code/platformio.ini index 0387abfe..78e4a529 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -4,8 +4,8 @@ src_dir = espurna data_dir = espurna/data [common] -platform = espressif8266 -#platform = https://github.com/platformio/platform-espressif8266.git#feature/stage +#platform = espressif8266 +platform = https://github.com/platformio/platform-espressif8266.git#v1.5.0 build_flags = -g -DMQTT_MAX_PACKET_SIZE=400 ${env.ESPURNA_FLAGS} debug_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM build_flags_512k = ${common.build_flags} -Wl,-Tesp8266.flash.512k0.ld