MiddlewareTimer :clock1:
A Rack middleware timer for Rails 4 and 5. Outputs results in miliseconds like so:
Started GET "/health" for 127.0.0.1 at 2016-12-15 23:39:19 +0000
ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by HealthController#show as HTML
Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
Sample message for Rack::Runtime ==> 22 ms
Sample message for ActionDispatch::Executor ==> 21 ms
Sample message for ActionDispatch::Static ==> 70 ms
Sample message for Rack::Sendfile ==> 70 ms
Installation
Put the following in your Gemfile:
gem 'rails-middleware_timer',
git: 'git://github.com/humzashah/rails-middleware_timer.git'
and bundle install
.
Then add the following to your environment.rb
file:
# config/environment.rb
# after: Rails.application.initialize!
Rails::MiddlewareTimer.time!
You can use a custom message format / method like so:
# config/initializers/rails-middleware_timer.rb
require 'rails/middleware_timer'
module Rails
module MiddlewareTimer
module Timer
module_function
def custom_output(class_name, time_taken)
puts "Sample message for #{class_name} ==> #{time_taken}"
end
end
end
end