##// END OF EJS Templates
dirstate: add a `set_tracked` method for "hg add"-like usage...
dirstate: add a `set_tracked` method for "hg add"-like usage This is a step further toward clarifying the semantic of various dirstate call. Having a dedicated function comes with a couple of benefits: 1) we can move duplicated logic about how to handle the previous state within the dirstate. Since we are sure this is always called in the same situation, we can implement that logic once in the dirstate. 2) having a dedicated method for this case unlock also having a dedicated method for the other case and recording more information at that time. All this leading having more code within the dirstate and higher level API that are less error prone. Differential Revision: https://phab.mercurial-scm.org/D11013

File last commit:

r46393:5b6c0af0 default
r48393:f927ad5a default
Show More
memorytop.py
44 lines | 1.4 KiB | text/x-python | PythonLexer
Joerg Sonnenberger
utils: helper function to print top memory allocation site...
r46393 # 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()