【发布时间】:2017-07-25 16:36:44
【问题描述】:
我一直在尝试使用 pprof 分析我的 go 应用程序 (evm-specification-miner),但输出并不是很有用:
(pprof) top5
108.59mins of 109.29mins total (99.36%)
Dropped 607 nodes (cum <= 0.55mins)
Showing top 5 nodes out of 103 (cum >= 0.98mins)
flat flat% sum% cum cum%
107.83mins 98.66% 98.66% 108.64mins 99.40% [evm-specification-miner]
0.36mins 0.33% 98.99% 6mins 5.49% net.dialIP
0.30mins 0.28% 99.27% 4.18mins 3.83% net.listenIP
0.06mins 0.052% 99.32% 34.66mins 31.71%
github.com/urfave/cli.BoolFlag.ApplyWithError
0.04mins 0.036% 99.36% 0.98mins 0.9% net.probeIPv6Stack
这里是累积输出:
(pprof) top5 --cum
1.80hrs of 1.82hrs total (98.66%)
Dropped 607 nodes (cum <= 0.01hrs)
Showing top 5 nodes out of 103 (cum >= 1.53hrs)
flat flat% sum% cum cum%
1.80hrs 98.66% 98.66% 1.81hrs 99.40% [evm-specification-miner]
0 0% 98.66% 1.53hrs 83.93% net.IP.matchAddrFamily
0 0% 98.66% 1.53hrs 83.92% net.(*UDPConn).WriteToUDP
0 0% 98.66% 1.53hrs 83.90% net.sockaddrToUDP
0 0% 98.66% 1.53hrs 83.89% net.(*UDPConn).readMsg
如您所见,大部分时间都花在evm-specification-miner(这是我的 go 应用程序的名称)上,但我无法获得更多详细信息,甚至无法理解这些方括号的含义(有a question 有类似问题,但没有收到任何答复。
这里是 build 和 pprof 命令:
go install evm-specification-miner
go tool pprof evm-specification-miner cpuprof
我什至尝试过调试标志 -gcflags "-N -l"(如此处所述:https://golang.org/doc/gdb#Introduction),但无济于事。
分析是通过调用pprof.StartCPUProfile() 和pprof.StopCPUProfile() 完成的,正如这篇博文所述:https://blog.golang.org/profiling-go-programs:
func StartProfiling(cpuprof string) error {
f, err := os.Create(cpuprof)
if err != nil {
return err
}
return pprof.StartCPUProfile(f)
}
func StopProfiling() error {
pprof.StopCPUProfile()
return nil
}
StartProfiling 在main() 的开头调用,StopProfiling 在收到信号(中断或终止)时(或程序正常终止)。此配置文件是在中断后获得的。
【问题讨论】:
-
什么是“evm-specification-miner”?您的程序是否有可能在 Go 函数上花费的时间不多?累计输出是什么样子的?
-
evm-specification-miner是我的 Go 应用程序的名称。我已经编辑了我的问题以添加累积输出。我不确定你所说的 go 函数,但我的程序不太可能花费大部分时间等待 goroutine 或其他任何东西。 -
Go 函数是指用 Go 编写的代码。您的代码是否调用了任何 C 库或在汇编中实现了任何功能?它是否花费大部分时间等待网络?您希望在个人资料中看到什么?你能分享代码,或者至少是创建配置文件的部分吗?
-
我使用了一个本身调用 C 代码的库。如果代码大部分时间都花在了那里,我不会感到惊讶,这可能是我有这个 pprof 输出的原因。我不等待网络,这只是我忘记禁用的并行事物。我希望在配置文件中看到我的函数名称,例如:
1.0hrs 15.12% 27.45% ... main.main我已经使用用于生成配置文件的确切代码编辑了我的帖子。 -
如果大部分时间都在 C 代码中,那么在配置文件中就没有太多可看的了。我不确定为什么你有
[evm-specification-miner]而不是main.main或package._Cfunc...之类的东西,但输出看起来与我预期的一样。您使用的是最新的 Go 版本吗?