From 5de18abaf95919d79f298e1f713a0e127836857c Mon Sep 17 00:00:00 2001 From: DmitryBorisenko33 Date: Mon, 9 Feb 2026 22:45:25 +0100 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=20=D0=B8=D0=B7=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D1=8F,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=20--limit=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D0=B5=D0=B9=20=D0=BD=D0=B0=20=D0=BE=D0=BA?= =?UTF-8?q?=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5,=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B1=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BE=20=D0=BB=D0=B8=D0=BC=D0=B8=D1=82=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- measure_size/measure.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/measure_size/measure.py b/measure_size/measure.py index c6a56583..5bca0686 100644 --- a/measure_size/measure.py +++ b/measure_size/measure.py @@ -119,6 +119,16 @@ def module_supports_env(used_libs, env): return False +def env_to_base_from_module(used_libs, env): + """Return the usedLibs pattern that matches env (base key for about.size). From module info, no hardcode.""" + if not used_libs: + return env + for pattern in used_libs: + if fnmatch.fnmatch(env, pattern): + return pattern + return env + + def build_profile_with_modules(prof_template, active_paths, env): """Return a new profile dict with only given module paths active for the given env.""" prof = json.loads(json.dumps(prof_template)) @@ -173,6 +183,7 @@ def main(): ap.add_argument("--profile", default="myProfile.json", help="Profile to use as template") ap.add_argument("--dry-run", action="store_true", help="Only list modules and envs, do not build") ap.add_argument("--no-color", action="store_true", help="Disable colored output") + ap.add_argument("--limit", type=int, default=None, metavar="N", help="Measure only first N modules per env (e.g. --limit 5)") args = ap.parse_args() if args.no_color: USE_COLOR = False @@ -189,6 +200,8 @@ def main(): modules = collect_modules() baseline_paths = set(BASELINE_MODULE_PATHS) modules_by_env = {e: [m for m in modules if module_supports_env(m["usedLibs"], e)] for e in envs} + if args.limit is not None: + modules_by_env = {e: mods[: args.limit] for e, mods in modules_by_env.items()} if args.dry_run: log_section("Dry run — modules per env") @@ -204,10 +217,12 @@ def main(): log_step(f"Profile: {profile_path.name}") log_step(f"Envs: {', '.join(envs)}") total_modules = sum(len(modules_by_env[e]) for e in envs) - log_step(f"Total builds: baseline×{len(envs)} + {total_modules} module builds") + limit_note = f" (first {args.limit} per env)" if args.limit is not None else "" + log_step(f"Total builds: baseline×{len(envs)} + {total_modules} module builds{limit_note}") platformio_ini = PROJECT_ROOT / "platformio.ini" platformio_backup = PROJECT_ROOT / "platformio.ini.ram_measure.bak" + original_env = prof_template["projectProp"]["platformio"].get("default_envs", envs[0] if envs else "esp32_4mb") shutil.copy(platformio_ini, platformio_backup) try: @@ -255,8 +270,9 @@ def main(): continue delta = size - baseline_size.get(env, 0) size_kb = max(0, round(delta / 1024)) - results[mod["modinfo_path"]][env] = size_kb - log_ok(f"[{idx}/{total_modules}] {mod['moduleName']}: +{delta:,} B → {size_kb} KB") + base = env_to_base_from_module(mod["usedLibs"], env) + results[mod["modinfo_path"]][base] = size_kb + log_ok(f"[{idx}/{total_modules}] {mod['moduleName']} ({base}): +{delta:,} B → {size_kb} KB") updated = 0 log_section("Updating modinfo.json") @@ -284,6 +300,12 @@ def main(): finally: shutil.copy(platformio_backup, platformio_ini) platformio_backup.unlink(missing_ok=True) + # Restore project state: run PrepareProject with original profile so all modules are as before + log_section("Restoring project state") + if run_prepare_project(profile_path, original_env): + log_ok(f"PrepareProject applied: {profile_path.name} (env={original_env})") + else: + log_fail(f"PrepareProject failed — restore manually: python PrepareProject.py -p {profile_path.name} -b {original_env}") print()