pymemtrace.trace_malloc

Module pymemtrace.trace_malloc

A wrapper around the tracemalloc standard library module.

class pymemtrace.trace_malloc.TraceMalloc(statistics_granularity: str = 'lineno')[source]

A wrapper around the tracemalloc module that can compensate for tracemalloc’s memory usage.

__enter__()[source]

Take a tracemalloc snapshot.

__exit__(exc_type, exc_val, exc_tb)[source]

Take a tracemalloc snapshot and subtract the initial snapshot. Also note the tracemalloc memory usage.

__init__(statistics_granularity: str = 'lineno')[source]

statistics_granularity can be ‘filename’, ‘lineno’ or ‘traceback’.

__weakref__

list of weak references to the object (if defined)

property diff: int

The net memory usage difference recorded by tracemalloc allowing for the memory usage of tracemalloc.

net_statistics()[source]

Returns the list of statistics ignoring those from the tracemalloc module itself.

property tracemalloc_memory_usage: int | None

Returns the tracemalloc memory usage between snapshots of None of no tracing.

pymemtrace.trace_malloc.trace_malloc_log(log_level: int)[source]

Decorator that logs the decorated function the use of Python memory in bytes at the desired log level. This can be switched to a NOP by setting TraceMalloc.TRACE_ON to False.