简体   繁体   English

Python分析 - runsnakerun输出中的列是什么?

[英]Python profiling - What are the columns in runsnakerun output?

This may be really obvious but just wanted to make sure I understand what the columns are in runsnakerun. 这可能非常明显,但只是想确保我理解runsnakerun中的列是什么。

Name, Calls, RCalls, Local, /Call, Cum, /Call, File, Line, Directory 名称,呼叫,RCalls,本地,/呼叫,暨,/呼叫,文件,线路,目录

Here are some that I think I understand 以下是我认为我理解的一些内容

Name - name of function being called 名称 - 被调用函数的名称

  1. Calls - number of calls? 通话 - 通话次数?
  2. File - file where the function is stored 文件 - 存储函数的文件
  3. Line - Line in File where the function is defined Line - 在文件中定义函数的行
  4. Directory - directory of file with function definition 目录 - 具有功能定义的文件目录

The ones I don't feel comfortable venturing a guess are the rest: 剩下的就是那些我不觉得冒险的人:

  1. RCalls RCalls
  2. Local 本地
  3. /Call /呼叫
  4. Cum 附带
  5. /Call /呼叫

Thanks 谢谢

Here is my understanding: 这是我的理解:

  • RCalls number of recursive calls RCalls递归调用的次数
  • Local Total time spent on local execution (without calling another method) Local在本地执行上花费的总时间(不调用另一种方法)
  • /Call Local time per call /Call每次通话的当地时间
  • Cum Total cumulative time Cum累计时间
  • /Call Cumulative time per call /Call每次通话的累计时间

The best way to illustrate is with an example -- suppose you have the following program (stored in profileme.py, but broken into pieces for clarity): 最好的说明方式是一个例子 - 假设您有以下程序(存储在profileme.py中,但为了清楚起见分成几部分):

def topfunction():
    tinyfunction()
    for i in range(100000):
        manytinyfunction()

Calls is simple -- how many times this function was called directly. 调用很简单 - 直接调用此函数的次数。 Of course as you select the items on the left side, those numbers will change, reflecting the number of times the function was called by the selected function. 当然,当您选择左侧的项目时,这些数字将会改变,反映所选功能调用该功能的次数。 manytinyfunction will get called 100,000 times, so calls will be 100,000. manytinyfunction将被调用100,000次,因此呼叫将为100,000次。 tinyfunction will get called once, so its calls will be 1. tinyfunction将被调用一次,因此它的调用将为1。

    for i in range(10):
        recursive(100)

rcalls is similar, but it also includes calls that happened while a call was being executed. rcalls类似,但它还包括在执行调用时发生的调用。 Notice for recursive that calls is only 10, but rcalls is 1010 (definition below, but it calls itself n times if its argument is n. 注意recursive调用只有10,但rcalls是1010(定义如下,但是如果它的参数是n,它会调用n次。

    alllocal()
    allcumulative()

Similarly, local includes all the time spent in the function itself, not counting calls out to other functions. 类似地, local包括在函数本身中花费的所有时间,而不包括对其他函数的调用。 Here alllocal has a large value here, but allcumulative has nothing here, since it fobs its work onto subfunction . 这里alllocal有一个很大的价值,但是allcumulative在这里没有任何东西,因为它将它的工作转移到subfunction

def tinyfunction():
    pass

def manytinyfunction():
    pass

The /Call next to the local simply breaks the local value above down per call, so manytinyfunction has a little time overall, but a very very tiny number in the local /call, since each call is really cheap. 本地/旁边的呼叫只是打破了每次呼叫上面的本地值,所以manytinyfunction总体上有一点时间,但是本地/呼叫中的数字非常小,因为每次呼叫都非常便宜。

def alllocal():
    for i in range(1000):
        for j in range(1000):
            for k in range(1000):
                pass

For alllocal the /call will be huge both for local and for cumulative, since this function is so expensive, and all the expense is local. 对于alllocal ,/ call对于本地和累积来说都是巨大的,因为这个功能非常昂贵,并且所有费用都是本地的。

def allcumulative():
    for i in range(1000):
        subfunction()

def subfunction():
    for j in range(1000):
        for k in range(1000):
            pass

The /Call next to cumulative is the same as the /call for local, except that, like cumulative itself, it has the complete cost of all calls out from the function itself included. 累计旁边/ Call与本地的/ call相同,除了像累积本身一样,它包含从函数本身包含的所有调用的全部成本。 So the local /call number was tiny for allcumulative , but large for alllocal . 所以本地/电话号码对于所有allcumulative来说allcumulative小,但是对于alllocal来说alllocal Not so for the cumulative /call, which will be the same in both cases. 累积/调用不是这样,在两种情况下都是相同的。

def recursive(n):
    if n > 0:
        return recursive(n-1)
    else:
        return 0

The definition for recursive is provided for completeness recursive的定义是为了完整性而提供的

if __name__=="__main__":
    topfunction()

After profiling it and running runsnake: 在分析它并运行runsnake之后:

python -m cProfile -o profileme.out profileme.py 
runsnake profileme.out

So, notice that alllocal has a large value for both local and cumulative, where as allcumulative is sharply different. 所以,请注意alllocal具有本地和累积,其中一个较大的值allcumulative是截然不同的。 Notice that recursive is the same in both columns -- calls to yourself are counted. 请注意,两列中的recursive都是相同的 - 计算对自己的调用。

The Callees button on the bottom lets you figure out what other functions the selected function is calling, while Callers lets you figure out who's calling the selected function. 底部的“Callees”按钮可让您确定所选功能正在调用的其他功能,而“ 呼叫者”可让您确定谁在调用所选功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM