MCPcopy Create free account
hub / github.com/1jehuang/jcode / print_human

Function print_human

scripts/jcode_memory_snapshot.py:199–230  ·  view source on GitHub ↗
(server: list[ProcMem], clients: list[ProcMem], aux: list[ProcMem])

Source from the content-addressed store, hash-verified

197
198
199def print_human(server: list[ProcMem], clients: list[ProcMem], aux: list[ProcMem]) -> None:
200 def print_group(name: str, procs: list[ProcMem]) -> None:
201 totals = sum_totals(procs)
202 print(f"\n{name} ({totals.count})")
203 print("-" * len(f"{name} ({totals.count})"))
204 print(
205 f"total: RSS {totals.rss_mb:.1f} MB | PSS {totals.pss_mb:.1f} MB | "
206 f"Anon {totals.anon_mb:.1f} MB | Private dirty {totals.private_dirty_mb:.1f} MB"
207 )
208 for p in sorted(procs, key=lambda x: (x.role, -x.pss_mb, x.pid)):
209 label = p.session_id or p.role
210 print(
211 f" pid {p.pid:<7} {label:<48} RSS {p.rss_mb:>6.1f} | PSS {p.pss_mb:>6.1f} | "
212 f"Anon {p.anon_mb:>6.1f} | PrivDirty {p.private_dirty_mb:>6.1f}"
213 )
214
215 print_group("Server", server)
216 print_group("Clients", clients)
217 if aux:
218 print_group("Auxiliary", aux)
219
220 grand = sum_totals(server + clients)
221 print("\nPrimary total (server + clients)")
222 print("--------------------------------")
223 print(
224 f"RSS {grand.rss_mb:.1f} MB | PSS {grand.pss_mb:.1f} MB | "
225 f"Anon {grand.anon_mb:.1f} MB | Private dirty {grand.private_dirty_mb:.1f} MB | "
226 f"Shared clean {grand.shared_clean_mb:.1f} MB"
227 )
228 print(
229 f"Overcount if you sum RSS instead of PSS: {round(grand.rss_mb - grand.pss_mb, 1):.1f} MB"
230 )
231
232
233def main() -> int:

Callers 1

mainFunction · 0.70

Calls 2

print_groupFunction · 0.85
sum_totalsFunction · 0.85

Tested by

no test coverage detected