我正在尝试对一个相当复杂的Python程序进行一些高级概要分析。但是,使用cProfile时,几乎所有时间的度量单位为:
{method 'enable' of '_lsProf.Profiler' objects}
如果我分析整个程序python -m cProfile ...以及在Python代码(使用profile.enable()/.disable()/.create_stats...)中进行性能分析时,都会发生这种情况
有任何指向我可能做错事情的指示吗?
这是因为你的代码中的某个地方有类似的东西
import cProfile
pr = cProfile.Profile()
pr.enable()
Run Code Online (Sandbox Code Playgroud)
这是为了手动保存结果或打印结果,如果您像您所说的那样调用探查器,则python -m cProfile -o program.prof my_program.py不需要在程序内使用 cProfile。