class DasProfiler::Middleware
Rack middleware to capture profile traces and submit them to Das Profiler.
Constants
- VERSION
Current gem version
Public Class Methods
new(app, options = {})
click to toggle source
@option options [#call] :enabled (->(_env) { rand <= 0.01 }) A callable
which receives the current Rack env and returns true if a trace should be taken of the request
@option options [Integer] :interval (1000) Microseconds between samples.
On some linux systems this may be rounded up to the nearest multiple of 4000 if mode is :cpu
@option options [Symbol] :mode (:cpu) Either :cpu or :wall @option (see DasProfiler::Middleware::Submitter#initialize)
# File lib/das_profiler/middleware.rb, line 17 def initialize(app, options = {}) @app = app @submitter = Submitter.new(options) @enabled = options[:enabled] || ->(_env) { rand <= 0.01 } interval = options[:interval] || 1000 mode = options[:mode] || :cpu @stackprof_opts = { mode: mode, interval: interval } end
Public Instance Methods
call(env)
click to toggle source
# File lib/das_profiler/middleware.rb, line 27 def call(env) enabled = @enabled.call(env) StackProf.start(@stackprof_opts) if enabled @app.call(env) ensure if enabled StackProf.stop @submitter.submit_if_needed end end