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

Function main

scripts/memwaste-report.py:229–388  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

227
228
229def main() -> int:
230 ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
231 ap.add_argument("dump")
232 ap.add_argument("--binary", help="the binary that produced the dump, for symbolisation")
233 ap.add_argument("--top", type=int, default=20)
234 ap.add_argument("--sort", choices=sorted(SITE_SORTS), default="bytes")
235 ap.add_argument("--json", action="store_true", help="emit the merged tables as JSON")
236 args = ap.parse_args()
237
238 procs = load(args.dump)
239 if not procs:
240 print("no waste-sanitizer dump found in", args.dump, file=sys.stderr)
241 return 2
242
243 names_by_pid = {}
244 for pid, p in procs.items():
245 addrs = list(p["sites"].keys()) + [a for (_, a) in p["work"].keys()]
246 names_by_pid[pid] = symbolise(args.binary, p["header"].get("image_base", "0x0"), addrs)
247
248 if args.json:
249 out = {"processes": {}}
250 for pid, p in procs.items():
251 names = names_by_pid[pid]
252 out["processes"][str(pid)] = {
253 "header": p["header"],
254 "phases": [h.get("phase_label") for h in p["headers"]],
255 "summary": summarise(p, names),
256 "sites": [dict(r, name=names.get(a, a),
257 **{(k if k.endswith("_phase") else k + "_max"): v
258 for k, v in p["snap_max"].get(a, {}).items()})
259 for a, r in p["sites"].items()],
260 "work": [dict(w, name=names.get(a, a)) for (_, a), w in p["work"].items()],
261 }
262 json.dump(out, sys.stdout, indent=1)
263 print()
264 return 0
265
266 # Work-heavy processes first: the index worker is the one that matters.
267 order = sorted(procs.items(), key=lambda kv: -kv[1]["header"].get("usable_bytes", 0))
268 for pid, p in order:
269 h = p["header"]
270 names = names_by_pid[pid]
271 s = summarise(p, names)
272 print("=" * 110)
273 print(f"process {pid} last dump={h.get('why')} phases={len(p['headers'])} allocs={h['allocs']:,} "
274 f"cum={h['usable_bytes'] / MB:,.0f} MB live={h['live_bytes'] / MB:,.0f} MB "
275 f"rss={h.get('rss_bytes', 0) / MB:,.0f} MB sites={h['sites']:,} fill={h.get('fill')} access={h.get('access')} "
276 f"layer={h.get('layer_vm_bytes', 0) / MB:,.0f} MB/{h.get('layer_threads', 0)} threads")
277 blind = {k: h.get(k, 0) for k in ("site_table_full", "pointer_table_full", "work_table_full", "untracked_frees")}
278 if any(blind.values()):
279 print(" blind spots: " + " ".join(f"{k}={v:,}" for k, v in blind.items()))
280 if h.get("foreign_frees", 0):
281 print(f" outside the shim: {h['foreign_frees']:,} frees of blocks another allocator made "
282 "(C runtime / system DLL; their allocations are invisible to the layer)")
283 print()
284 print(" WASTE SUMMARY")
285 for key, label, unit in WASTE_CLASSES:
286 v = s.get(key, 0)

Callers 1

memwaste-report.pyFile · 0.70

Calls 11

symboliseFunction · 0.85
strFunction · 0.85
summariseFunction · 0.85
fmtFunction · 0.85
pctFunction · 0.85
keysMethod · 0.80
loadFunction · 0.70
sectionFunction · 0.70
getMethod · 0.65
listFunction · 0.50
keyFunction · 0.50

Tested by

no test coverage detected