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, slow_request_threshold = 5, sampling_interval = 0.1) ⇒ ProfilingApp
constructor
A new instance of ProfilingApp.
- #output_handler(env) ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(app, slow_request_threshold = 5, sampling_interval = 0.1) ⇒ ProfilingApp
Returns a new instance of ProfilingApp.
9 10 11 12 13 14 15 16 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 9 def initialize(app, slow_request_threshold=5, sampling_interval=0.1) @app = app @slow_request_threshold = slow_request_threshold @sampling_interval = sampling_interval @post = Post.new @prof = SamplingProf.new(@sampling_interval) at_exit { terminate } end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 18 def call(env) @prof.profile(output_handler(env)) { @app.call(env) } end |
#output_handler(env) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 27 def output_handler(env) request_env = RequestEnv.new(env) lambda do |data| if request_env.time > @slow_request_threshold @post.enqueue(request_env.to_report.merge("data" => data)) end end end |
#terminate ⇒ Object
22 23 24 25 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 22 def terminate @prof.terminate rescue nil @post.terminate rescue nil end |