我正在尝试使用 cprofile 分析一个合理大小的 python 项目。
我通常将我的 python 应用程序作为模块调用,例如:
python -m cabon.apps.detector -i input_image.png
现在如何从命令行使用 cprofile。我看到 cProfile 本身是作为模块调用的 -m
,如何将它与我的 python 应用程序结合起来,它也是作为模块调用的?
最佳答案
The files
cProfile
andprofile
can also be invoked as a script to profile another script. For example:
python -m cProfile [-o output_file] [-s sort_order] (-m module | myscript.py)
如 documentation 中所述,我们可以通过使用额外的 -m
来指定正在对模块进行分析。首先是 cProfile
,然后是实际模块:
python -m cProfile -m cabon.apps.detector -i input_image.png
关于python - python模块上的cprofile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68303528/