Profile a python script using cProfile into an external file

。_饼干妹妹 提交于 2019-12-05 00:14:53

The output file generated by the cProfile -o module isn't plaintext; it's a serialized pstats.Stats object. Rather than using the -o option, I generally just redirect stdout into the file I want to create.

python -m cProfile -s time my_script.py > profile.text 2>&1

Otherwise, you just need to use the pstats module to read the file and inspect its contents (see the documentation linked above).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!