summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tracemalloc.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-10-25 11:31:16 (GMT)
committerGitHub <noreply@github.com>2018-10-25 11:31:16 (GMT)
commit9e00e80e213ebc37eff89ce72102c1f928ebc133 (patch)
tree50b24d69615a7994aeb4d776adc8666fcec5aafd /Lib/test/test_tracemalloc.py
parentd7c3e5f0e89cb807093e33165815c8bbd3c00f4b (diff)
downloadcpython-9e00e80e213ebc37eff89ce72102c1f928ebc133.zip
cpython-9e00e80e213ebc37eff89ce72102c1f928ebc133.tar.gz
cpython-9e00e80e213ebc37eff89ce72102c1f928ebc133.tar.bz2
bpo-35053: Enhance tracemalloc to trace free lists (GH-10063)
tracemalloc now tries to update the traceback when an object is reused from a "free list" (optimization for faster object creation, used by the builtin list type for example). Changes: * Add _PyTraceMalloc_NewReference() function which tries to update the Python traceback of a Python object. * _Py_NewReference() now calls _PyTraceMalloc_NewReference(). * Add an unit test.
Diffstat (limited to 'Lib/test/test_tracemalloc.py')
-rw-r--r--Lib/test/test_tracemalloc.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index 76a6159..c386648 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -111,6 +111,26 @@ class TestTracemallocEnabled(unittest.TestCase):
traceback = tracemalloc.get_object_traceback(obj)
self.assertEqual(traceback, obj_traceback)
+ def test_new_reference(self):
+ tracemalloc.clear_traces()
+ # gc.collect() indirectly calls PyList_ClearFreeList()
+ support.gc_collect()
+
+ # Create a list and "destroy it": put it in the PyListObject free list
+ obj = []
+ obj = None
+
+ # Create a list which should reuse the previously created empty list
+ obj = []
+
+ nframe = tracemalloc.get_traceback_limit()
+ frames = get_frames(nframe, -3)
+ obj_traceback = tracemalloc.Traceback(frames)
+
+ traceback = tracemalloc.get_object_traceback(obj)
+ self.assertIsNotNone(traceback)
+ self.assertEqual(traceback, obj_traceback)
+
def test_set_traceback_limit(self):
obj_size = 10