关于python评测的问题

2024-04-26 12:28:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用python分析我的应用程序。我正在使用cProfile库。我需要分析应用程序的onFrame函数,但这是由外部应用程序调用的。我尝试了很多方法,但目前我的onFrame方法有以下几种:

runProfiler(self)

在我的课外,我有以下内容:

^{pr2}$

如果这看起来很奇怪,那是因为我已经尽了一切努力来消除错误“name doProfile not defined”。即使现在,runProfiler方法会被调用,并且“runProfiler called”也会被打印出来,但是我得到了刚才描述的错误。我做错什么了?在


Tags: 方法函数nameself应用程序错误notcprofile
2条回答

在这种情况下,您应该将必要的上下文传递给^{}

cProfile.runctx("doProfile()", globals(), locals(), "profile.log")

另一种方法是使用Profile对象的runcall方法。在

profiler = cProfile.Profile()
profiler.runcall(doProfile)
profiler.dump_stats("profile.log")

相关问题 更多 >