python profiler_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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值