我正在尝试使用cProfile来分析一些python代码。我认为我需要使用cProfile.runcall(),而不是cProfile.run(),因为我想运行的方法是表单self.funct(),而不是简单的funct()。
当我尝试使用cProfile.runcall,详细的这里时,我会得到以下错误:
AttributeError: 'module' object has no attribute 'runcall'
运行调用方法是否已从cProfile中删除?如果是,是否有其他方法使用表单cProfile.runcall(self.funct,*args)?
最低(非)工作示例:
import cProfile
def funct(a):
print a
cProfile.runcall(funct,"Hello")发布于 2018-02-07 18:37:29
在这种情况下,问题在于runcall()是Profile类实例的方法,而不是模块级函数(这是代码试图使用它的方式)。您需要首先构造一个实例,如文档中的代码片段所示。
这似乎有效(在Python2.7.14中):
import cProfile
def funct(a):
print a
pr = cProfile.Profile()
pr.enable()
pr.runcall(funct, "Hello")https://stackoverflow.com/questions/48670339
复制相似问题