我正在用pprof分析Go应用程序。
该应用程序使用了大约4%-10%的CPU,并使其运行了一段时间,产生了大约6-11 it的配置文件。这对我来说意味着它应该能够对某些活动进行取样。
然而,当我查看结果时,我看到以下情况:
$ 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上,go版本1.6.1和pprof版本2.2.1的google-perftools (如果这很重要的话)。
发布于 2016-05-22 03:23:01
您错误地使用了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.7s,您也应该得到一些样本(从这里开始):
启用CPU分析时,Go程序每秒大约停止100次,并在当前正在执行的goroutine堆栈上记录一个由程序计数器组成的示例。
发布于 2021-07-14 09:23:25
有时,当程序完成执行太快时,会出现此问题。小心!
https://stackoverflow.com/questions/37368353
复制相似问题