profile cProfile 效率分析
2018-08-12 11:05
337 查看
版权声明:本文为博主原创,转载请注明出处。 https://blog.csdn.net/Chihwei_Hsu/article/details/81604553
功效:对脚本进行简单的效率分析并生成分析图表
test.py:
import os import sys def process(filename): print filename for (dirpath, dirnames, filenames) in os.walk(sys.argv[1]): for filename in filenames: process(filename)
cProfile用法:
# 生成.pstats分析文档 python -m cProfile -o profile.pstats test.py /usr # 排序 python -m cProfile -s tottime myscript.py # 查看pstats文档 python -m pstats profile.pstats # ?: 查看可用指令;sort cumtime:排序;stats:查看pstats文档 -s 选项: 'calls' (call count) 'cumulative' (cumulative time) 'cumtime' (cumulative time) 'file' (file name) 'filename' (file name) 'module' (file name) 'ncalls' (call count) 'pcalls' (primitive call count) 'line' (line number) 'name' (function name) 'nfl' (name/file/line) 'stdname' (standard name) 'time' (internal time) 'tottime' (internal time)
gprof2dot用法:
# 安装 gprof2dot pip install gprof2dot # 通过.pstats文档生成相应的dot文档 python -m gprof2dot -f pstats profile.pstats # 安装graphviz(centOS系统) sudo yum install graphviz # 输出png文档 python -m gprof2dot -f pstats profile.pstats | dot -T png -o profile.png
阅读更多作者:Chihwei_hsu
来源:http://chihweihsu.com
Github:https://github.com/HsuChihwei
相关文章推荐
- MySQL 使用profile分析慢sql,group left join效率高于子查询
- MySQL利用profile分析慢sql详解(group left join效率高于子查询)
- MySQL 使用profile分析慢sql,group left join效率高于子查询
- 深层面分析技术团队的情绪与效率
- 网站推广途径有效率分析
- MySQL单列索引和组合索引的选择效率与explain分析(没图)
- Python程序性能分析模块----------cProfile
- 10—(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!
- 算法设计与分析学习-算法效率分析
- 对于Oracle中分页排序查询语句执行效率的比较分析
- VB.NET位运算之交换两个数字的效率分析
- 【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!
- in和exists的区别与SQL执行效率分析
- 如何分析matlab程序的主要效率问题
- Mysql 优化——分析表读写和sql效率问题
- 数组的下标访问和指针访问方式效率分析比较
- java中使用SQL的效率分析例子
- JavaScript清空数组的三种方法及效率分析
- Oracle in和exists效率问题分析
- sql优化-分页查询效率慢的问题分析及处理