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


Python tracemalloc.is_tracing方法代码示例

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


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

示例1: tracemalloc_dump

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def tracemalloc_dump() -> None:
    if not tracemalloc.is_tracing():
        logger.warning("pid %s: tracemalloc off, nothing to dump",
                       os.getpid())
        return
    # Despite our name for it, `timezone_now` always deals in UTC.
    basename = "snap.{}.{}".format(os.getpid(),
                                   timezone_now().strftime("%F-%T"))
    path = os.path.join(settings.TRACEMALLOC_DUMP_DIR, basename)
    os.makedirs(settings.TRACEMALLOC_DUMP_DIR, exist_ok=True)

    gc.collect()
    tracemalloc.take_snapshot().dump(path)

    with open(f'/proc/{os.getpid()}/stat', 'rb') as f:
        procstat = f.read().split()
    rss_pages = int(procstat[23])
    logger.info("tracemalloc dump: tracing %s MiB (%s MiB peak), using %s MiB; rss %s MiB; dumped %s",
                tracemalloc.get_traced_memory()[0] // 1048576,
                tracemalloc.get_traced_memory()[1] // 1048576,
                tracemalloc.get_tracemalloc_memory() // 1048576,
                rss_pages // 256,
                basename) 
开发者ID:zulip,项目名称:zulip,代码行数:25,代码来源:debug.py

示例2: tracemalloc_state

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [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

示例3: test_create_snapshot

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def test_create_snapshot(self):
        raw_traces = [(5, (('a.py', 2),))]

        with contextlib.ExitStack() as stack:
            stack.enter_context(patch.object(tracemalloc, 'is_tracing',
                                             return_value=True))
            stack.enter_context(patch.object(tracemalloc, 'get_traceback_limit',
                                             return_value=5))
            stack.enter_context(patch.object(tracemalloc, '_get_traces',
                                             return_value=raw_traces))

            snapshot = tracemalloc.take_snapshot()
            self.assertEqual(snapshot.traceback_limit, 5)
            self.assertEqual(len(snapshot.traces), 1)
            trace = snapshot.traces[0]
            self.assertEqual(trace.size, 5)
            self.assertEqual(len(trace.traceback), 1)
            self.assertEqual(trace.traceback[0].filename, 'a.py')
            self.assertEqual(trace.traceback[0].lineno, 2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_tracemalloc.py

示例4: run_in_subinterp

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def run_in_subinterp(code):
    """
    Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
    module is enabled.
    """
    # Issue #10915, #15751: PyGILState_*() functions don't work with
    # sub-interpreters, the tracemalloc module uses these functions internally
    try:
        import tracemalloc
    except ImportError:
        pass
    else:
        if tracemalloc.is_tracing():
            raise unittest.SkipTest("run_in_subinterp() cannot be used "
                                     "if tracemalloc module is tracing "
                                     "memory allocations")
    import _testcapi
    return _testcapi.run_in_subinterp(code) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:__init__.py

示例5: test_create_snapshot

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def test_create_snapshot(self):
        raw_traces = [(0, 5, (('a.py', 2),))]

        with contextlib.ExitStack() as stack:
            stack.enter_context(patch.object(tracemalloc, 'is_tracing',
                                             return_value=True))
            stack.enter_context(patch.object(tracemalloc, 'get_traceback_limit',
                                             return_value=5))
            stack.enter_context(patch.object(tracemalloc, '_get_traces',
                                             return_value=raw_traces))

            snapshot = tracemalloc.take_snapshot()
            self.assertEqual(snapshot.traceback_limit, 5)
            self.assertEqual(len(snapshot.traces), 1)
            trace = snapshot.traces[0]
            self.assertEqual(trace.size, 5)
            self.assertEqual(len(trace.traceback), 1)
            self.assertEqual(trace.traceback[0].filename, 'a.py')
            self.assertEqual(trace.traceback[0].lineno, 2) 
开发者ID:bkerler,项目名称:android_universal,代码行数:21,代码来源:test_tracemalloc.py

示例6: _memory_of_version

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def _memory_of_version(self, version, store_packets=500) -> tracemalloc.Snapshot:
        """
        Create memory snapshot of collector run with packets of version :version:
        :param version:
        :return:
        """
        if not tracemalloc.is_tracing():
            raise RuntimeError
        pkts, t1, t2 = send_recv_packets(generate_packets(NUM_PACKETS_PERFORMANCE, version),
                                         store_packets=store_packets)
        self.assertEqual(len(pkts), NUM_PACKETS_PERFORMANCE)
        snapshot = tracemalloc.take_snapshot()
        del pkts
        return snapshot 
开发者ID:bitkeks,项目名称:python-netflow-v9-softflowd,代码行数:16,代码来源:test_performance.py

示例7: setUp

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def setUp(self):
        if tracemalloc.is_tracing():
            self.skipTest("tracemalloc must be stopped before the test")

        tracemalloc.start(1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_tracemalloc.py

示例8: test_is_tracing

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def test_is_tracing(self):
        tracemalloc.stop()
        self.assertFalse(tracemalloc.is_tracing())

        tracemalloc.start()
        self.assertTrue(tracemalloc.is_tracing()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_tracemalloc.py

示例9: fork_child

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def fork_child(self):
        if not tracemalloc.is_tracing():
            return 2

        obj_size = 12345
        obj, obj_traceback = allocate_bytes(obj_size)
        traceback = tracemalloc.get_object_traceback(obj)
        if traceback is None:
            return 3

        # everything is fine
        return 0 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_tracemalloc.py

示例10: test_env_var_disabled_by_default

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def test_env_var_disabled_by_default(self):
        # not tracing by default
        code = 'import tracemalloc; print(tracemalloc.is_tracing())'
        ok, stdout, stderr = assert_python_ok('-c', code)
        stdout = stdout.rstrip()
        self.assertEqual(stdout, b'False') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_tracemalloc.py

示例11: test_env_var_enabled_at_startup

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def test_env_var_enabled_at_startup(self):
        # tracing at startup
        code = 'import tracemalloc; print(tracemalloc.is_tracing())'
        ok, stdout, stderr = assert_python_ok('-c', code, PYTHONTRACEMALLOC='1')
        stdout = stdout.rstrip()
        self.assertEqual(stdout, b'True') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_tracemalloc.py

示例12: setup

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [as 别名]
def setup():
    global _INIT_MEMORY_SNAPSHOT
    if tracemalloc.is_tracing():
        _INIT_MEMORY_SNAPSHOT = tracemalloc.take_snapshot()
    server = BackdoorServer()
    server.start()
    return server 
开发者ID:anyant,项目名称:rssant,代码行数:9,代码来源:tools.py

示例13: start_profiler

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

        def start():
            tracemalloc.start(self.MAX_TRACEBACK_SIZE)
        self.agent.run_in_main_thread(start)

        self.start_ts = time.time()

        def monitor_overhead():
            if tracemalloc.is_tracing() and tracemalloc.get_tracemalloc_memory() > self.MAX_MEMORY_OVERHEAD:
                self.agent.log('Allocation profiler memory overhead limit exceeded: {0} bytes'.format(tracemalloc.get_tracemalloc_memory()))
                self.stop_profiler()

        self.overhead_monitor = self.agent.schedule(0.5, 0.5, monitor_overhead) 
开发者ID:stackimpact,项目名称:stackimpact-python,代码行数:17,代码来源:allocation_profiler.py

示例14: stop_profiler

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import is_tracing [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


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