Class: StackProf::Remote::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/stackprof/remote/middleware.rb

Overview

Middleware is a simple Rack middleware that handles requests to urls matching /__stackprof__ for starting/stopping a profile session and retreiving the dump files. It delegates to the ProcessReportCollector to do the actual work of collecting and combining the dumps.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



25
26
27
28
29
30
31
# File 'lib/stackprof/remote/middleware.rb', line 25

def initialize(app, options = {})
  @app       = app
  self.class.logger   = options[:logger] || Logger.new(STDOUT)
  self.class.enabled  = options[:enabled] || false
  self.class.options  = options
  logger.info "[stackprof] Stackprof Middleware enabled"
end

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



14
15
16
# File 'lib/stackprof/remote/middleware.rb', line 14

def enabled
  @enabled
end

.loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/stackprof/remote/middleware.rb', line 14

def logger
  @logger
end

.optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/stackprof/remote/middleware.rb', line 14

def options
  @options
end

Class Method Details

.enabled?(env) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/stackprof/remote/middleware.rb', line 16

def enabled?(env)
  if enabled.respond_to?(:call)
    enabled.call(env)
  else
    enabled
  end
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/stackprof/remote/middleware.rb', line 33

def call(env)
  path = env['PATH_INFO']
  if self.class.enabled?(env) && in_stackprof?(path)
    handle_stackprof(path)
  else
    @app.call(env)
  end
end