Mercurial > hg
view mercurial/utils/memorytop.py @ 51686:39033e7a6e0a
convert: stringify `shlex` class argument
The documentation is handwavy, but typeshed says this should be `str`[1]. I'm
not sure if this is the correct encoding (vs `fsencode` or "latin1" like the
tokens returned by the proxy class).
While we're here, we can add a few more type hints that would have caused pytype
to flag the problem.
[1] https://github.com/python/typeshed/blob/6a9b53e719a139c2d6b41cf265ed0990cf438192/stdlib/shlex.pyi#L51
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 11 Jul 2024 21:16:45 -0400 |
parents | 5b6c0af021da |
children | 1c5810ce737e |
line wrap: on
line source
# memorytop requires Python 3.4 # # Usage: set PYTHONTRACEMALLOC=n in the environment of the hg invocation, # where n>= is the number of frames to show in the backtrace. Put calls to # memorytop in strategic places to show the current memory use by allocation # site. import gc import tracemalloc def memorytop(limit=10): gc.collect() snapshot = tracemalloc.take_snapshot() snapshot = snapshot.filter_traces( ( tracemalloc.Filter(False, "<frozen importlib._bootstrap>"), tracemalloc.Filter(False, "<frozen importlib._bootstrap_external>"), tracemalloc.Filter(False, "<unknown>"), ) ) stats = snapshot.statistics('traceback') total = sum(stat.size for stat in stats) print("\nTotal allocated size: %.1f KiB\n" % (total / 1024)) print("Lines with the biggest net allocations") for index, stat in enumerate(stats[:limit], 1): print( "#%d: %d objects using %.1f KiB" % (index, stat.count, stat.size / 1024) ) for line in stat.traceback.format(most_recent_first=True): print(' ', line) other = stats[limit:] if other: size = sum(stat.size for stat in other) count = sum(stat.count for stat in other) print( "%s other: %d objects using %.1f KiB" % (len(other), count, size / 1024) ) print()