简体   繁体   English

Pprof和golang - 如何解释结果?

[英]Pprof and golang - how to interpret a results?

I am trying to use pprof on my program, however, I have slightly different results from articles I read (links below). 我试图在我的程序中使用pprof,但是,我的文章与我读过的文章略有不同(链接如下)。 In my results, I am getting such table: 在我的结果中,我得到了这样的表:

(pprof) top10
1.65s of 1.72s total (95.93%)
Showing top 10 nodes out of 114 (cum >= 0.01s)
      flat  flat%   sum%        cum   cum%
     1.19s 69.19% 69.19%      1.20s 69.77%  syscall.Syscall
     0.16s  9.30% 78.49%      0.16s  9.30%  runtime._ExternalCode

what are this columns: flat flat% sum% cum cum% ? 这列是什么: flat flat% sum% cum cum%

Articles I was reading: https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs http://blog.golang.org/profiling-go-programs 我正在阅读的文章: https//software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs http://blog.golang.org/profiling-走的程序

flat and cum 平和暨

Assuming there is a function foo, which is composed of 3 functions and a direct operation. 假设有一个函数foo,它由3个函数和一个直接操作组成。

func foo(){
    a()                                 step1
    b()                                 step2
    do something directly.              step3
    c()                                 step4
}

Imagine when you call function foo , it takes 6 seconds, and the time distribution are following. 想象一下,当您调用函数foo ,它需要6秒,并且时间分布如下。

func foo(){
    a()                                 // step1 takes 1s
    b()                                 // step2 takes 1s
    do something directly.              // step3 takes 3s
    c()                                 // step4 takes 1s
}
  • flat would be the time spent on step3. flat将花费在第三步的时间。
  • cum would be the total execution time of foo, which contains sub-function call and direct operations. cum将是foo的总执行时间,其中包含子函数调用和直接操作。 (cum = step1+ step2+ step3+ step4) (cum = step1 + step2 + step3 + step4)

sum% 和%

when you run top in pprof console, each line of output stands for the time spent on specific function. 当您在pprof控制台中运行top时,每行输出代表在特定函数上花费的时间。 Sum% means how much time/memory has been spent by previous lines. Sum%表示前一行花费了多少时间/内存。

To explain this metric, I pick another example which contains more lines. 为了解释这个指标,我选择了另一个包含更多行的示例。 the value of sum% for forth line is 45.17%. 第四行的sum%的值为45.17%。 it's the calculated in this way: 这是以这种方式计算的:

line1 19.33%
line2 13.27%
line3 6.60%
line4 5.97%
-----------
sum% 45.17%

在此输入图像描述

Application of sum% 应用总和%

sum% could help you to identify the big rocks quickly. sum%可以帮助您快速识别大石头。 The following is another example of memory allocation report. 以下是内存分配报告的另一个示例。

You can see that the first four functions consume 91.06% memory. 您可以看到前四个函数占用了91.06%的内存。 If I want to do some performance tuning, I should focus on first four functions. 如果我想做一些性能调整,我应该专注于前四个功能。 All the functions below fourth could be ignored. 第四个以下的所有功能都可以忽略。

在此输入图像描述

Reference 参考

Reddit: What is the meaning of "flat" and "cum" in golang pprof output Reddit:golang pprof输出中“flat”和“cum”的含义是什么?

I know I'm going to get flack for this, but take a look at the GopherCon talks; 我知道我会为此而烦恼,但看看GopherCon会谈; one such example on interpretation is here , there is also a talk from Uber about pprof as well. 这里一个关于解释的例子 ,也有来自优步的关于pprof的谈话。

There is also Profiling Go Programs blog post. 还有Profiling Go Programs博客文章。

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

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