Arn*_*len 6 performance profiling go pprof
我正在使用 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%
$
Run Code Online (Sandbox Code Playgroud)
有趣的信息似乎缺失了。可能出什么问题了?
这是在 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%
Run Code Online (Sandbox Code Playgroud)
与此(注意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]
Run Code Online (Sandbox Code Playgroud)
这不是错误采样的问题:考虑到每秒执行大约 100 个样本,所以即使是 1.7 秒,你也应该得到一些样本(从这里):
当启用 CPU 分析时,Go 程序每秒停止大约 100 次,并在当前执行的 Goroutine 堆栈上记录由程序计数器组成的样本