MCPcopy Index your code
hub / github.com/python/cpython / test_reset_peak

Method test_reset_peak

Lib/test/test_tracemalloc.py:277–299  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

275 self.assertIsNone(traceback2)
276
277 def test_reset_peak(self):
278 # Python allocates some internals objects, so the test must tolerate
279 # a small difference between the expected size and the real usage
280 tracemalloc.clear_traces()
281
282 # Example: allocate a large piece of memory, temporarily
283 large_sum = sum(list(range(100000)))
284 size1, peak1 = tracemalloc.get_traced_memory()
285
286 # reset_peak() resets peak to traced memory: peak2 < peak1
287 tracemalloc.reset_peak()
288 size2, peak2 = tracemalloc.get_traced_memory()
289 self.assertGreaterEqual(peak2, size2)
290 self.assertLess(peak2, peak1)
291
292 # check that peak continue to be updated if new memory is allocated:
293 # peak3 > peak2
294 obj_size = 1024 * 1024
295 obj, obj_traceback = allocate_bytes(obj_size)
296 size3, peak3 = tracemalloc.get_traced_memory()
297 self.assertGreaterEqual(peak3, size3)
298 self.assertGreater(peak3, peak2)
299 self.assertGreaterEqual(peak3 - peak2, obj_size)
300
301 def test_is_tracing(self):
302 tracemalloc.stop()

Callers

nothing calls this directly

Calls 6

listClass · 0.85
allocate_bytesFunction · 0.85
get_traced_memoryMethod · 0.80
assertGreaterEqualMethod · 0.80
assertGreaterMethod · 0.80
assertLessMethod · 0.45

Tested by

no test coverage detected