Search code examples
gopprof

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


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?


Solution

  • 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.