正确的函数(my\u deamon\u fun())的配置文件不正确

2024-04-27 00:22:13 发布

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

我们已经使用python内存探查器和guppy插入了方法:my_daemon_fun())

要分析代码,我需要做的就是:

 STEP#1 -> decorate the my_daemon_fun() with "profile" decorator   
 STEP#2 -> start memory profiling 
 STEP#3 -> end memory profiling

像这样:

@profile                                               => STEP#1    
@inlineCallbacks
def my_daemon_fun(self):
    """
    Monitor my daemons
    """
    if self.running == True:
        try:
            hp = hpy()                                 => STEP#2
            before = hp.heap()
            yield self._lock.acquire()
            .....
            if ((x_running == False) or (b_running == False)):
                log.error('Daemons are not running, restarting...')
                yield self._restart_daemons()
        except:
            log.exception('Exception restarting daemons')
        finally:
            yield self._lock.release()
            reactor.callLater(MY_DAEMON_MONITOR_INTERVAL, self.my_daemon_fun)
            after = hp.heap()                         => STEP#3
            leftover = after - before

现在我们运行脚本来调用方法:my\u daemon\u fun()。 运行脚本后,虽然我们看到内存分析正在发生,但正在分析的函数不是我们用@profile修饰的函数:

Line #    Mem usage    Increment      Line Contents
1176     42.3 MiB      0.0 MiB       def unwindGenerator(*args, **kwargs):
1177     42.3 MiB      0.0 MiB           try:
1178     42.3 MiB      0.0 MiB               gen = f(*args, **kwargs)
1183     42.3 MiB      0.0 MiB           if not isinstance(gen, types.GeneratorType):
1187     42.3 MiB      0.0 MiB           return _inlineCallbacks(None, gen, Deferred())

我怀疑generatorinlineCallbackdecorator是否禁止对正确的代码进行分析

我正在调查为什么实际函数(即我的\u daemon \u fun())没有被分析? 同时,如果你能在这里帮助我们,那就太好了


Tags: 函数内存selfifmystepprofilerunning