4

This blog details how to run CPU profile using pprof. When profiling, a function like main may disappear from the sample because pprof truncates the sample to the bottom 100 stack frames. This is documented:

In fact the total for main.FindLoops and main.main should have been 100%, but each stack sample only includes the bottom 100 stack frames; during about a quarter of the samples, the recursive main.DFS function was more than 100 frames deeper than main.main so the complete trace was truncated.

The issue with is that I have a particular function I want to profile. The sampler reports it appearing something like 5% of the time but I know that's not accurate. Its frame on the stack must have been lost due to the truncation.

Is there a way I can profile a particular function and never truncate it from the stack frame sample? I want to know its true CPU profile out of 100%.

bli00
  • 2,215
  • 2
  • 19
  • 46
  • 2
    Run _only_ that function. Typically this is done in a benchmark for this function: `go test -run x -bench TheBenchmarkOfThatFunction --cpuprofile cpu.out`. Note that you cannot have pprof sample some function only. The only thing you can do is run just this function. – Volker Sep 05 '20 at 07:07
  • Other tools for profiling outside of pprof can be made to do this kind of instrumentation ... https://www.jaegertracing.io/ for example can be made to work on only particular functions – cjds Sep 05 '20 at 17:29

0 Answers0