python - python模块上的cprofile

标签 python profiling cprofile

我正在尝试使用 cprofile 分析一个合理大小的 python 项目。

我通常将我的 python 应用程序作为模块调用,例如:

python -m cabon.apps.detector -i input_image.png

现在如何从命令行使用 cprofile。我看到 cProfile 本身是作为模块调用的 -m ,如何将它与我的 python 应用程序结合起来,它也是作为模块调用的?

最佳答案

The files cProfile and profile 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/

相关文章:

python - 计算复杂 numpy ndarray 的 abs()**2 的最节省内存的方法

php - 如何使用 xdebug 只调试一个虚拟主机?

c++ - Windows 上的原生 C++ 有哪些好的分析器?

python-2.7 -> 90%的时间花费在 'acquire'对象的 'thread.lock'方法上

Python 从 cProfile 获得有意义的结果

python - 嵌套函数中的 cProfile

python - django 模板不呈现

python-mplayer 立即关闭

python - 无法在 basemap Python中找到shapefile

gcc - 配置文件生成与PG