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, config) ⇒ ProfilingApp
constructor
A new instance of ProfilingApp.
- #output_handler(env) ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(app, config) ⇒ ProfilingApp
Returns a new instance of ProfilingApp.
16 17 18 19 20 21 22 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 16 def initialize(app, config) @app = app @config = config @post = Post.new(config.post_interval) @prof = SamplingProf.new(config.sampling_interval) at_exit { terminate } end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 24 def call(env) if @config.profiling? @prof.profile(output_handler(env)) { @app.call(env) } else @app.call(env) end end |
#output_handler(env) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 37 def output_handler(env) request_env = RequestEnv.new(env) lambda do |data| if request_env.time > @config.slow_request_threshold @post.enqueue(request_env.to_report.merge("data" => data)) end end end |
#terminate ⇒ Object
32 33 34 35 |
# File 'lib/corn/rack/slow_request_profiler.rb', line 32 def terminate @prof.terminate rescue nil @post.terminate rescue nil end |