Use pprof to view go program stack traces

Chris Bailey
3 min readMar 19, 2022

Simple instructions for using pprof to view the stack traces of currently running goroutines.

So it appears your go program is hung, and you aren’t sure where/exactly what it’s doing that is hung. Maybe it’s hung, maybe it’s just running slowly? You can use pprof to help you figure this out. This is not a detailed debugging tutorial, just a very simple recipe to see the stack traces, as often this is all you may need to see in order to know where to dig in and start your debugging/analysis.

The below will allow you to simple go to a URL in your browser to view the stack traces of a go program (that you’ve instrumented) running on your system. What’s slick here is that this can also be used in production systems where you can at least access the web server that gets run by your program (ensure you don’t open that up to the public of course). And, because pprof is very low overhead, it’s a viable thing to do in production (at least for the duration of your debugging).

I found the following two articles useful in learning about this (they cover memory profiling, but more instructions on pprof, etc.):

Instrument your Go program

Thankfully this part is super simple. Add the imports, and start a web server…

--

--

Chris Bailey
Chris Bailey

Written by Chris Bailey

NatureQuant CTO/Co-founder. HotelTonight Co-founder. Cyclist, trail runner, skier, espresso & coffee lover, geek, traveler, foodie.

No responses yet