"Python探测器未提供足够的信息"

2024-05-12 22:21:41 发布

您现在位置: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())

正如你所见,这其实没什么用处。
我需要的是一些关于所有时间都花在哪里的详细信息,我在这里遗漏了什么?在


Tags: inimportreport功能functioncpuprofileseconds
2条回答

简介报告生成输出而不是调用()函数。在

要评测一个主入口点为foo()的应用程序,可以在模块中添加以下内容:

import cProfile
cProfile.run('foo()')

也许the python docs on profiling是有帮助的。在

你说了两件不同的事:

  • “我需要的是一些有关所有时间都花在哪里的详细信息”

  • “我试图找出为什么某个功能需要很长时间才能完成”

你看,这不是一回事。我认为问为什么where更好,因为where实际上非常模糊。在

例如,假设有一个“瓶颈”,由一个气泡状的字符串组成。时间花在哪里?它是在冒泡排序的内部循环中,还是在字符串比较中?探查器会说后者,但它存在的原因和实际问题是调用堆栈的更高层。在

Here's an example of how I do it.

相关问题 更多 >