Class: RailsApiProfiler::Middleware
- Inherits:
-
Object
- Object
- RailsApiProfiler::Middleware
- Defined in:
- lib/rails_api_profiler/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/rails_api_profiler/middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rails_api_profiler/middleware.rb', line 7 def call(env) config = RailsApiProfiler.configuration return @app.call(env) unless config.enabled Subscribers::ActiveRecord.reset! start = Process.clock_gettime(Process::CLOCK_MONOTONIC) status, headers, response = @app.call(env) finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) duration = ((finish - start) * 1000).round(2) db_stats = Subscribers::ActiveRecord.stats log(env, status, duration, db_stats, config) [status, headers, response] end |