1

I am profiling my go application by exposing the /debug/pprof endpoints and obtaining profiles using those endpoints. However, when I run the /debug/pprof/profile for CPU snapshots I see that my total sample is a small portion of overall duration. Duration: 30s, Total samples = 340ms ( 1.13%)

How do I increase total samples?

Doing a search led me to SetCPUProfileRate, But I'm not sure how to use that with command line pprof tool. Another follow up : why is the sampling percentage so low?

  • 2
    Is your application actually doing anything? You can't sample what isn't happening. You usually profile an application at the max possible load, or under a benchmark. – JimB Mar 29 '22 at 20:49
  • 1
    not sure about your sampling stats but see that piece of documentation (which does not fit here) https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/runtime/pprof/pprof.go;l=762 Also you might find interesting to see the pprof profile http handler implementation https://go.dev/src/net/http/pprof/pprof.go#L120 –  Mar 29 '22 at 20:52
  • @JimB thank for checking. The application isn't in max load, it handles about ~20 rps. Do the sample duration increase with load? I understand more fuctions/stacktrace might appear in the sample, but I dont see how the duration would increase with load. – Fulliautomatix Mar 29 '22 at 21:01
  • The duration won't increase, but the number of captured samples will. A sampling profiler doesn't record everything that happens, sampling is a statistical operation, and you are only recording what is being executed at specific moments. The further from 100% utilization you are, the more often there's nothing to sample, and the longer you are going to have to collect samples to get a usable profile. – JimB Mar 29 '22 at 21:07
  • Seconding JimB's question, it's very common for people to write a program that does I/O, possibly in a loop or call tree, runs a CPU profiler on it (which is blind to I/O) and ask why the CPU time is so small, compared to overall time. Every I/O statement takes orders of magnitude more time than other statements. – Mike Dunlavey Mar 30 '22 at 17:47

0 Answers0