Python 有高级分析模块吗?
我想分析我的 Python 代码。我很了解 cProfile
,并且使用它,但它的级别太低了。 (例如,甚至没有一种简单的方法来捕获您正在分析的函数的返回值。)
我想做的一件事:我想在我的程序中获取一个函数并将其设置为在运行程序时即时进行分析。
例如,假设我的程序中有一个函数 heavy_func
。我想启动程序并让 heavy_func
函数不分析本身。但在程序运行时的某个时候,我想更改 heavy_func
以在程序运行时对其自身进行分析。 (如果您想知道如何在程序运行时操作某些内容:我可以从调试探针或集成到我的 GUI 应用程序中的 shell 执行此操作。)
是否已经编写了一个模块可以执行类似的操作?我可以自己写,但我只是想先问一下,这样我就不会重新发明轮子了。
I want to profile my Python code. I am well-aware of cProfile
, and I use it, but it's too low-level. (For example, there isn't even a straightforward way to catch the return value from the function you're profiling.)
One of the things I would like to do: I want to take a function in my program and set it to be profiled on the fly while running the program.
For example, let's say I have a function heavy_func
in my program. I want to start the program and have the heavy_func
function not profile itself. But sometime during the runtime of my program, I want to change heavy_func
to profile itself while it's running. (If you're wondering how I can manipulate stuff while the program is running: I can do it either from the debug probe or from the shell that's integrated into my GUI app.)
Is there a module already written which does stuff like this? I can write it myself but I just wanted to ask before so I won't be reinventing the wheel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能有点令人费解,但是 这种技术应该可以帮助您找到“瓶颈”,这就是您想要做的。
您非常确定自己想要关注哪些日常活动。
如果这是你需要关注的日常习惯,那么它会证明你是对的。
如果真正的问题在其他地方,它会告诉您它们在哪里。
如果您想要一份乏味的原因列表,请查看此处。
It may be a little mind-bending, but this technique should help you find the "bottlenecks", it that's what you want to do.
You're pretty sure of what routine you want to focus on.
If that's the routine you need to focus on, it will prove you right.
If the real problem(s) are somewhere else, it will show you where they are.
If you want a tedious list of reasons why, look here.
我为它编写了自己的模块。我称之为
cute_profile
。 这是代码。 以下是测试。这是解释如何操作的博客文章来使用它。
它是GarlicSim的一部分,所以如果你想使用它,你可以安装
garlicsim
并执行from Garlicsim.general_misc import Cute_profile.
如果您想在 Python 3 代码上使用它,只需安装 Python 3 fork of
garlicsim
。以下是代码的过时摘录:
I wrote my own module for it. I called it
cute_profile
. Here is the code. Here are the tests.Here is the blog post explaining how to use it.
It's part of GarlicSim, so if you want to use it you can install
garlicsim
and dofrom garlicsim.general_misc import cute_profile
.If you want to use it on Python 3 code, just install the Python 3 fork of
garlicsim
.Here's an outdated excerpt from the code: