Posts Tagged ‘Profiling’

Getting the Perf out of perf script

Monday, May 6th, 2024

I’m a big fan of sampling profilers. I tend to prefer them over tracing profilers, due to the more limited amount of distortion they create in the measurements.

To start off with, Go has its own sampling profiling tool through runtime/pprof. These emit a pprof file which can be fed into pprof. pprof can generate various reports and visualizations. You can also use the same tool for heap and allocation profiling. This tool is molded in the shape of gperftools, another Google release, which works similarly but for native code. For gperftools, you link in the profiler with -lprofiler, and then set the CPUPROFILE environment variable and you’re on your way. You can use the very same pprof you’d use with Go, or you can use its predecessor, a Perl script also named pprof.

Both of these are great, but there’s a limitation: They rely mostly on counters, so while you can see where most of the time is spent, you can’t easily see when that time had been spent. This is where you’d want something more like a Flamegraph.

(more…)