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

Function main

scripts/memwaste-ratchet.py:58–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56
57
58def main() -> int:
59 ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
60 ap.add_argument("--out", required=True, help="memwaste.sh --out directory")
61 ap.add_argument("--venue", required=True, help="baseline key, e.g. pr-linux, dryrun-macos")
62 ap.add_argument("--tolerance", type=float, default=0.05, help="allowed growth before a class fails")
63 ap.add_argument("--enforce", action="store_true")
64 ap.add_argument("--record", action="store_true")
65 args = ap.parse_args()
66
67 cur = current(args.out)
68 base_all = json.load(open(BASELINE)) if os.path.exists(BASELINE) else {}
69 if args.record:
70 base_all[args.venue] = cur
71 with open(BASELINE, "w") as fh:
72 json.dump(base_all, fh, indent=1, sort_keys=True)
73 fh.write("\n")
74 print(f"baseline recorded for {args.venue} ({cur['nodes']:,} nodes)")
75 return 0
76 base = base_all.get(args.venue)
77 if not base:
78 print(f"no baseline for {args.venue}: nothing to hold yet (record one with --record)")
79 return 0
80
81 worse, better = [], []
82 print(f"{'class':<28} {'baseline/1k':>14} {'now/1k':>14} {'delta':>8}")
83 for c in CLASSES:
84 b = base["per_1k_nodes"].get(c, 0.0)
85 n = cur["per_1k_nodes"].get(c, 0.0)
86 delta = (n - b) / b if b else (0.0 if n == 0 else float("inf"))
87 mark = ""
88 if delta > args.tolerance:
89 worse.append(c)
90 mark = " WORSE"
91 elif delta < -args.tolerance:
92 better.append(c)
93 mark = " better"
94 shown = "new" if delta == float("inf") else f"{delta * 100:+.1f}%"
95 print(f"{c:<28} {b:>14,.3f} {n:>14,.3f} {shown:>8}{mark}")
96 if better:
97 print(f"\n{len(better)} class(es) improved beyond tolerance: lower the baseline with --record")
98 if worse:
99 print(f"\n{len(worse)} class(es) grew beyond {args.tolerance * 100:.0f}%: {', '.join(worse)}")
100 return 1 if args.enforce else 0
101 return 0
102
103
104if __name__ == "__main__":

Callers 1

Calls 5

loadMethod · 0.80
currentFunction · 0.70
getMethod · 0.65
openFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected