Skip to content

Instantly share code, notes, and snippets.

@hkdnet
Created August 15, 2018 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkdnet/3a6cea0543a7fc89f2f4129ffacd59b4 to your computer and use it in GitHub Desktop.
Save hkdnet/3a6cea0543a7fc89f2f4129ffacd59b4 to your computer and use it in GitHub Desktop.
rack middleware ごとの経過時間をはかるやつ
# ref: http://blog.mirakui.com/entry/2012/04/03/slow-middleware
module RackMiddlewareBenchmarker
module Benchmarker
def call(env)
result = nil
ms = Benchmark.ms { result = super }
puts "MIDDLEWARE END #{self.class.to_s} (#{ms.to_i}ms)"
result
end
end
def build(app)
app.class.prepend(Benchmarker)
super
end
end
ActionDispatch::MiddlewareStack::Middleware.prepend(RackMiddlewareBenchmarker)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment