Python 3.6+tracemallocterm
tracemalloc.DomainFilter
filters
A trace filter by address space (domain): it separates Python memory from memory reported by C extensions.
Syntax
tracemalloc.DomainFilter(inclusive, domain)
The Python allocator records everything in domain 0. Extensions such as NumPy report their buffers through the C API in a domain of their own, and in a snapshot those traces are mixed with the usual ones. DomainFilter(False, 0) keeps only "foreign" memory, DomainFilter(True, 0) only Python's. Unlike Filter, the file name is not checked. Added in 3.6.
Examples
import tracemalloc
tracemalloc.start()
data = bytes(10_000)
snap = tracemalloc.take_snapshot()
python_only = snap.filter_traces([tracemalloc.DomainFilter(True, 0)])
foreign = snap.filter_traces([tracemalloc.DomainFilter(False, 0)])
print(len(python_only.traces) > 0, len(foreign.traces)) # → True 0
tracemalloc.stop()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy