debug.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:metan 作者: utatsuya 项目源码 文件源码
def run_profile(func, sort_order="cumtime", count=1, strip_dir=True, name_filter=""):
    """sort_order : keywords 'ncalls', 'tottime', 'cumtime', 'filename' """

    @wraps(func)
    def wrapper(*args, **kwargs):

        def cmd():
            for i in range(count):
                func(*args, **kwargs)

        prof = cProfile.Profile()
        _profile = prof.runctx("cmd()", globals(), locals())
        stream = StringIO.StringIO()
        stats = pstats.Stats(_profile, stream=stream)
        if strip_dir:
            stats.strip_dirs()
        stats.sort_stats(sort_order)
        stats.print_stats(name_filter)
        return stream.getvalue()
    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号