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

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 显示调用树中的每个调用?

默认pprof removes nodes with less than 0.5% of the CPU time and edges with less then 0.1% 的CPU 次。您可以通过提供 -nodefraction=0-edgefraction=0 标志要求 pprof 不这样做,这可能会解决您的问题。

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

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

您可以复制 StartCPUProfile 并更改 hz 变量以使其更频繁地捕获。