MCPcopy Index your code
hub / github.com/python/mypy / print_memory_profile

Function print_memory_profile

mypy/memprofile.py:69–91  ·  view source on GitHub ↗
(run_gc: bool = True)

Source from the content-addressed store, hash-verified

67
68
69def print_memory_profile(run_gc: bool = True) -> None:
70 if not sys.platform.startswith("win"):
71 import resource
72
73 system_memuse = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
74 else:
75 system_memuse = -1 # TODO: Support this on Windows
76 if run_gc:
77 gc.collect()
78 freqs, memuse = collect_memory_stats()
79 print("%7s %7s %7s %s" % ("Freq", "Size(k)", "AvgSize", "Type"))
80 print("-------------------------------------------")
81 totalmem = 0
82 i = 0
83 for n, mem in sorted(memuse.items(), key=lambda x: -x[1]):
84 f = freqs[n]
85 if i < 50:
86 print("%7d %7d %7.0f %s" % (f, mem // 1024, mem / f, n))
87 i += 1
88 totalmem += mem
89 print()
90 print("Mem usage RSS ", system_memuse // 1024)
91 print("Total reachable ", totalmem // 1024)
92
93
94def find_recursive_objects(objs: list[object]) -> None:

Callers 2

mainFunction · 0.90

Calls 6

collect_memory_statsFunction · 0.85
printFunction · 0.85
sortedFunction · 0.85
startswithMethod · 0.45
collectMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…