Browse Source

Make string formatting consistent

sensors
Ryan Jarvis 5 years ago
parent
commit
97b5ef9c8c
1 changed files with 16 additions and 16 deletions
  1. +16
    -16
      code/memanalyzer.py

+ 16
- 16
code/memanalyzer.py View File

@ -56,7 +56,7 @@ def file_size(file):
def analyse_memory(elf_file): def analyse_memory(elf_file):
command = "%s -t '%s'" % (objdump_binary, elf_file)
command = "{} -t '{}'".format(objdump_binary, elf_file)
response = subprocess.check_output(shlex.split(command)) response = subprocess.check_output(shlex.split(command))
if isinstance(response, bytes): if isinstance(response, bytes):
response = response.decode('utf-8') response = response.decode('utf-8')
@ -67,8 +67,8 @@ def analyse_memory(elf_file):
ret = {} ret = {}
for (id_, _) in list(sections.items()): for (id_, _) in list(sections.items()):
section_start_token = " _%s_start" % id_
section_end_token = " _%s_end" % id_
section_start_token = " _{}_start".format(id_)
section_end_token = " _{}_end".format(id_)
section_start = -1 section_start = -1
section_end = -1 section_end = -1
for line in lines: for line in lines:
@ -93,9 +93,9 @@ def analyse_memory(elf_file):
# print("{0: >10}|{1: >30}|{2:12X}|{3:12X}|{4:8}".format(id_, descr, section_start, section_end, section_length)) # print("{0: >10}|{1: >30}|{2:12X}|{3:12X}|{4:8}".format(id_, descr, section_start, section_end, section_length))
# i += 1 # i += 1
# print("Total Used RAM : %d" % usedRAM)
# print("Free RAM : %d" % (TOTAL_DRAM - usedRAM))
# print("Free IRam : %d" % usedIRAM)
# print("Total Used RAM : {:d}".format(usedRAM))
# print("Free RAM : {:d}".format(TOTAL_DRAM - usedRAM))
# print("Free IRam : {:d}".format(usedIRAM))
return ret return ret
@ -103,7 +103,7 @@ def run(env_, modules_):
flags = "" flags = ""
for item in modules_.items(): for item in modules_.items():
flags += "-D%s_SUPPORT=%d " % item flags += "-D%s_SUPPORT=%d " % item
command = "ESPURNA_BOARD=\"WEMOS_D1_MINI_RELAYSHIELD\" ESPURNA_FLAGS=\"%s\" platformio run --silent --environment %s 2>/dev/null" % (flags, env_)
command = "ESPURNA_BOARD=\"WEMOS_D1_MINI_RELAYSHIELD\" ESPURNA_FLAGS=\"{}\" platformio run --silent --environment {} 2>/dev/null".format(flags, env_)
subprocess.check_call(command, shell=True) subprocess.check_call(command, shell=True)
@ -164,7 +164,7 @@ if __name__ == '__main__':
# Check test modules exist # Check test modules exist
for module in test_modules: for module in test_modules:
if module not in available_modules: if module not in available_modules:
print("Module %s not found" % module)
print("Module {} not found".format(module))
sys.exit(2) sys.exit(2)
# Define base configuration # Define base configuration
@ -177,9 +177,9 @@ if __name__ == '__main__':
# Show init message # Show init message
if len(test_modules) > 0: 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"))
print("Analyzing module(s) {} on top of {} configuration\n".format(", ".join(test_modules), "CORE" if args.core > 0 else "DEFAULT"))
else: else:
print("Analyzing %s configuration\n" % ("CORE" if args.core > 0 else "DEFAULT"))
print("Analyzing {} configuration\n".format("CORE" if args.core > 0 else "DEFAULT"))
output_format = "{:<20}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}" output_format = "{:<20}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}"
print(output_format.format( print(output_format.format(
@ -215,8 +215,8 @@ if __name__ == '__main__':
# Build the core without modules to get base memory usage # Build the core without modules to get base memory usage
run(env, modules) run(env, modules)
base = analyse_memory(".pioenvs/%s/firmware.elf" % env)
base['size'] = file_size(".pioenvs/%s/firmware.bin" % env)
base = analyse_memory(".pioenvs/{}/firmware.elf".format(env))
base['size'] = file_size(".pioenvs/{}/firmware.bin".format(env))
calc_free(base) calc_free(base)
print(output_format.format( print(output_format.format(
"CORE" if args.core == 1 else "DEFAULT", "CORE" if args.core == 1 else "DEFAULT",
@ -235,8 +235,8 @@ if __name__ == '__main__':
modules[module] = 1 modules[module] = 1
run(env, modules) run(env, modules)
results[module] = analyse_memory(".pioenvs/%s/firmware.elf" % env)
results[module]['size'] = file_size(".pioenvs/%s/firmware.bin" % env)
results[module] = analyse_memory(".pioenvs/{}/firmware.elf".format(env))
results[module]['size'] = file_size(".pioenvs/{}/firmware.bin".format(env))
calc_free(results[module]) calc_free(results[module])
modules[module] = 0 modules[module] = 0
@ -257,8 +257,8 @@ if __name__ == '__main__':
for module in test_modules: for module in test_modules:
modules[module] = 1 modules[module] = 1
run(env, modules) run(env, modules)
total = analyse_memory(".pioenvs/%s/firmware.elf" % env)
total['size'] = file_size(".pioenvs/%s/firmware.bin" % env)
total = analyse_memory(".pioenvs/{}/firmware.elf".format(env))
total['size'] = file_size(".pioenvs/{}/firmware.bin".format(env))
calc_free(total) calc_free(total)
if len(test_modules) > 1: if len(test_modules) > 1:


Loading…
Cancel
Save