MCPcopy Index your code
hub / github.com/python/cpython / print_memstats

Function print_memstats

Tools/peg_generator/pegen/testutil.py:116–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114
115
116def print_memstats() -> bool:
117 MiB: Final = 2**20
118 try:
119 import psutil
120 except ImportError:
121 return False
122 print("Memory stats:")
123 process = psutil.Process()
124 meminfo = process.memory_info()
125 res = {}
126 res["rss"] = meminfo.rss / MiB
127 res["vms"] = meminfo.vms / MiB
128 if sys.platform == "win32":
129 res["maxrss"] = meminfo.peak_wset / MiB
130 else:
131 # See https://stackoverflow.com/questions/938733/total-memory-used-by-python-process
132 import resource # Since it doesn't exist on Windows.
133
134 rusage = resource.getrusage(resource.RUSAGE_SELF)
135 if sys.platform == "darwin":
136 factor = 1
137 else:
138 factor = 1024 # Linux
139 res["maxrss"] = rusage.ru_maxrss * factor / MiB
140 for key, value in res.items():
141 print(f" {key:12.12s}: {value:10.0f} MiB")
142 return True

Callers 1

mainFunction · 0.90

Calls 2

ProcessMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…