Skip to content

Instantly share code, notes, and snippets.

@brainopia
Last active August 29, 2015 14:05
Show Gist options
  • Save brainopia/8f0a7d83509c80b53c45 to your computer and use it in GitHub Desktop.
Save brainopia/8f0a7d83509c80b53c45 to your computer and use it in GitHub Desktop.
track sql duration
def track_sql(&block)
timing = Hash.new 0
track = ->(_,start,finish,_,data) do
Thread.exclusive do
timing[data[:name]] += (finish - start)
end
end
ActiveSupport::Notifications.subscribed(track, 'sql.active_record', &block)
timing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment