(run_gc: bool = True)
| 67 | |
| 68 | |
| 69 | def 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 | |
| 94 | def find_recursive_objects(objs: list[object]) -> None: |
no test coverage detected
searching dependent graphs…