How a Ruby profiler works: Stackprof under a microscope
summary
Stackprof profiles Ruby with just ~2,000 lines of C and Ruby by sampling (typical intervals 1–10 ms) instead of tracing every call, uses setitimer/sigaction (SIGALRM for wall, SIGPROF for CPU), captures stacks via RB_profile_frames, and defers unsafe work with the postpone_job API to store either raw or aggregated samples. It supports allocation, CPU and wall modes, emits stack collapse output for flamegraphs (speedcope compatible), is low overhead, and shows limits on many-threaded apps.
AI-written summary · about
chapters (8)
- 0:00StackProf and Ruby profiling
- 4:21Sampling in profilers
- 8:11Four profiler components
- 12:24CPU vs wall time sampling
- 15:34Postpone jobs for safety
- 19:27Efficient sample storage
- 21:57Flame graphs from results
- 23:43StackProf's power
related talks
37mThe Future of Ruby Performance Tooling
29mext/profile, or How to Make Profilers Tell the Truth
24mDIY::Thread.profile -- Light-Weight Profiling in Pure Ruby
43mReal World Ruby Performance at Scale
42mDebugging Ruby
28mTracing your way through Ruby
36mDebugging Ruby
29mChasing Real-Time Observability for CRuby
