{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)
| 75 | |
| 76 | |
| 77 | def 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 | |
| 114 | def pe_image_base(binary: str) -> int | None: |
no test coverage detected