Class: RuntimeProfiler::Profiler
- Inherits:
-
Object
- Object
- RuntimeProfiler::Profiler
- Defined in:
- lib/runtime_profiler/profiler.rb
Instance Attribute Summary collapse
-
#instrumented_constants ⇒ Object
Returns the value of attribute instrumented_constants.
Instance Method Summary collapse
-
#initialize(konstants) ⇒ Profiler
constructor
A new instance of Profiler.
- #prepare_for_instrumentation ⇒ Object
- #prepare_methods_to_instrument ⇒ Object
- #save_instrumentation_data ⇒ Object
- #subscribe_to_event_notifications ⇒ Object
- #unsubscribe_to_event_notifications ⇒ Object
Constructor Details
#initialize(konstants) ⇒ Profiler
Returns a new instance of Profiler.
11 12 13 |
# File 'lib/runtime_profiler/profiler.rb', line 11 def initialize(konstants) self.instrumented_constants = konstants end |
Instance Attribute Details
#instrumented_constants ⇒ Object
Returns the value of attribute instrumented_constants.
9 10 11 |
# File 'lib/runtime_profiler/profiler.rb', line 9 def instrumented_constants @instrumented_constants end |
Instance Method Details
#prepare_for_instrumentation ⇒ Object
15 16 17 18 |
# File 'lib/runtime_profiler/profiler.rb', line 15 def prepare_for_instrumentation subscribe_to_event_notifications prepare_methods_to_instrument end |
#prepare_methods_to_instrument ⇒ Object
40 41 42 43 |
# File 'lib/runtime_profiler/profiler.rb', line 40 def prepare_methods_to_instrument instrumented_constants.flatten .each { |constant| MethodMeter.observe(constant, RuntimeProfiler.excepted_methods) } end |
#save_instrumentation_data ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/runtime_profiler/profiler.rb', line 45 def save_instrumentation_data unsubscribe_to_event_notifications instrumentation_data = RuntimeProfiler::InstrumentationData.new \ controller_data: @action_controller_callback.controller_data, sql_data: @active_record_callback.data instrumentation_data.persist! end |
#subscribe_to_event_notifications ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/runtime_profiler/profiler.rb', line 20 def subscribe_to_event_notifications @subscribers = [] @active_record_callback = Callback::ActiveRecord.new @subscribers << ActiveSupport::Notifications .subscribe('sql.active_record', @active_record_callback) @action_controller_callback = Callback::ActionController.new @subscribers << ActiveSupport::Notifications .subscribe('process_action.action_controller', @action_controller_callback) end |
#unsubscribe_to_event_notifications ⇒ Object
34 35 36 37 38 |
# File 'lib/runtime_profiler/profiler.rb', line 34 def unsubscribe_to_event_notifications @subscribers.each do |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) end end |