class Corn::Rack::SlowRequestProfiler::ProfilingApp

Public Class Methods

new(app) click to toggle source
# 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

Public Instance Methods

call(env) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/corn/rack/slow_request_profiler.rb, line 38
def slow_request_threshold
  @srt ||= Corn.slow_request_threshold
end
terminate() click to toggle source
# File lib/corn/rack/slow_request_profiler.rb, line 25
def terminate
  @@prof.terminate
  @@prof = nil
end