Pprof和Golang – 如何解读结果?

huangapple go评论149阅读模式
英文:

Pprof and golang - how to interpret a results?

问题

我正在尝试在我的程序中使用pprof,但是我得到的结果与我阅读的文章(下面的链接)略有不同。在我的结果中,我得到了这样的表格:

(pprof) top10
1.65秒占总时间的1.72秒(95.93%)
显示114个节点中的前10个(累积时间 >= 0.01秒)
      flat  flat%   sum%        cum   cum%
     1.19秒 69.19% 69.19%      1.20秒 69.77%  syscall.Syscall
     0.16秒  9.30% 78.49%      0.16秒  9.30%  runtime._ExternalCode

这些列代表什么意思: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-go-programs

英文:

I am trying to use pprof on my program, however, I have slightly different results from articles I read (links below). 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%?

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

答案1

得分: 40

flat 和 cum

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

func foo(){
    a()                                 // 步骤1
    b()                                 // 步骤2
    直接执行某些操作                      // 步骤3
    c()                                 // 步骤4
}

假设当你调用函数 foo 时,它需要 6 秒钟,并且时间分布如下:

func foo(){
    a()                                 // 步骤1 耗时 1 秒
    b()                                 // 步骤2 耗时 1 秒
    直接执行某些操作                      // 步骤3 耗时 3 秒
    c()                                 // 步骤4 耗时 1 秒
}
  • flat 表示步骤3所花费的时间。
  • cum 表示 foo 的总执行时间,包括子函数调用和直接操作。(cum = 步骤1 + 步骤2 + 步骤3 + 步骤4)

sum%

当你在 pprof 控制台中运行 top 命令时,每行输出代表特定函数所花费的时间。Sum% 表示前面几行所花费的时间或内存的总和。

为了解释这个指标,我选择了另一个包含更多行的示例。第四行的 sum% 值为 45.17%。计算方法如下:

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

Pprof和Golang – 如何解读结果?

sum% 的应用

sum% 可以帮助你快速识别主要问题。下面是另一个内存分配报告的示例。

你可以看到前四个函数占用了 91.06% 的内存。如果我想进行性能调优,应该集中关注前四个函数,而可以忽略第四个函数以下的所有函数。

Pprof和Golang – 如何解读结果?

参考资料

Reddit: What is the meaning of "flat" and "cum" in golang pprof output

英文:

flat and cum

Assuming there is a function foo, which is composed of 3 functions and a direct operation.

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.

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.
  • cum would be the total execution time of foo, which contains sub-function call and direct operations. (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. Sum% means how much time/memory has been spent by previous lines.

To explain this metric, I pick another example which contains more lines. the value of sum% for forth line is 45.17%. it's the calculated in this way:

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

Pprof和Golang – 如何解读结果?

Application of sum%

sum% could help you to identify the big rocks quickly. The following is another example of memory allocation report.

You can see that the first four functions consume 91.06% memory. If I want to do some performance tuning, I should focus on first four functions. All the functions below fourth could be ignored.

Pprof和Golang – 如何解读结果?

Reference

Reddit: What is the meaning of "flat" and "cum" in golang pprof output

答案2

得分: 2

我知道我会因为这个而受到指责,但是看一下GopherCon的演讲吧;这里有一个关于解释的例子,还有一场来自Uber关于pprof的演讲

还有一篇关于Go程序性能分析的博文。

英文:

I know I'm going to get flack for this, but take a look at the GopherCon talks; one such example on interpretation is here, there is also a talk from Uber about pprof as well.

There is also Profiling Go Programs blog post.

huangapple
  • 本文由 发表于 2015年9月15日 02:20:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/32571396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定