Class: Corn::Rack::SlowRequestProfiler::ProfilingApp
- Inherits:
-
Object
- Object
- Corn::Rack::SlowRequestProfiler::ProfilingApp
- Defined in:
- lib/corn/rack/slow_request_profiler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ProfilingApp
constructor
A new instance of ProfilingApp.
- #output_handler(env) ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(app) ⇒ ProfilingApp
Returns a new instance of ProfilingApp.
8 9 10 11 12 13 14 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 8 def initialize(app) @@prof ||= Profiler.new(Corn.post_interval, Corn.sampling_interval) @app = app Corn.logger.info("Corn sampling interval: #{Corn.sampling_interval}") Corn.logger.info("Corn slow request threshold: #{Corn.slow_request_threshold}") end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 16 def call(env) if Corn.profiling?(env) @@prof.profile(output_handler(env)) { @app.call(env) } else @app.call(env) end end |
#output_handler(env) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 29 def output_handler(env) request_env = RequestEnv.new(env) lambda do |data| if request_env.time > Corn.slow_request_threshold request_env.to_report.merge("data" => data) end end end |
#terminate ⇒ Object
24 25 26 27 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 24 def terminate @@prof.terminate @@prof = nil end |