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


Python tracemalloc.start方法代码示例

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


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

示例1: profile_main

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def profile_main():
    """

    :return:
    """
    log.info("Profiling: ENABLED")
    # Enable memory usage profiling at the line level
    tracemalloc.start()
    # Enable CPU usage/function call timing/rate at the function level
    # Automatigically dumps profile to `filename` for further analysis
    cProfile.run("main()", filename=(CWD + "/chimay-red.cprof"))
    # Take snapshot of traced malloc profile
    snapshot = tracemalloc.take_snapshot()
    # Print snapshot statistics filtering for only `tracefiles`
    display_top(snapshot, limit=20, modpaths=TRACEFILES)

    return 0 
开发者ID:seekintoo,项目名称:Chimay-Red,代码行数:19,代码来源:chimay_red.py

示例2: test_trace

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

    tracemalloc.start(10)
    time1 = tracemalloc.take_snapshot()

    import pycorrector

    c = pycorrector.correct('少先队员因该为老人让坐')
    print(c)

    time2 = tracemalloc.take_snapshot()
    stats = time2.compare_to(time1, 'lineno')
    print('*' * 32)
    for stat in stats[:3]:
        print(stat)

    stats = time2.compare_to(time1, 'traceback')
    print('*' * 32)
    for stat in stats[:3]:
        print(stat.traceback.format()) 
开发者ID:shibing624,项目名称:pycorrector,代码行数:23,代码来源:memory_test.py

示例3: tracemalloc_state

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

示例4: test_set_traceback_limit

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

示例5: test_get_traces_intern_traceback

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

示例6: main

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def main():
    print("Warming up (to discount regex cache etc.)")
    run()

    tracemalloc.start(25)
    gc.collect()
    snapshot1 = tracemalloc.take_snapshot()
    run()
    gc.collect()
    snapshot2 = tracemalloc.take_snapshot()

    top_stats = snapshot2.compare_to(snapshot1, 'traceback')

    print("Objects not released")
    print("====================")
    for stat in top_stats:
        if "tracemalloc.py" in str(stat) or stat.size_diff == 0:
            continue
        print(stat)
        for line in stat.traceback.format():
            print("    ", line)

    print("\nquickjs should not show up above.") 
开发者ID:PetterS,项目名称:quickjs,代码行数:25,代码来源:check_memory.py

示例7: rev_comp_gene_calls_dict

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def rev_comp_gene_calls_dict(gene_calls_dict, contig_sequence):
    contig_length = len(contig_sequence)
    gene_caller_ids = list(gene_calls_dict.keys())

    gene_caller_id_conversion_dict = dict([(gene_caller_ids[-i - 1], i) for i in range(0, len(gene_caller_ids))])
    G = lambda g: gene_caller_id_conversion_dict[g]

    reverse_complemented_gene_calls = {}
    for gene_callers_id in gene_calls_dict:
        g = copy.deepcopy(gene_calls_dict[gene_callers_id])
        g['start'], g['stop'] = contig_length - g['stop'], contig_length - g['start']
        g['direction'] = 'f' if g['direction'] == 'r' else 'r'

        reverse_complemented_gene_calls[G(gene_callers_id)] = g

    return reverse_complemented_gene_calls, gene_caller_id_conversion_dict 
开发者ID:merenlab,项目名称:anvio,代码行数:18,代码来源:utils.py

示例8: get_split_start_stops_without_gene_calls

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def get_split_start_stops_without_gene_calls(contig_length, split_length):
    """Returns split start stop locations for a given contig length."""
    num_chunks = int(contig_length / split_length)

    if num_chunks < 2:
        return [(0, contig_length)]

    chunks = []
    for i in range(0, num_chunks):
        chunks.append((i * split_length, (i + 1) * split_length),)
    chunks.append(((i + 1) * split_length, contig_length),)

    if (chunks[-1][1] - chunks[-1][0]) < (split_length / 2):
        # last chunk is too small :/ merge it to the previous one.
        last_tuple = (chunks[-2][0], contig_length)
        chunks.pop()
        chunks.pop()
        chunks.append(last_tuple)

    return chunks 
开发者ID:merenlab,项目名称:anvio,代码行数:22,代码来源:utils.py

示例9: is_this_name_OK_for_database

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def is_this_name_OK_for_database(variable_name, content, stringent=True, additional_chars_allowed=''):
    if not content:
        raise ConfigError("But the %s is empty? Come on :(" % variable_name)

    if content[0] in constants.digits:
        raise ConfigError("Sorry, %s can't start with a digit. Long story. Please specify a name "
                           "that starts with an ASCII letter." % variable_name)

    if stringent:
        allowed_chars = constants.allowed_chars.replace('.', '').replace('-', '')
    else:
        allowed_chars = constants.allowed_chars.replace('.', '')

    if len(additional_chars_allowed):
        allowed_chars += additional_chars_allowed

    if len([c for c in content if c not in allowed_chars]):
        raise ConfigError("Well, the %s contains characters that anvi'o does not like :/ Please limit the characters "
                           "to ASCII letters, digits, and the underscore ('_') character." % variable_name) 
开发者ID:merenlab,项目名称:anvio,代码行数:21,代码来源:utils.py

示例10: test

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test(self):
        timings = []
        memory_usage = []
        tracemalloc.start()

        for i in range(self.repeat):
            before_memory = tracemalloc.take_snapshot()
            start_time = time.time()

            self.bench()

            end_time = time.time()
            after_memory = tracemalloc.take_snapshot()
            timings.append(end_time - start_time)
            memory_usage.append(sum([t.size for t in after_memory.compare_to(before_memory, 'filename')]))

        print("time min:", min(timings), "max:", max(timings), "avg:", sum(timings) / len(timings))  # NOQA
        print("memory min:", min(memory_usage), "max:", max(memory_usage), "avg:", sum(memory_usage) / len(memory_usage))  # NOQA 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:benchmark.py

示例11: test_basic

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_basic(zipkin_url, client, loop):
    endpoint = az.create_endpoint('simple_service', ipv4='127.0.0.1', port=80)
    interval = 50
    tracer = await az.create(zipkin_url, endpoint, sample_rate=1.0,
                             send_interval=interval, loop=loop)

    with tracer.new_trace(sampled=True) as span:
        span.name('root_span')
        span.tag('span_type', 'root')
        span.kind(az.CLIENT)
        span.annotate('SELECT * FROM')
        await asyncio.sleep(0.1)
        span.annotate('start end sql')

    # close forced sending data to server regardless of send interval
    await tracer.close()

    trace_id = span.context.trace_id
    url = URL(zipkin_url).with_path('/zipkin/api/v2/traces')
    data = await _retry_zipkin_client(url, client)
    assert any(s['traceId'] == trace_id for trace in data for s in trace), data 
开发者ID:aio-libs,项目名称:aiozipkin,代码行数:23,代码来源:test_zipkin.py

示例12: test_leak_in_transport

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_leak_in_transport(zipkin_url, client, loop):

    tracemalloc.start()

    endpoint = az.create_endpoint('simple_service')
    tracer = await az.create(zipkin_url, endpoint, sample_rate=1,
                             send_interval=0.0001, loop=loop)

    await asyncio.sleep(5)
    gc.collect()
    snapshot1 = tracemalloc.take_snapshot()

    await asyncio.sleep(10)
    gc.collect()
    snapshot2 = tracemalloc.take_snapshot()

    top_stats = snapshot2.compare_to(snapshot1, 'lineno')
    count = sum(s.count for s in top_stats)
    await tracer.close()
    assert count < 400  # in case of leak this number is around 901452 
开发者ID:aio-libs,项目名称:aiozipkin,代码行数:22,代码来源:test_zipkin.py

示例13: main

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def main():
    # change path to launcher
    global __file__
    __file__ = os.path.abspath(__file__)
    if os.path.islink(__file__):
        __file__ = getattr(os, 'readlink', lambda x: x)(__file__)
    os.chdir(os.path.dirname(os.path.abspath(__file__)))

    # xlog.info("start XX-Net %s", current_version)

    allow_remote = 0

    restart_from_except = False

    module_init.start_all_auto()

    while True:
        time.sleep(1) 
开发者ID:miketwes,项目名称:XX-Net-mini,代码行数:20,代码来源:start.py

示例14: memory_monitor

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def memory_monitor(command_queue: Queue, poll_interval=1):
    tracemalloc.start()
    old_max = 0
    snapshot = None
    while True:
        try:
            command_queue.get(timeout=poll_interval)
            if snapshot is not None:
                print(datetime.now())
                display_top(snapshot)

            return
        except Empty:
            max_rss = getrusage(RUSAGE_SELF).ru_maxrss
            if max_rss > old_max:
                old_max = max_rss
            snapshot = tracemalloc.take_snapshot()
            display_top(snapshot, limit=1)
            print(datetime.now(), 'max RSS', old_max) 
开发者ID:automl,项目名称:Auto-PyTorch,代码行数:21,代码来源:mem_test_thread.py

示例15: main

# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def main():
    await bot.start()
    await bot.run_until_disconnected() 
开发者ID:LonamiWebs,项目名称:Telethon,代码行数:5,代码来源:payment.py


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