Tasmota/pio-tools/metrics-firmware.py

26 lines
1.1 KiB
Python
Raw Normal View History

Import("env")
2023-05-03 10:04:10 +01:00
import os
import tasmotapiolib
2023-05-03 10:04:10 +01:00
from os.path import join
def firm_metrics(source, target, env):
if env["PIOPLATFORM"] == "espressif32":
import tasmota_metrics
2023-06-27 19:56:40 +01:00
env.Execute("$PYTHONEXE -m tasmota_metrics \"" + str(tasmotapiolib.get_source_map_path(env).resolve()) + "\"")
2023-05-03 10:04:10 +01:00
elif env["PIOPLATFORM"] == "espressif8266":
map_file = join(env.subst("$BUILD_DIR")) + os.sep + "firmware.map"
with open(map_file,'r', encoding='utf-8') as f:
2023-05-03 10:04:10 +01:00
phrase = "_text_end = ABSOLUTE (.)"
for line in f:
if phrase in line:
address = line.strip().split(" ")[0]
if int(address, 16) < 0x40108000:
used_bytes = int(address, 16) - 0x40100000
remaining_bytes = 0x8000 - used_bytes
percentage = round(used_bytes / 0x8000 * 100,1)
print("Used static IRAM:",used_bytes,"bytes (",remaining_bytes,"remain,",percentage,"% used)")
2023-06-27 19:56:40 +01:00
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin",firm_metrics)