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
- #slow_request_threshold ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(app) ⇒ ProfilingApp
Returns a new instance of ProfilingApp.
9 10 11 12 13 14 15 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 9 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
17 18 19 20 21 22 23 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 17 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
30 31 32 33 34 35 36 37 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 30 def output_handler(env) request_env = RequestEnv.new(env) lambda do |data| if request_env.time > slow_request_threshold request_env.to_report.merge(:data => data) end end end |
#slow_request_threshold ⇒ Object
38 39 40 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 38 def slow_request_threshold @srt ||= Corn.slow_request_threshold end |
#terminate ⇒ Object
25 26 27 28 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 25 def terminate @@prof.terminate @@prof = nil end |