Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to the option ignore_gc to middleware #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions lib/stackprof/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ def initialize(app, options = {})
@options = options
@num_reqs = options[:save_every] || nil

Middleware.mode = options[:mode] || :cpu
Middleware.interval = options[:interval] || 1000
Middleware.raw = options[:raw] || false
Middleware.enabled = options[:enabled]
options[:path] = 'tmp/' if options[:path].to_s.empty?
Middleware.path = options[:path]
Middleware.metadata = options[:metadata] || {}
Middleware.mode = options[:mode] || :cpu
Middleware.interval = options[:interval] || 1000
Middleware.raw = options[:raw] || false
Middleware.enabled = options[:enabled]
options[:path] = 'tmp/' if options[:path].to_s.empty?
Middleware.path = options[:path]
Middleware.ignore_gc = options[:ignore_gc]
Middleware.metadata = options[:metadata] || {}
at_exit{ Middleware.save } if options[:save_at_exit]
end

def call(env)
enabled = Middleware.enabled?(env)
StackProf.start(
mode: Middleware.mode,
interval: Middleware.interval,
raw: Middleware.raw,
metadata: Middleware.metadata,
mode: Middleware.mode,
interval: Middleware.interval,
raw: Middleware.raw,
ignore_gc: Middleware.raw,
metadata: Middleware.metadata,
) if enabled
@app.call(env)
ensure
Expand All @@ -37,7 +39,13 @@ def call(env)
end

class << self
attr_accessor :enabled, :mode, :interval, :raw, :path, :metadata
attr_accessor :enabled,
:mode,
:interval,
:raw,
:path,
:ignore_gc,
:metadata

def enabled?(env)
if enabled.respond_to?(:call)
Expand Down Expand Up @@ -66,7 +74,6 @@ def save
filename
end
end

end
end
end