MCPcopy Create free account
hub / github.com/vercel/vercel / generate_plain_report

Function generate_plain_report

packages/python-analysis/scripts/profile-wasm.py:647–683  ·  view source on GitHub ↗

Generate a plain-text report (no colors) for file output.

(section_sizes, crate_sizes, entries, top_n)

Source from the content-addressed store, hash-verified

645
646
647def generate_plain_report(section_sizes, crate_sizes, entries, top_n):
648 """Generate a plain-text report (no colors) for file output."""
649 total_code = section_sizes.get("CODE", 0)
650 total_rodata = section_sizes.get(".rodata", 0)
651 total_data_seg = section_sizes.get(".data", 0) + section_sizes.get(".bss", 0)
652 total_data = total_rodata + total_data_seg
653 total = total_code + total_data
654
655 lines = []
656 lines.append("=== WASM Binary Size Analysis ===")
657 lines.append(f"Total (code+data): {format_bytes_long(total)}")
658 if total > 0:
659 lines.append(f" Code: {total_code:>10,} bytes ({100*total_code/total:.1f}%)")
660 lines.append(f" Data: {total_data:>10,} bytes ({100*total_data/total:.1f}%)")
661 lines.append(f" .rodata: {total_rodata:>10,} bytes")
662 lines.append(f" .data: {total_data_seg:>10,} bytes")
663 lines.append("")
664
665 sorted_crates = sorted(crate_sizes.items(), key=lambda x: x[1]["total"], reverse=True)
666 lines.append(f"=== Top {min(top_n, len(sorted_crates))} Crates by Size ===")
667 lines.append(f" {'#':>3} {'crate':<30} {'total':>10} {'code':>10} {'data':>10} {'%':>5}")
668 for i, (crate, sizes) in enumerate(sorted_crates[:top_n], 1):
669 pct = 100 * sizes["total"] / total if total else 0
670 data_sz = sizes["rodata"] + sizes["data"]
671 lines.append(
672 f" {i:3}. {crate:<30} {sizes['total']:>10,} {sizes['code']:>10,} {data_sz:>10,} {pct:5.1f}%"
673 )
674 lines.append("")
675
676 sorted_items = sorted(entries, key=lambda x: x[3], reverse=True)
677 lines.append(f"=== Top {min(top_n, len(sorted_items))} Items by Size ===")
678 for i, (section, crate, symbol, size) in enumerate(sorted_items[:top_n], 1):
679 label = symbol if symbol else f"[{section}]"
680 lines.append(f" {i:3}. {crate:<25} {label:<50} {size:>10,} bytes")
681 lines.append("")
682
683 return "\n".join(lines)
684
685
686# ---------------------------------------------------------------------------

Callers 1

mainFunction · 0.85

Calls 5

format_bytes_longFunction · 0.85
appendMethod · 0.80
getMethod · 0.65
itemsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected