pprof CPU go 应用程序的配置文件未显示任何示例

pprof CPU profile of a go application does not show any samples

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

该应用程序正在使用大约 4-10% CPU 并暂时保留它 运行 生成大约 6-11kb 的配置文件。这向我建议它应该能够采样一些 activity.

然而,当我查看结果时,我看到以下内容:

$ 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(如果重要的话)。

您误用了 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 秒,你也应该得到一些样本 (from here):

When CPU profiling is enabled, the Go program stops about 100 times per second and records a sample consisting of the program counters on the currently executing goroutine's stack

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