MCPcopy Create free account
hub / github.com/FastLED/FastLED / print_summary

Function print_summary

ci/bloat.py:204–245  ·  view source on GitHub ↗

Read report.json and print a top-N table of flash bloat.

(report_json: Path, top: int)

Source from the content-addressed store, hash-verified

202
203
204def print_summary(report_json: Path, top: int) -> None:
205 """Read report.json and print a top-N table of flash bloat."""
206 data = json.loads(report_json.read_text(encoding="utf-8"))
207 flash_syms = [s for s in data["symbols"] if s["region"] == "flash"]
208 total_flash: int = int(data["total_flash"])
209 total_ram: int = int(data["total_ram"])
210
211 by_name: dict[str, _AggBucket] = {}
212 for s in flash_syms:
213 n: str = s["demangled"]
214 bucket = by_name.setdefault(n, _AggBucket())
215 bucket.size += int(s["size"])
216 if not bucket.archive:
217 bucket.archive = s.get("archive") or "(none)"
218 bucket.object = s.get("object") or "-"
219 bucket.sources.add(s["source"])
220
221 rows: list[tuple[str, _AggBucket]] = sorted(
222 by_name.items(), key=lambda kv: -kv[1].size
223 )[:top]
224
225 print()
226 print(
227 f"Total flash: {total_flash:,} B "
228 f"({len(flash_syms):,} sized flash symbols). "
229 f"RAM: {total_ram:,} B."
230 )
231 print()
232 print(f"{'#':>3} {'BYTES':>8} {'ARCHIVE':<22} {'OBJECT':<26} SYMBOL")
233 print("-" * 120)
234 for i, (name, bucket) in enumerate(rows, 1):
235 srcs = "/".join(sorted(bucket.sources))
236 shown = name if len(name) <= 70 else name[:67] + "..."
237 print(
238 f"{i:>3} {bucket.size:>8,} "
239 f"{bucket.archive[:22]:<22} {bucket.object[:26]:<26} "
240 f"{shown} [{srcs}]"
241 )
242 print()
243 print("Artifacts:")
244 print(f" JSON: {report_json}")
245 print(f" MD: {report_json.with_name('report.md')}")
246
247
248def main() -> int:

Callers 1

mainFunction · 0.70

Calls 5

_AggBucketClass · 0.85
itemsMethod · 0.80
printFunction · 0.50
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected