【问题标题】:Pprof and golang - how to interpret a results?Pprof 和 golang - 如何解释结果?
【发布时间】:2015-09-14 18:20:41
【问题描述】:

我正在尝试在我的程序中使用 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

这些列是什么: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

【问题讨论】:

  • 格式有点不同,但是数据和列的意思还是一样的。 'flat' 是函数中的时间,'cum' 是累积时间是一个函数,它下面的所有内容。
  • 你介意把你的标题改成What does flat, flat%, sum%, cum, cum% mean in Golang pprof results?
  • 我认为当人们搜索此类问题时可能更容易找到。

标签: linux go pprof


【解决方案1】:

平和暨

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

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

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

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

总和%

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

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

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

sum%的应用

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

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

参考

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

【讨论】:

    【解决方案2】:

    我知道我会为此大发雷霆,但请看一下 GopherCon 的演讲; one such example on interpretation is here,还有来自Uber about pprof的演讲。

    还有Profiling Go Programs的博文。

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-06
      • 2019-02-12
      • 2018-06-14
      • 2021-08-12
      • 2021-05-17
      相关资源
      最近更新 更多