python - python模块上的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

https://stackoverflow.com/questions/68303528/

相关文章:

ansible - 如何在ansible替换模块中转义+字符

serialization - 使用#[serde(untagged)] 和#[serde(with

reactjs - 如何在 primereact 中拥有主题切换器

python - 通用协议(protocol) : mypy error: Argument 1 h

kubernetes - 部署后如何在 kubernetes 中删除 Traefik 2.0 中间件

python - numpy 中如何实现多维数组切片/索引?

api - 通过 Bitbucket REST API 获取所有 Pull-Request 评论

django - 如何在基于 Django 类的 View 中更改模板

x86-64 - AVX512 与矢量比较不屏蔽

rust - 如何正确处理 Warp 路由的错误