Pprof和golang - 如何解释结果?

Sła*_*osz 5 linux go pprof

我试图在我的程序中使用pprof,但是,我的文章与我读过的文章略有不同(链接如下).在我的结果中,我得到了这样的表:

(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
Run Code Online (Sandbox Code Playgroud)

这列是什么:flat flat% sum% cum cum%

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

Rya*_* Lv 16

平 和 暨

假设有一个函数foo,它由3个函数和一个直接操作组成。

func foo(){
    a()                                 step1
    b()                                 step2
    do something directly.              step3
    c()                                 step4
}
Run Code Online (Sandbox Code Playgroud)

想象一下,当你调用 function 时foo,需要 6 秒,时间分布如下。

func foo(){
    a()                                 // step1 takes 1s
    b()                                 // step2 takes 1s
    do something directly.              // step3 takes 3s
    c()                                 // step4 takes 1s
}
Run Code Online (Sandbox Code Playgroud)
  • flat 将是在 step3 上花费的时间。
  • cum将是 foo 的总执行时间,其中包含子函数调用和直接操作。(cum = step1+ step2+ step3+ step4)

和%

当您top在 pprof 控制台中运行时,每一行输出代表在特定功能上花费的时间。Sum%表示前几行花费了多少时间/内存。

为了解释这个指标,我选择了另一个包含更多行的例子。的值sum%对于所述线是45.17%。它是这样计算的:

line1 19.33%
line2 13.27%
line3 6.60%
line4 5.97%
-----------
sum% 45.17%
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

sum%的应用

sum%可以帮助您快速识别大石头。下面是另一个内存分配报告的例子。

可以看到前四个函数消耗了 91.06% 的内存。如果我想做一些性能调优,我应该专注于前四个功能。可以忽略第四个以下的所有功能。

在此处输入图片说明

参考

Reddit:golang pprof 输出中的“flat”和“cum”是什么意思


小智 2

我知道我会因此受到批评,但看看 GopherCon 的演讲;这里有一个关于解释的例子,还有Uber 的关于 pprof 的演讲。

还有Profiling Go Programs博客文章。