如何让 pprof 在调用树中显示每个单独的函数?

huangapple go评论90阅读模式
英文:

How can I make pprof show every single function in a call tree?

问题

我正在尝试从https://github.com/greenplum-db/gpbackup获取gpbackup的完整调用树。我使用的是runtime/pprof而不是net/http/pprof,据我所知,收集统计信息不应该有任何时间限制。我在程序的最开始启动pprof服务器,并在os.Exit()命令之前停止它。为了收集统计信息,我运行gpbackup,它按预期工作并生成了cpu.prof输出。然后我使用pprof --nodecount=100000 gpb cpu.prof命令生成调用树,并使用png命令生成图像。问题是调用树缺少大量函数。例如,DoBackup()函数以日志函数开始,但在调用树中缺失,还有许多其他函数似乎也没有出现。我该如何让pprof显示每个单独的调用在调用树中?

英文:

I'm trying to get a full call tree of gpbackup from https://github.com/greenplum-db/gpbackup. I use runtime/pprof, not net/http/pprof, so as far as I know there shouldn't be any time limitations for collecting stats. I start pprof server in a very beginning of a program and stop it right before os.Exit() command. To collect stats I run gpbackup, it works as intended and I get cpu.prof output. Then I use pprof --nodecount=100000 gpb cpu.prof and generate a call tree with png command. The problem is that call tree lacks of major number of functions. For example, DoBackup() starts with logging functions, but they miss in a call tree, and there are lots of other functions that don't seem to appear either. How can I make pprof show every single call in a call tree?

答案1

得分: 0

默认情况下,pprof会删除CPU时间少于0.5%的节点和CPU时间少于0.1%的边。你可以通过提供-nodefraction=0-edgefraction=0标志来告诉pprof不要这样做,这可能会解决你的问题。

并不完全正确,runtime/pprof每秒采样100次。每次采样时,它会捕获完整的堆栈跟踪。因此,如果某些函数的执行速度快于0.01秒,并且不是较长运行函数的堆栈帧的一部分,你可能会错过这些函数。

你可以复制StartCPUProfile并更改hz变量,以便更频繁地进行采样。

英文:

By default pprof removes nodes with less than 0.5% of the CPU time and edges with less then 0.1% of the CPU time. You can ask pprof to not do this by supplying the -nodefraction=0 and -edgefraction=0 flags, this might solve your issue.

> so as far as I know there shouldn't be any time limitations for collecting stats

Not fully true, runtime/pprof samples 100 times per second. Every time it samples, it captures the full stack-trace. So you might miss functions if they execute faster than 100th of a second and are not part of the stack frame of longer running functions.

You could copy StartCPUProfile and change the hz variable so it captures more often.

huangapple
  • 本文由 发表于 2022年1月10日 02:48:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/70644428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定