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

Function render_items_table

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

Render the top items table with a two-line layout per item.

(entries, top_n)

Source from the content-addressed store, hash-verified

570
571
572def render_items_table(entries, top_n):
573 """Render the top items table with a two-line layout per item."""
574 header(f"Top {top_n} Items by Size")
575 sorted_items = sorted(entries, key=lambda x: x[3], reverse=True)
576 if not sorted_items:
577 iprint(f"{DIM}(no data){RESET}")
578 return
579
580 max_size = sorted_items[0][3]
581 total_size = sum(e[3] for e in sorted_items)
582 # Bar fills the available width minus the fixed-width suffix
583 bar_w = max(10, _TERM_WIDTH - 28) # leave room for size + pct
584
585 for i, (section, crate, symbol, size) in enumerate(sorted_items[:top_n], 1):
586 short = shorten_symbol(crate, symbol)
587 is_code = section == "CODE"
588 c = CYAN if is_code else MAGENTA
589 kind_tag = f"{CYAN}fn{RESET}" if is_code else f"{MAGENTA}data{RESET}"
590
591 # Line 1: rank, kind, crate :: symbol (full width, truncate if needed)
592 if short:
593 sym_display = short
594 else:
595 sym_display = f"[{section}]"
596 max_sym = _TERM_WIDTH - len(crate) - 14 # rank(4) + kind(4) + " :: "(4) + margin
597 if len(sym_display) > max_sym > 10:
598 sym_display = sym_display[:max_sym - 1] + "\u2026"
599
600 if short:
601 line1_label = f"{BOLD}{crate}{RESET}{DIM}::{RESET}{sym_display}"
602 else:
603 line1_label = f"{BOLD}{crate}{RESET} {DIM}{sym_display}{RESET}"
604
605 iprint(f"{DIM}{i:>3}.{RESET} {kind_tag} {line1_label}")
606
607 # Line 2: bar + size + percentage
608 frac = size / max_size if max_size else 0
609 pct = 100 * size / total_size if total_size else 0
610 iprint(f" {bar(frac, bar_w, c)} {format_bytes(size):>10} {DIM}{pct:5.1f}%{RESET}")
611
612
613def hyperlink(url, text):

Callers 1

mainFunction · 0.85

Calls 5

iprintFunction · 0.85
shorten_symbolFunction · 0.85
barFunction · 0.85
format_bytesFunction · 0.85
headerFunction · 0.70

Tested by

no test coverage detected