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

Function load

scripts/memwaste-report.py:77–111  ·  view source on GitHub ↗

{pid: {"header": last header, "headers": [...], "sites": {addr: row}, "snap_max": {addr: {...}}, "work": {(kind, addr): row}}} — sites/work from the LAST dump of the process.

(path: str)

Source from the content-addressed store, hash-verified

75
76
77def load(path: str):
78 """{pid: {"header": last header, "headers": [...], "sites": {addr: row}, "snap_max": {addr: {...}},
79 "work": {(kind, addr): row}}} — sites/work from the LAST dump of the process."""
80 procs: dict[int, dict] = {}
81 cur = None
82 with open(path, encoding="utf-8", errors="replace") as fh:
83 for line in fh:
84 line = line.strip()
85 if not line:
86 continue
87 try:
88 obj = json.loads(line)
89 except json.JSONDecodeError:
90 continue # a torn line from a process that died mid-write
91 if "memwaste" in obj:
92 pid = int(obj.get("pid", 0))
93 p = procs.setdefault(pid, {"headers": [], "snap_max": defaultdict(dict)})
94 p["headers"].append(obj)
95 p["header"] = obj
96 p["sites"] = {}
97 p["work"] = {}
98 cur = p
99 elif cur is None:
100 continue
101 elif "work" in obj:
102 cur["work"][(obj["work"], obj["site"])] = obj
103 elif "site" in obj:
104 cur["sites"][obj["site"]] = obj
105 snap = cur["snap_max"][obj["site"]]
106 for f in SNAPSHOT_FIELDS:
107 v = obj.get(f, 0)
108 if v > snap.get(f, 0):
109 snap[f] = v
110 snap[f + "_phase"] = cur["header"].get("phase_label", "?")
111 return procs
112
113
114def pe_image_base(binary: str) -> int | None:

Callers 2

mainFunction · 0.70
cbm_preprocess_with_mapFunction · 0.50

Calls 2

getMethod · 0.65
openFunction · 0.50

Tested by

no test coverage detected