Bha*_*yay 4 python profiling kcachegrind cprofile
我想分析python代码的性能,为此我使用了cProfile模块并生成了python文档中提到的.cprof文件。我正在使用pyprof2calltree python模块将.cprof文件打开到KCacheGrind中。
。我已经放入了分析结果的屏幕快照,它表明名为循环5的函数占用了100.04%的CPU时间。我不知道这代表什么。它也没有显示此功能的任何源代码。
它表明名为循环5的函数占用了100.04%的CPU时间。
不,它表明某些“周期5”以及从中调用的所有函数以及从中调用的所有函数都使用100%的“包含”时间。
<cycle>并不是真正的函数,而是kcachegrind 尝试从配置文件格式中尝试获取递归信息的方式(“循环内调用的包容性成本没有意义”)。这种格式(为callgrind定义)没有函数调用序列的确切信息(f1调用f2调用f3 ...),仅存储成对的caller-callee。当存在递归时,此格式仅适用于“自我”时间,而不适用于“包含”时间(包括所有被叫者时间)。
KCachegrind允许(并建议)使用“ 查看”菜单关闭“执行周期检测” :https : //kcachegrind.github.io/html/NewsOld.html
循环检测可通过工具栏按钮进行切换。对于GUI应用程序,有时关闭循环检测很有用,即使递归调用存在一些可视化错误。
如果没有“循环检测”,<cycle>将不会生成任何综合功能,但是某些功能可能具有> 100%的“含”。时间。尝试使用“自我”的时间,或者用更好的格式分析工具(Linux的perf,operf,ocperf.py,谷歌的cpuprofile和其他用途剖析格式的全功能调用堆栈)。https://github.com/jrfonseca/gprof2dot列出了许多好的格式,并且还可以正确地可视化它们(如果有足够的信息)。尝试使用python配置文件格式:
python配置文件
Run Code Online (Sandbox Code Playgroud)python -m profile -o output.pstats path/to/your/script arg1 arg2 gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.pngpython cProfile(以前称为lsprof)
Run Code Online (Sandbox Code Playgroud)python -m cProfile -o output.pstats path/to/your/script arg1 arg2 gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.pngpython hotshot profiler
热点分析器不包含主要功能。请改用hotshotmain.py脚本。
Run Code Online (Sandbox Code Playgroud)hotshotmain.py -o output.pstats path/to/your/script arg1 arg2 gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.png