summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2025-04-24 17:52:43 +1000
committerDamien George <damien@micropython.org>2025-04-24 22:16:32 +1000
commit584fa8800b833b53c6d6f9eb7572774a67304d2f (patch)
tree0e72250c6ab02b7f445deceb04dc9609f2085c61
parentce7f65f96703bbbe6039ba29e079023a32dccef0 (diff)
downloadmicropython-584fa8800b833b53c6d6f9eb7572774a67304d2f.tar.gz
micropython-584fa8800b833b53c6d6f9eb7572774a67304d2f.zip
esp32/tools: Update metrics_esp32 script for ESP-IDF >=v5.4.x.
The output of 'idf.py size' has changed, plus some other cleanups around build dir name, etc. Can now run on v5.2.2 and v5.4.1, probably other versions. Signed-off-by: Angus Gratton <angus@redyak.com.au>
-rwxr-xr-xports/esp32/tools/metrics_esp32.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/ports/esp32/tools/metrics_esp32.py b/ports/esp32/tools/metrics_esp32.py
index 66a6a588ba..5e65a78c97 100755
--- a/ports/esp32/tools/metrics_esp32.py
+++ b/ports/esp32/tools/metrics_esp32.py
@@ -32,6 +32,7 @@
# column of the table is really D/IRAM.
import os
import re
+import shutil
import sys
import subprocess
from dataclasses import dataclass
@@ -47,6 +48,13 @@ BUILDS = (
)
+def rmtree(path):
+ try:
+ shutil.rmtree(path)
+ except FileNotFoundError:
+ pass
+
+
@dataclass
class BuildSizes:
idf_ver: str
@@ -99,7 +107,7 @@ class BuildSizes:
def build_dir(self):
if self.variant:
- return f"build-{self.board}_{self.variant}"
+ return f"build-{self.board}-{self.variant}"
else:
return f"build-{self.board}"
@@ -124,12 +132,23 @@ class BuildSizes:
def make_size(self):
try:
size_out = self.run_make("size")
- # "Used static DRAM:" or "Used stat D/IRAM:"
- RE_DRAM = r"Used stat(?:ic)? D.*: *(\d+) bytes"
- RE_IRAM = r"Used static IRAM: *(\d+) bytes"
+ try:
+ # pre IDF v5.4 size output
+ # "Used static DRAM:" or "Used stat D/IRAM:"
+ RE_DRAM = r"Used stat(?:ic)? D.*: *(\d+) bytes"
+ RE_IRAM = r"Used static IRAM: *(\d+) bytes"
+ self.dram_size = re.search(RE_DRAM, size_out).group(1)
+ self.iram_size = re.search(RE_IRAM, size_out).group(1)
+ except AttributeError:
+ # IDF v5.4 size output is much nicer formatted
+ # Note the pipes in these expressions are not the ASCII/RE |
+ RE_DRAM = r"│ *DI?RAM *│ *(\d+)"
+ RE_IRAM = r"│ *IRAM *│ *(\d+)"
+ self.dram_size = re.search(RE_DRAM, size_out).group(1)
+ self.iram_size = re.search(RE_IRAM, size_out).group(1)
+
+ # This line is the same on before/after versions
RE_BIN = r"Total image size: *(\d+) bytes"
- self.dram_size = re.search(RE_DRAM, size_out).group(1)
- self.iram_size = re.search(RE_IRAM, size_out).group(1)
self.bin_size = re.search(RE_BIN, size_out).group(1)
except subprocess.CalledProcessError:
self.bin_size = "build failed"
@@ -139,13 +158,26 @@ def main(do_clean):
if "IDF_PATH" not in os.environ:
raise RuntimeError("IDF_PATH must be set")
+ if not os.path.exists("Makefile"):
+ raise RuntimeError(
+ "This script must be run from the ports/esp32 directory, i.e. as ./tools/metrics_esp32.py"
+ )
+
+ if "IDF_PYTHON_ENV_PATH" in os.environ:
+ raise RuntimeError(
+ "Run this script without any existing ESP-IDF environment active/exported."
+ )
+
sizes = []
for idf_ver in IDF_VERS:
switch_ver(idf_ver)
+ rmtree("managed_components")
for board, variant in BUILDS:
print(f"Building '{board}'/'{variant}'...", file=sys.stderr)
result = BuildSizes(idf_ver, board, variant)
- result.run_make("clean")
+ # Rather than running the 'clean' target, delete the build directory to avoid
+ # environment version mismatches, etc.
+ rmtree(result.build_dir())
result.make_size()
result.print_summary()
sizes.append(result)