require "rails_instrument/version" module RailsInstrument class <", "#{sql_html_overlay}") end body = new_body end rescue => e headers["X-Rails-Instrument"] = "Error" end [status, headers, body] end private def html_reponse?(headers) headers['Content-Type'] =~ /html/ end def sql_html_overlay %Q{
#{sql_count} / #{"%.3f" % db_runtime}
} end def db_runtime RailsInstrument.data["process_action.action_controller"][:db_runtime] end def view_runtime RailsInstrument.data["process_action.action_controller"][:view_runtime] end def sql_count RailsInstrument.sql_count end end class Engine < ::Rails::Engine #:nodoc: initializer "my_engine.add_middleware" do |app| app.middleware.use RailsInstrument::Middleware ActiveSupport::Notifications.subscribe("process_action.action_controller") do |name, start, finish, id, payload| RailsInstrument.init $rails_instrument[name] = payload end ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload| RailsInstrument.init RailsInstrument.increment_sql_count unless (payload[:name] == "SCHEMA" || %w(BEGIN COMMIT ROLLBACK).include?(payload[:sql])) end end end end