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


Python tracemalloc.stop方法代码示例

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


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

示例1: tracemalloc_state

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def tracemalloc_state(enabled=True):
        orig_enabled = tracemalloc.is_tracing()

        def set_enabled(new_enabled):
            cur_enabled = tracemalloc.is_tracing()
            if cur_enabled == new_enabled:
                return

            if new_enabled:
                tracemalloc.start()
            else:
                tracemalloc.stop()

        set_enabled(enabled)

        try:
            yield
        finally:
            set_enabled(orig_enabled) 
开发者ID:zhuyifei1999,项目名称:guppy3,代码行数:21,代码来源:support.py

示例2: test_set_traceback_limit

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def test_set_traceback_limit(self):
        obj_size = 10

        tracemalloc.stop()
        self.assertRaises(ValueError, tracemalloc.start, -1)

        tracemalloc.stop()
        tracemalloc.start(10)
        obj2, obj2_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj2)
        self.assertEqual(len(traceback), 10)
        self.assertEqual(traceback, obj2_traceback)

        tracemalloc.stop()
        tracemalloc.start(1)
        obj, obj_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj)
        self.assertEqual(len(traceback), 1)
        self.assertEqual(traceback, obj_traceback) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_tracemalloc.py

示例3: test_get_traces_intern_traceback

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def test_get_traces_intern_traceback(self):
        # dummy wrappers to get more useful and identical frames in the traceback
        def allocate_bytes2(size):
            return allocate_bytes(size)
        def allocate_bytes3(size):
            return allocate_bytes2(size)
        def allocate_bytes4(size):
            return allocate_bytes3(size)

        # Ensure that two identical tracebacks are not duplicated
        tracemalloc.stop()
        tracemalloc.start(4)
        obj_size = 123
        obj1, obj1_traceback = allocate_bytes4(obj_size)
        obj2, obj2_traceback = allocate_bytes4(obj_size)

        traces = tracemalloc._get_traces()

        trace1 = self.find_trace(traces, obj1_traceback)
        trace2 = self.find_trace(traces, obj2_traceback)
        size1, traceback1 = trace1
        size2, traceback2 = trace2
        self.assertEqual(traceback2, traceback1)
        self.assertIs(traceback2, traceback1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_tracemalloc.py

示例4: test_snapshot

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def test_snapshot(self):
        obj, source = allocate_bytes(123)

        # take a snapshot
        snapshot = tracemalloc.take_snapshot()

        # write on disk
        snapshot.dump(support.TESTFN)
        self.addCleanup(support.unlink, support.TESTFN)

        # load from disk
        snapshot2 = tracemalloc.Snapshot.load(support.TESTFN)
        self.assertEqual(snapshot2.traces, snapshot.traces)

        # tracemalloc must be tracing memory allocations to take a snapshot
        tracemalloc.stop()
        with self.assertRaises(RuntimeError) as cm:
            tracemalloc.take_snapshot()
        self.assertEqual(str(cm.exception),
                         "the tracemalloc module must be tracing memory "
                         "allocations to take a snapshot") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_tracemalloc.py

示例5: profile_memory

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def profile_memory(func: Callable[[], Any]) -> MemoryFrame:
    """Profile memory and return a tree of statistics.

    Feed those to `render_memory_svg()` to write an SVG.
    """
    import tracemalloc

    tracemalloc.start(1024)
    try:
        func()
    finally:
        snap = tracemalloc.take_snapshot()
        tracemalloc.stop()
    stats = snap.statistics("traceback")
    root = MemoryFrame(blocks=0, size=0)
    for stat in stats:
        blocks = stat.count
        size = stat.size
        callee = root
        callee.blocks += blocks
        callee.size += size
        for frame in stat.traceback:
            lineid = (frame.filename, frame.lineno)
            callee = callee.callers.setdefault(
                lineid, MemoryFrame(blocks=0, size=0)
            )
            callee.blocks += blocks
            callee.size += size
    while len(root.callers) == 1:
        root = next(iter(root.callers.values()))
    return root 
开发者ID:edgedb,项目名称:edgedb,代码行数:33,代码来源:profiler.py

示例6: tearDown

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def tearDown(self) -> None:
        """
        After each test run, stop tracemalloc.
        :return:
        """
        tracemalloc.stop() 
开发者ID:bitkeks,项目名称:python-netflow-v9-softflowd,代码行数:8,代码来源:test_performance.py

示例7: tearDown

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def tearDown(self):
        tracemalloc.stop() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_tracemalloc.py

示例8: test_get_traces

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
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)
        size, traceback = trace
        self.assertEqual(size, obj_size)
        self.assertEqual(traceback, obj_traceback._frames)

        tracemalloc.stop()
        self.assertEqual(tracemalloc._get_traces(), []) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_tracemalloc.py

示例9: test_get_traced_memory

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
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:Microvellum,项目名称:Fluid-Designer,代码行数:37,代码来源:test_tracemalloc.py

示例10: stop_profiler

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def stop_profiler(self):
        self.agent.log('Deactivating memory allocation profiler.')

        with self.profile_lock:
            if self.overhead_monitor:
                self.overhead_monitor.cancel()
                self.overhead_monitor = None

            if tracemalloc.is_tracing():
                snapshot = tracemalloc.take_snapshot()
                self.agent.log('Allocation profiler memory overhead {0} bytes'.format(tracemalloc.get_tracemalloc_memory()))
                tracemalloc.stop()
                self.process_snapshot(snapshot, time.time() - self.start_ts) 
开发者ID:stackimpact,项目名称:stackimpact-python,代码行数:15,代码来源:allocation_profiler.py

示例11: memory_tracer

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def memory_tracer():
    tracemalloc.start()
    tracemalloc.clear_traces()

    filters = (
        tracemalloc.Filter(True, aiormq.__file__),
        tracemalloc.Filter(True, pamqp.__file__),
        tracemalloc.Filter(True, aio_pika.__file__),
    )

    snapshot_before = tracemalloc.take_snapshot().filter_traces(filters)

    try:
        yield

        with suppress(Exception):
            gc.collect()

        snapshot_after = tracemalloc.take_snapshot().filter_traces(filters)

        top_stats = snapshot_after.compare_to(
            snapshot_before, "lineno", cumulative=True,
        )

        assert not top_stats
    finally:
        tracemalloc.stop() 
开发者ID:mosquito,项目名称:aio-pika,代码行数:29,代码来源:conftest.py

示例12: test_get_traces

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
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:bkerler,项目名称:android_universal,代码行数:17,代码来源:test_tracemalloc.py

示例13: test_get_traces_intern_traceback

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import stop [as 别名]
def test_get_traces_intern_traceback(self):
        # dummy wrappers to get more useful and identical frames in the traceback
        def allocate_bytes2(size):
            return allocate_bytes(size)
        def allocate_bytes3(size):
            return allocate_bytes2(size)
        def allocate_bytes4(size):
            return allocate_bytes3(size)

        # Ensure that two identical tracebacks are not duplicated
        tracemalloc.stop()
        tracemalloc.start(4)
        obj_size = 123
        obj1, obj1_traceback = allocate_bytes4(obj_size)
        obj2, obj2_traceback = allocate_bytes4(obj_size)

        traces = tracemalloc._get_traces()

        obj1_traceback._frames = tuple(reversed(obj1_traceback._frames))
        obj2_traceback._frames = tuple(reversed(obj2_traceback._frames))

        trace1 = self.find_trace(traces, obj1_traceback)
        trace2 = self.find_trace(traces, obj2_traceback)
        domain1, size1, traceback1 = trace1
        domain2, size2, traceback2 = trace2
        self.assertIs(traceback2, traceback1) 
开发者ID:bkerler,项目名称:android_universal,代码行数:28,代码来源:test_tracemalloc.py


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