Python脚本性能剖析$ python -m cProfile -o test1.out test1.p
$ python -c "import pstats; p=pstats.Stats("test1.out"); p.print_stats()"
$ python -c "import pstats; p=pstats.Stats("test1.out"); p.sort_stats("time").print_stats()"
除了命令行外,可直接在脚本内部使用
sort_stats支持以下参数:
ncalls 被调用次数
cumulative 函数运行的总时间
file 文件名
module 文件名
pcalls 简单调用统计(兼容旧版,未统计递归调用)
line 行号
name 函数名
nfl Name/file/line
stdname 标准函数名
time 函数内部运行时间(不计调用子函数的时间)
输出结果说明:
ncalls 函数的被调用次数
tottime 函数总计运行时间,除去函数中调用的函数运行时间
percall 函数运行一次的平均时间,等于tottime/ncalls
cumtime 函数总计运行时间,含调用的函数运行时间
percall 函数运行一次的平均时间,等于cumtime/ncalls
filename:lineno(function) 函数所在的文件名,函数的行号,函数名
Stats的若干参数
strip_dirs() 用以除去文件名前名的路径信息。
add(filename,[…]) 把profile的输出文件加入Stats实例中统计
dump_stats(filename) 把Stats的统计结果保存到文件
sort_stats(key,[…]) 最重要的一个函数,用以排序profile的输出
reverse_order() 把Stats实例里的数据反序重排
print_stats([restriction,…]) 把Stats报表输出到stdout
print_callers([restriction,…]) 输出调用了指定的函数的函数的相关信息
print_callees([restriction,…]) 输出指定的函数调用过的函数的相关信息Python向PHP发起GET与POST请求 http://www.linuxidc.com/Linux/2014-10/107903.htm《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htmPython 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htmPython 的详细介绍:请点这里
Python 的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-12/110451.htm