4

我正在使用 pprof 分析 Go 应用程序。

该应用程序使用大约 4-10% 的 CPU 并让它运行一小会儿会产生大约 6-11kb 的配置文件。这向我表明它应该能够对一些活动进行采样。

但是,当我查看结果时,我看到以下内容:

$ go tool pprof --text bigproc
1.77s of 1.77s total (  100%)
      flat  flat%   sum%        cum   cum%
     1.77s   100%   100%      1.77s   100%
$

有趣的信息似乎丢失了。有什么问题?

这是在 linux 上,带有 google-perftools 的 go 版本 1.6.1 和 pprof 版本 2.2.1(如果重要的话)。

4

2 回答 2

3

您误用了go tool pprof,因为您应指定与生成的配置文件关联的可执行文件。

比较这个

$ go tool pprof --text cpuprofile.prof
680ms of 680ms total (  100%)
      flat  flat%   sum%        cum   cum%
     680ms   100%   100%      680ms   100% 

有了这个(注意main,这是产生的可执行文件cpuprofile.prof

$ go tool pprof --text main cpuprofile.prof
680ms of 680ms total (  100%)
      flat  flat%   sum%        cum   cum%
     350ms 51.47% 51.47%      610ms 89.71%  main.renderMandelbrotUnified
     130ms 19.12% 70.59%      130ms 19.12%  math.Log
      40ms  5.88% 76.47%       60ms  8.82%  image.(*RGBA).Set
[cut]

这不是错误采样的问题:考虑到每秒执行大约 100 个样本,所以即使是 1.7 秒,你也应该得到一些样本(从这里):

启用 CPU 分析后,Go 程序每秒停止大约 100 次,并在当前执行的 goroutine 的堆栈上记录由程序计数器组成的样本

于 2016-05-22T03:23:01.487 回答
-1

有时当您的程序完成执行太快时会出现此问题。小心!

于 2021-07-14T09:23:25.333 回答