当前位置: 首页>>代码示例>>Python>>正文


Python tracemalloc.clear_traces函数代码示例

本文整理汇总了Python中tracemalloc.clear_traces函数的典型用法代码示例。如果您正苦于以下问题:Python clear_traces函数的具体用法?Python clear_traces怎么用?Python clear_traces使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了clear_traces函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_traced_memory

    def test_get_traced_memory(self):
        # Python allocates some internals objects, so the test must tolerate
        # a small difference between the expected size and the real usage
        max_error = 2048

        # allocate one object
        obj_size = 1024 * 1024
        tracemalloc.clear_traces()
        obj, obj_traceback = allocate_bytes(obj_size)
        size, peak_size = tracemalloc.get_traced_memory()
        self.assertGreaterEqual(size, obj_size)
        self.assertGreaterEqual(peak_size, size)

        self.assertLessEqual(size - obj_size, max_error)
        self.assertLessEqual(peak_size - size, max_error)

        # destroy the object
        obj = None
        size2, peak_size2 = tracemalloc.get_traced_memory()
        self.assertLess(size2, size)
        self.assertGreaterEqual(size - size2, obj_size - max_error)
        self.assertGreaterEqual(peak_size2, peak_size)

        # clear_traces() must reset traced memory counters
        tracemalloc.clear_traces()
        self.assertEqual(tracemalloc.get_traced_memory(), (0, 0))

        # allocate another object
        obj, obj_traceback = allocate_bytes(obj_size)
        size, peak_size = tracemalloc.get_traced_memory()
        self.assertGreaterEqual(size, obj_size)

        # stop() also resets traced memory counters
        tracemalloc.stop()
        self.assertEqual(tracemalloc.get_traced_memory(), (0, 0))
开发者ID:asvetlov,项目名称:cpython,代码行数:35,代码来源:test_tracemalloc.py

示例2: test_clear_traces

    def test_clear_traces(self):
        obj, obj_traceback = allocate_bytes(123)
        traceback = tracemalloc.get_object_traceback(obj)
        self.assertIsNotNone(traceback)

        tracemalloc.clear_traces()
        traceback2 = tracemalloc.get_object_traceback(obj)
        self.assertIsNone(traceback2)
开发者ID:asvetlov,项目名称:cpython,代码行数:8,代码来源:test_tracemalloc.py

示例3: stop

def stop():
    """ Stops application memory profiling """
    logging.debug("Stopping memory profiling")
    with _lock:
        if is_running():
            snapshot(_make_snapshot_name)
            tracemalloc.clear_traces()
            tracemalloc.stop()
开发者ID:oVirt,项目名称:ovirt-hosted-engine-ha,代码行数:8,代码来源:memory_profiler.py

示例4: test_get_tracemalloc_memory

    def test_get_tracemalloc_memory(self):
        data = [allocate_bytes(123) for count in range(1000)]
        size = tracemalloc.get_tracemalloc_memory()
        self.assertGreaterEqual(size, 0)

        tracemalloc.clear_traces()
        size2 = tracemalloc.get_tracemalloc_memory()
        self.assertGreaterEqual(size2, 0)
        self.assertLessEqual(size2, size)
开发者ID:asvetlov,项目名称:cpython,代码行数:9,代码来源:test_tracemalloc.py

示例5: test_get_traces

    def test_get_traces(self):
        tracemalloc.clear_traces()
        obj_size = 12345
        obj, obj_traceback = allocate_bytes(obj_size)

        traces = tracemalloc._get_traces()
        trace = self.find_trace(traces, obj_traceback)

        self.assertIsInstance(trace, tuple)
        domain, size, traceback = trace
        self.assertEqual(size, obj_size)
        self.assertEqual(traceback, obj_traceback._frames)

        tracemalloc.stop()
        self.assertEqual(tracemalloc._get_traces(), [])
开发者ID:asvetlov,项目名称:cpython,代码行数:15,代码来源:test_tracemalloc.py

示例6: test_get_object_traceback

 def test_get_object_traceback(self):
     tracemalloc.clear_traces()
     obj_size = 12345
     obj, obj_traceback = allocate_bytes(obj_size)
     traceback = tracemalloc.get_object_traceback(obj)
     self.assertEqual(traceback, obj_traceback)
开发者ID:asvetlov,项目名称:cpython,代码行数:6,代码来源:test_tracemalloc.py


注:本文中的tracemalloc.clear_traces函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。