The stackprof Ruby gem was a trailblazer in low-overhead high-accuracy profiling for Ruby. It influenced the development of a bunch of modern Ruby VM observability APIs, and if you squint at the Datadog Ruby profiler, the vernier profiler, or the pf2 profiler you will see how they heavily borrowed from the ideas in stackprof.

And the reason why profiler developers keep looking at stackprof is because stackprof has an extremely elegant and straightforward design. Sitting at around a thousand lines of C code and another thousand lines of Ruby code, it makes for an extremely easy to get started in understanding how one builds a profiler.

At the Euruko 2025 conference in my home country of Portugal, I went through all 1000 lines of stackprof on stage (in less than 30 minutes!), explaining how a profiler works in practice.

While I hope most people won’t ever need to build their own profiler (insert joke about instead paying my employer for theirs), having an understanding of how profilers work and what they’re actually doing helps a lot in interpreting the data they gather and in making the best out of it.

So yeah, if I’ve managed to pique your interest, you’ll find the video of my talk and the slides below. And here’s one final link to the magic file — stackprof.c.

Slide deck: