Python 分析器没有提供足够的信息
我试图找出为什么某些功能需要很长时间才能完成。
我正在使用这样的探查器:
ipdb> import profile
ipdb> profile.runctx('report.generateOutput()', globals(), locals())
1 function calls in 40.783 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
0 0.000 0.000 profile:0(profiler)
1 40.783 40.783 40.783 40.783 profile:0(report.generateOutput())
如您所见,这并没有多大用处。
我需要的是一些关于所有时间都花在哪里的详细信息,我在这里错过了什么?
I am trying to find out why some function is taking a long time to complete.
I am using the profiler like this:
ipdb> import profile
ipdb> profile.runctx('report.generateOutput()', globals(), locals())
1 function calls in 40.783 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
0 0.000 0.000 profile:0(profiler)
1 40.783 40.783 40.783 40.783 profile:0(report.generateOutput())
As you can see, that's not really of much use.
What I need is some detailed information about where all the time is being spent, what am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
配置文件report.generateOutput(),而不是函数调用。
要分析具有 foo() 主入口点的应用程序,您可以将以下内容添加到您的模块中:
Maybe 有关分析的 python 文档很有帮助。
Profile report.generateOutput(), instead of the function call.
To profile an application with a main entry point of foo(), you would add the following to your module:
Maybe the python docs on profiling are helpful.
你说了两件事:
“我需要的是一些关于在哪里所有时间都花在哪里的详细信息”
“我试图找出为什么某些功能需要很长时间才能完成”
您看,这些不是同一件事。我认为问为什么比问哪里更好,因为哪里实际上非常模糊。
例如,假设存在一个由大字符串数组的冒泡排序组成的“瓶颈”。时间都花在哪里了?是在冒泡排序的内循环中,还是在字符串比较中?探查器会说后者,但它存在的原因以及实际的问题是在调用堆栈的更高层。
以下是我的操作示例。
You say two different things:
"What I need is some detailed information about where all the time is being spent"
"I am trying to find out why some function is taking a long time to complete"
You see, these are not the same thing. I think it is better to ask why than where, because where is actually very fuzzy.
For example, suppose there is a "bottleneck" consisting of a bubble sort of a big array of strings. Where is the time spent? Is it in the inner loop of the bubble sort, or is it in the string compare? Profilers would say the latter, but the reason why it's there, and the actual problem, is higher up the call stack.
Here's an example of how I do it.