def test_filter_traces_domain_filter(self): snapshot, snapshot2 = create_snapshots() filter1 = tracemalloc.DomainFilter(False, domain=3) filter2 = tracemalloc.DomainFilter(True, domain=3) snapshot3 = snapshot.filter_traces((filter1, )) self.assertEqual(snapshot3.traces._traces, [(0, 10, (('a.py', 2), ('b.py', 4))), (0, 10, (('a.py', 2), ('b.py', 4))), (0, 10, (('a.py', 2), ('b.py', 4))), (1, 2, (('a.py', 5), ('b.py', 4))), (2, 66, (('b.py', 1), ))]) snapshot3 = snapshot.filter_traces((filter2, )) self.assertEqual(snapshot3.traces._traces, [(3, 7, (('<unknown>', 0), ))])
def get_allocated_khash_memory(): snapshot = tracemalloc.take_snapshot() snapshot = snapshot.filter_traces( (tracemalloc.DomainFilter(True, ht.get_hashtable_trace_domain()),) ) return sum(map(lambda x: x.size, snapshot.traces))
def get_traced_memory(self): # Get the traced size in the domain snapshot = tracemalloc.take_snapshot() domain_filter = tracemalloc.DomainFilter(True, self.domain) snapshot = snapshot.filter_traces([domain_filter]) return sum(trace.size for trace in snapshot.traces)