class Tracebin::Subscribers
Subscribes to certain events, handels them, and passes event data to the Recorder
class. The general workflow goes like this:
-
Patch the method you want to profile. It should generate an array that
looks like the following:
[ "event_type.event_domain", start_time, stop_time, etc..., { event: :data } ]
Note that the event hash must be the last element in the array (this is to maintain consistency with ActiveSupport::Notifications).
-
Store that event array into an appropriate
Event
subclass. -
Add each
Event
object to +@events_data+ using the +#<<+ method.
Public Class Methods
new()
click to toggle source
# File lib/tracebin/subscribers.rb, line 29 def initialize @events_data = Recorder collect_events_data end
Private Instance Methods
active_job_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 102 def active_job_hook ::Tracebin::BackgroundJobInstrumentation.install :active_job end
background_job_hooks()
click to toggle source
# File lib/tracebin/subscribers.rb, line 59 def background_job_hooks if defined? ::ActiveJob active_job_hook else sidekiq_hook resque_hook end end
collect_events_data()
click to toggle source
# File lib/tracebin/subscribers.rb, line 36 def collect_events_data if rails_app? rails_hooks else other_hooks end background_job_hooks end
db_hooks()
click to toggle source
# File lib/tracebin/subscribers.rb, line 68 def db_hooks postgres_hook mysql2_hook end
mysql2_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 119 def mysql2_hook return unless defined? ::Mysql2 ::Tracebin::Patches.patch_mysql2 do |event_data| event = SQLEvent.new event_data @events_data << event end end
other_hooks()
click to toggle source
# File lib/tracebin/subscribers.rb, line 54 def other_hooks sinatra_hook if sinatra_app? db_hooks end
postgres_hook()
click to toggle source
process_action_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 81 def process_action_hook subscribe_asn 'process_action.action_controller', ControllerEvent end
rails_app?()
click to toggle source
# File lib/tracebin/subscribers.rb, line 163 def rails_app? defined? ::Rails end
rails_hooks()
click to toggle source
# File lib/tracebin/subscribers.rb, line 46 def rails_hooks sql_hook process_action_hook render_layout_hook render_template_hook render_partial_hook end
render_layout_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 85 def render_layout_hook unless [ActionPack::VERSION::MAJOR, ActionPack::VERSION::MINOR] == [3, 0] ::Tracebin::Patches.patch_action_view_layout do |event_data| event = ViewEvent.new event_data @events_data << event end end end
render_partial_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 98 def render_partial_hook subscribe_asn 'render_partial.action_view', ViewEvent end
render_template_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 94 def render_template_hook subscribe_asn 'render_template.action_view', ViewEvent end
resque_hook()
click to toggle source
# File lib/tracebin/subscribers.rb, line 136 def resque_hook return unless defined? ::Resque ::Tracebin::BackgroundJobInstrumentation.install :resque end
sidekiq_hook()
click to toggle source
sinatra_app?()
click to toggle source
# File lib/tracebin/subscribers.rb, line 167 def sinatra_app? defined? ::Sinatra end
sinatra_hook()
click to toggle source
sql_hook()
click to toggle source
subscribe_asn(event_name, event_klass)
click to toggle source