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

Method test_get_traced_memory

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

Source from the content-addressed store, hash-verified

230 self.assertIs(traceback2, traceback1)
231
232 def test_get_traced_memory(self):
233 # Python allocates some internals objects, so the test must tolerate
234 # a small difference between the expected size and the real usage
235 max_error = 2048
236
237 # allocate one object
238 obj_size = 1024 * 1024
239 tracemalloc.clear_traces()
240 obj, obj_traceback = allocate_bytes(obj_size)
241 size, peak_size = tracemalloc.get_traced_memory()
242 self.assertGreaterEqual(size, obj_size)
243 self.assertGreaterEqual(peak_size, size)
244
245 self.assertLessEqual(size - obj_size, max_error)
246 self.assertLessEqual(peak_size - size, max_error)
247
248 # destroy the object
249 obj = None
250 size2, peak_size2 = tracemalloc.get_traced_memory()
251 self.assertLess(size2, size)
252 self.assertGreaterEqual(size - size2, obj_size - max_error)
253 self.assertGreaterEqual(peak_size2, peak_size)
254
255 # clear_traces() must reset traced memory counters
256 tracemalloc.clear_traces()
257 self.assertEqual(tracemalloc.get_traced_memory(), (0, 0))
258
259 # allocate another object
260 obj, obj_traceback = allocate_bytes(obj_size)
261 size, peak_size = tracemalloc.get_traced_memory()
262 self.assertGreaterEqual(size, obj_size)
263
264 # stop() also resets traced memory counters
265 tracemalloc.stop()
266 self.assertEqual(tracemalloc.get_traced_memory(), (0, 0))
267
268 def test_clear_traces(self):
269 obj, obj_traceback = allocate_bytes(123)

Callers

nothing calls this directly

Calls 7

allocate_bytesFunction · 0.85
get_traced_memoryMethod · 0.80
assertGreaterEqualMethod · 0.80
assertLessEqualMethod · 0.80
assertLessMethod · 0.45
assertEqualMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected