cat 14:27:47 UTC Flamegraphs are cool. Let me show you: require 'flamegraph' module Rack class Flamegraph def initialize ( app , & enabler ) @app = app @enabler = enabler || proc { false } end def call ( env ) req = Rack :: Request .new ( env ) if ! @enabler .call ( req ) return @app .call ( env ) end html = :: Flamegraph .generate do @app .call ( env ) end [ 200 , { 'Content-Type' => 'text/html' }, [ html ]] end end end Then inject it: config .middleware.use Rack :: Flamegraph do | req | req . GET [ '_flamegraph' ] == 'secret' end Then visit /?_flamegraph=secret in production:

cat 14:40:31 UTC What does it tell you: It shows you every backtrace that happened in your action in a 1ms internval. Time moves from left to right. The height represents the stack size. Notice the bars that are pink followed by green followed by pink? That's a database call. Notice the repeated pattern? That's a N+1 query issue.