正在运行的 Python 应用程序示例

发布于 2024-07-12 10:22:56 字数 207 浏览 13 评论 0原文

我习惯于对基于 C 的应用程序进行采样,每隔几毫秒就会看到当时正在调用什么函数堆栈。

这让我可以看到应用程序的大部分时间都花在哪里,以便我可以对其进行优化。

然而,当使用 python 时,sample 就没那么有用了,因为它采样的是 python 解释器的 C 函数,而不是 python 代码本身。

python 有没有好用的采样工具?

I'm used to sampling C-based apps, which every few milliseconds sees what function stack is being called at that moment.

This allows me to see where most of the time is spent in an app so I can optimize it.

When using python, however, sample isn't so helpful, since it's sampling the C functions of the python interpreter, not the python code itself.

Is there a useful sampling tool for python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宛菡 2024-07-19 10:22:56

Python 包含一组内置的分析工具。 特别是,您可以从命令行在任意 python 脚本上运行 cProfile:

$ python -m cProfile myscript.py

通过直接调用 API 可以获得更详细的用法。 请注意,cProfile 模块是在 Python 2.5 中添加的。 在早期版本中,您可以使用纯Python,但速度较慢的“profile”模块。

Python includes a built-in set of profiling tools. In particular, you can run cProfile on an arbitrary python script from the command-line:

$ python -m cProfile myscript.py

Much more elaborate usage is available by calling the API directly. Note that the cProfile module was added in Python 2.5. In earlier versions, you can use the pure-Python, but slower "profile" module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文