PythonUtil.py 文件源码

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

项目:POTCO-PS 作者: ksmit799 项目源码 文件源码
def quickProfile(name="unnamed"):
    import pstats
    def profileDecorator(f):
        if(not config.GetBool("use-profiler",0)):
            return f
        def _profiled(*args, **kArgs):
            # must do this in here because we don't have base/simbase
            # at the time that PythonUtil is loaded
            if(not config.GetBool("profile-debug",0)):
                #dumb timings
                st=globalClock.getRealTime()
                f(*args,**kArgs)
                s=globalClock.getRealTime()-st
                print "Function %s.%s took %s seconds"%(f.__module__, f.__name__,s)
            else:
                import profile as prof, pstats
                #detailed profile, stored in base.stats under (
                if(not hasattr(base,"stats")):
                    base.stats={}
                if(not base.stats.get(name)):
                    base.stats[name]=[]

                prof.runctx('f(*args, **kArgs)', {'f':f,'args':args,'kArgs':kArgs},None,"t.prof")
                s=pstats.Stats("t.prof")
                #p=hotshot.Profile("t.prof")
                #p.runctx('f(*args, **kArgs)', {'f':f,'args':args,'kArgs':kArgs},None)
                #s = hotshot.stats.load("t.prof")
                s.strip_dirs()
                s.sort_stats("cumulative")
                base.stats[name].append(s)

        _profiled.__doc__ = f.__doc__
        return _profiled
    return profileDecorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号