Class: Rack::Stackprof

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/stackprof/version.rb,
lib/rack/stackprof.rb

Constant Summary collapse

VERSION =
'0.2.0'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Stackprof.



5
6
7
8
9
10
11
# File 'lib/rack/stackprof.rb', line 5

def initialize(app, options = {})
  @app = app
  @profile_interval_seconds = options.fetch(:profile_interval_seconds)
  @sampling_interval_microseconds = options.fetch(:sampling_interval_microseconds)
  @last_profiled_at = nil
  StackProf::Middleware.path = options.fetch(:result_directory) # for `StackProf::Middleware.save`
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
# File 'lib/rack/stackprof.rb', line 13

def call(env)
  # Profile every X seconds (not everytime) to prevent from consuming disk excessively
  profile_every(seconds: @profile_interval_seconds, env: env) do
    @app.call(env)
  end
end