core.py 文件源码

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

项目:mitogen 作者: dw 项目源码 文件源码
def enable_profiling():
    global _profile_hook
    import cProfile, pstats
    def _profile_hook(name, func, *args):
        profiler = cProfile.Profile()
        profiler.enable()
        try:
            return func(*args)
        finally:
            profiler.create_stats()
            fp = open('/tmp/mitogen.stats.%d.%s.log' % (os.getpid(), name), 'w')
            try:
                stats = pstats.Stats(profiler, stream=fp)
                stats.sort_stats('cumulative')
                stats.print_stats()
            finally:
                fp.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号