aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_tracemalloc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_tracemalloc.py')
-rw-r--r--Lib/test/test_tracemalloc.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index 635a9d39816..c5ae4e6d653 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -246,6 +246,30 @@ class TestTracemallocEnabled(unittest.TestCase):
traceback2 = tracemalloc.get_object_traceback(obj)
self.assertIsNone(traceback2)
+ def test_reset_peak(self):
+ # Python allocates some internals objects, so the test must tolerate
+ # a small difference between the expected size and the real usage
+ tracemalloc.clear_traces()
+
+ # Example: allocate a large piece of memory, temporarily
+ large_sum = sum(list(range(100000)))
+ size1, peak1 = tracemalloc.get_traced_memory()
+
+ # reset_peak() resets peak to traced memory: peak2 < peak1
+ tracemalloc.reset_peak()
+ size2, peak2 = tracemalloc.get_traced_memory()
+ self.assertGreaterEqual(peak2, size2)
+ self.assertLess(peak2, peak1)
+
+ # check that peak continue to be updated if new memory is allocated:
+ # peak3 > peak2
+ obj_size = 1024 * 1024
+ obj, obj_traceback = allocate_bytes(obj_size)
+ size3, peak3 = tracemalloc.get_traced_memory()
+ self.assertGreaterEqual(peak3, size3)
+ self.assertGreater(peak3, peak2)
+ self.assertGreaterEqual(peak3 - peak2, obj_size)
+
def test_is_tracing(self):
tracemalloc.stop()
self.assertFalse(tracemalloc.is_tracing())