lib/tunemygc/spies/action_controller.rb in tunemygc-1.0.34 vs lib/tunemygc/spies/action_controller.rb in tunemygc-1.0.35
- old
+ new
@@ -30,18 +30,17 @@
module Spies
class ActionController < TuneMyGc::Spies::Base
attr_reader :subscriptions
def initialize
+ super
@subscriptions = []
- @requests_processed = 0
- @requests_limit = nil
end
def install
- @subscriptions << ActiveSupport::Notifications.subscribe(/^start_processing.action_controller$/, TuneMyGc::StartRequestSubscriber.new)
- @subscriptions << ActiveSupport::Notifications.subscribe(/^process_action.action_controller$/, TuneMyGc::EndRequestSubscriber.new)
+ subscription(/^start_processing.action_controller$/, TuneMyGc::StartRequestSubscriber.new)
+ subscription(/^process_action.action_controller$/, TuneMyGc::EndRequestSubscriber.new)
TuneMyGc.log "hooked: action_controller"
end
def uninstall
TuneMyGc.uninstall_gc_tracepoint
@@ -51,16 +50,21 @@
TuneMyGc.log "uninstalled action_controller spy"
end
def check_uninstall
if ENV["RUBY_GC_TUNE_REQUESTS"]
- @requests_limit ||= Integer(ENV["RUBY_GC_TUNE_REQUESTS"])
- @requests_processed += 1
- if @requests_processed == @requests_limit
+ @limit ||= Integer(ENV["RUBY_GC_TUNE_REQUESTS"])
+ @processed += 1
+ if @processed == @limit
uninstall
- TuneMyGc.log "kamikaze after #{@requests_processed} of #{@requests_limit} requests"
+ TuneMyGc.log "kamikaze after #{@processed} of #{@limit} requests"
end
end
+ end
+
+ private
+ def subscription(pattern, handler)
+ @subscriptions << ActiveSupport::Notifications.subscribe(pattern, handler)
end
end
end
end
\ No newline at end of file