Hello Python profiler

发布时间:2019-06-14 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Hello Python profiler脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

思路

  • 什么是 PRofiler

  • profiler 的 Hello World

  • 给 Flask App 做 profiler

什么是 profiler

就是性能分析器啊。

profiler ['prəufailə]
  Word Explanation:
     * n. 分析器,分析工具;仿形铣床;[测] 断面仪

另外的一个单词是 profiling,就是性能分析的意思。用多种的技来实现分析代码的运行性能。这样的技术很早就有了,被用来测试新的硬件平台、编译器、代码效率……

Hello Python Profiler

$ brew install graphviz
$ pip install gprof2dot
$ cat hello_profiler2.py
def profiler(s):
    for x in range(10000):
        for c in ' profiler ':
            s += c
    return s


def hello():
    s = 'hello'
    s = profiler(s)
    print s

if __name__ == '__main__':
    hello()
$ python -m cProfile -o hello_profiler2.pstats hello_profiler2.py
$ gprof2dot -f pstats hello_profiler2.pstats | dot -tpng -o output.png

参考

WSGI Profiler

#!flask/bin/python
From werkzeug.contrib.profiler import ProfilerMiddleware
from app import app

app.config['PROFILE'] = True
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
app.run(debug = True)

脚本宝典总结

以上是脚本宝典为你收集整理的Hello Python profiler全部内容,希望文章能够帮你解决Hello Python profiler所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。