class Upfluence::HTTP::Endpoint::Profiler
Public Class Methods
new(opts = {})
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 7 def initialize(opts = {}) @interval = opts[:interval] || 50 @mode = opts[:mode] || :cpu @mapping = Rack::URLMap.new( '/start' => lambda { |env| start(env) }, '/stop' => lambda { |env| stop(env) }, '/profile' => lambda { |env| profile(env) } ) end
Public Instance Methods
call(env)
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 17 def call(env) @mapping.call(env) end
Private Instance Methods
ok()
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 41 def ok [200, {}, ['ok']] end
path(env)
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 45 def path(env) Rack::Request.new(env).path end
profile(env)
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 33 def profile(env) results = StackProf.results @last_results = Marshal.dump(results) if results return [200, {}, [@last_results]] if @last_results return [404, {}, ['No profile available']] end
start(env)
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 28 def start(env) StackProf.start(mode: @mode, interval: @interval, raw: false) return ok end
stop(env)
click to toggle source
# File lib/upfluence/http/endpoint/profiler.rb, line 23 def stop(env) StackProf.stop return ok end