tracemalloc.start()

tracemalloc.start(nframe: int=1) Start tracing Python memory allocations: install hooks on Python memory allocators. Collected tracebacks of traces will be limited to nframe frames. By default, a trace of a memory block only stores the most recent frame: the limit is 1. nframe must be greater or equal to 1. Storing more than 1 frame is only useful to compute statistics grouped by 'traceback' or to compute cumulative statistics: see the Snapshot.compare_to() and Snapshot.statistics() methods.

tracemalloc.Snapshot.load()

classmethod load(filename) Load a snapshot from a file. See also dump().

tracemalloc.get_traced_memory()

tracemalloc.get_traced_memory() Get the current size and peak size of memory blocks traced by the tracemalloc module as a tuple: (current: int, peak: int).

tracemalloc.is_tracing()

tracemalloc.is_tracing() True if the tracemalloc module is tracing Python memory allocations, False otherwise. See also start() and stop() functions.

tracemalloc.get_tracemalloc_memory()

tracemalloc.get_tracemalloc_memory() Get the memory usage in bytes of the tracemalloc module used to store traces of memory blocks. Return an int.

tracemalloc.Snapshot.dump()

dump(filename) Write the snapshot into a file. Use load() to reload the snapshot.

tracemalloc.Snapshot.compare_to()

compare_to(old_snapshot: Snapshot, group_by: str, cumulative: bool=False) Compute the differences with an old snapshot. Get statistics as a sorted list of StatisticDiff instances grouped by group_by. See the Snapshot.statistics() method for group_by and cumulative parameters. The result is sorted from the biggest to the smallest by: absolute value of StatisticDiff.size_diff, StatisticDiff.size, absolute value of StatisticDiff.count_diff, Statistic.count and then by StatisticDiff.traceback.

tracemalloc.Snapshot

class tracemalloc.Snapshot Snapshot of traces of memory blocks allocated by Python. The take_snapshot() function creates a snapshot instance. compare_to(old_snapshot: Snapshot, group_by: str, cumulative: bool=False) Compute the differences with an old snapshot. Get statistics as a sorted list of StatisticDiff instances grouped by group_by. See the Snapshot.statistics() method for group_by and cumulative parameters. The result is sorted from the biggest to the smallest by: absolute value o

tracemalloc.get_traceback_limit()

tracemalloc.get_traceback_limit() Get the maximum number of frames stored in the traceback of a trace. The tracemalloc module must be tracing memory allocations to get the limit, otherwise an exception is raised. The limit is set by the start() function.

tracemalloc.get_object_traceback()

tracemalloc.get_object_traceback(obj) Get the traceback where the Python object obj was allocated. Return a Traceback instance, or None if the tracemalloc module is not tracing memory allocations or did not trace the allocation of the object. See also gc.get_referrers() and sys.getsizeof() functions.