MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / report

Function report

scripts/memlab-report.py:97–145  ·  view source on GitHub ↗
(path, census_path, top, binary=None)

Source from the content-addressed store, hash-verified

95
96
97def report(path, census_path, top, binary=None):
98 summaries, series = load_profile(path)
99 if not summaries and not series:
100 print(f"{path}: no waste-layer records -- was the memwaste flavour run with CBM_MEMWASTE=1?")
101 return
102 names = load_symbols(binary, summaries, series.keys())
103 last = summaries[-1] if summaries else {}
104 print(f"=== {path} ===")
105 if last:
106 print(f"samples : {len(summaries)} dumps (every allocation size is tracked)")
107 print(f"sites seen : {last.get('sites', 0)}")
108 print(f"attributed live: {last.get('live_bytes', 0)/1048576:.1f} MB "
109 f"in {last.get('live_blocks', 0)} blocks")
110 lost = last.get("site_table_full", 0) + last.get("pointer_table_full", 0)
111 if lost:
112 print(f"RECORDS LOST : {lost} — tables exhausted, treat totals as a floor")
113
114 growth = []
115 for site, samples in series.items():
116 live = [s["live_bytes"] for s in samples]
117 slope = linear_slope(live)
118 if slope <= 0 and live[-1] <= live[0]:
119 continue
120 growth.append((slope, live[-1] - live[0], live[-1], names.get(site, site)))
121 growth.sort(key=lambda row: row[0], reverse=True)
122
123 print(f"\n--- sites whose retained bytes GROW (top {top}) ---")
124 if not growth:
125 print("none — no tracked site retains more over time.")
126 for slope, delta, live, name in growth[:top]:
127 print(f" +{slope/1024:8.1f} KB/sample total +{delta/1048576:6.2f} MB "
128 f"live {live/1048576:6.2f} MB")
129 print(f" {name}")
130
131 if census_path:
132 rows = parse_census(census_path)
133 if rows:
134 priv = [r["priv_kb"] for r in rows if "priv_kb" in r]
135 # attributed = what the waste layer holds live, sampled at its own dumps
136 prof = [int(h.get("live_bytes", 0)) // 1024 for h in summaries]
137 print(f"\n--- pools vs attribution ({len(rows)} samples) ---")
138 if priv:
139 print(f" private committed : {priv[0]/1024:.1f} -> {priv[-1]/1024:.1f} MB "
140 f"({linear_slope(priv):+.1f} KB/sample)")
141 if prof and priv:
142 unattributed = (priv[-1] - priv[0]) - (prof[-1] - prof[0])
143 print(f" attributed growth : {(prof[-1]-prof[0])/1024:+.1f} MB")
144 print(f" UNATTRIBUTED : {unattributed/1024:+.1f} MB "
145 "<- allocator metadata, fragmentation, or memory outside malloc (mmap, stacks)")
146
147
148def diff(path_a, path_b, top, binary=None):

Callers 1

mainFunction · 0.70

Calls 6

load_profileFunction · 0.85
load_symbolsFunction · 0.85
linear_slopeFunction · 0.85
parse_censusFunction · 0.85
keysMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected