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


Python Stats.stream方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import stream [as 别名]
    def __init__(self):
        settings_manager = SettingsManager() # Set up the settings_manager

        max_workers = settings_manager.getint('application', 'max-workers') # Get the max workers from settings manager
        profiler_on = settings_manager.getint('debugging', 'profiler-on') # Get whether there is a profiler
        absolute = settings_manager.getint('save', 'absolute') # Get whether it's an absolute path
        save_path = settings_manager.get('save', 'path') # Get whether it's an absolute path
        if not absolute:
            save_path = PROJECT_PATH + os.path.sep + save_path

        executor = ThreadPoolExecutor(max_workers=max_workers, profiler_on=profiler_on) # Set up the thread executor
        dis = Disassembler(settings_manager) # Build the disassembler
        server = PyDAServer('0.0.0.0',9000) # Set up the PyDA server
        save_manager = SaveManager(save_path)

        if profiler_on:
            profile = Profile()
            profile.enable()

        app.build_and_run(settings_manager, dis, executor, server, save_manager) # Run the interface

        if profiler_on:
            profile.disable()
            stats = executor.getProfileStats()
            if stats == None:
                stats = Stats(profile)
            else:
                stats.add(profile)
            with open('profile.stats', 'wb') as statsfile:
                stats.stream = statsfile
                stats.sort_stats('cumulative').print_stats()
开发者ID:cherry-wb,项目名称:PyDA,代码行数:33,代码来源:PyDA.py

示例2: profile

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import stream [as 别名]
def profile(locals_dict, globals_dict, *args, **kwargs):
    """ Generates a profile

    You can request a profile anytime by appending ?profile to the url.

    If config.profile_passhash is set, then you must use ?profile=password
    where sha1(password.encode() + b'foobarusrex') == profile_passhash

    If the password is required and not correct, raises a value error.

    """
    
    from tempfile import NamedTemporaryFile
    from hashlib import sha1
    from io import StringIO
    import cProfile
    from pstats import Stats
    import regex
    key = kwargs['profile'].encode() + b'spambarusrex'
    if sc.config.app['profile_passhash'] and (sha1(key).hexdigest() !=
        sc.config.app['profile_passhash']):
            raise ValueError('Invalid Password')
    with NamedTemporaryFile(prefix='profile') as tmpfile:
        cProfile.runctx("show.default(*args, **kwargs)",
            globals=globals_dict,
            locals=locals_dict,
            filename=tmpfile.name)
        stats = Stats(tmpfile.name)
    stats.sort_stats('tottime')
    stats.stream = StringIO()
    out = stats.stream.getvalue()
    splitpoint = out.find('ncalls')
    preamble = out[:splitpoint]
    table = out[splitpoint:]
    def splitdict(d):
        return ['{}: {}'.format(k, d[k]) for k in sorted(d)]
            
    m = regex.search(r'(?<= )(/home/.*)(/site-packages)(?=/)', table)
    site_packages = m[1] + m[2] if m else 'Unknown'
    table = table.replace(site_packages, '…')
            
    return '''<!DOCTYPE html><html><head><meta charset="utf8">
<title>{}</title>\
<body style="font-family: monospace;">
<h1> {} : Debug and Profile information</h1>
<h2> Request Info: </h2>

<pre>cherrypy.request.config = {{\n{}\n}}</pre>
<pre>cherrypy.request.headers = {{\n{}\n}}</pre>

<h2> Profile </h2>
<pre>{}\nsite-packages (…) = {}</pre>
<table><tbody>{}</tbody></table>
<script src="/js/vendor/jquery-1.10.2.min.js"></script>
<script src="/js/tablesort.js"></script>'''.format(
        'Profile',
        ''.join('/' + a for a in args),
        '\n'.join('    ' + e for e in splitdict(cherrypy.request.config)),
        '\n'.join('    ' + e for e in splitdict(cherrypy.request.headers)),
        preamble,
        site_packages,
        '\n'.join('<tr>' + ''.join(
            '<td>{}'.format(s) for s in line.split(maxsplit=5)) for line in table.split('\n'))
    )
开发者ID:,项目名称:,代码行数:66,代码来源:


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