Class: RuntimeProfiler::Profiler
- Inherits:
-
Object
- Object
- RuntimeProfiler::Profiler
- Defined in:
- lib/runtime_profiler/profiler.rb
Instance Attribute Summary collapse
-
#profiled_constants ⇒ Object
Returns the value of attribute profiled_constants.
Instance Method Summary collapse
-
#initialize(constants) ⇒ Profiler
constructor
A new instance of Profiler.
- #prepare_for_profiling ⇒ Object
- #prepare_methods_to_profile ⇒ Object
- #save_profiling_data ⇒ Object
- #subscribe_to_event_notifications ⇒ Object
- #unsubscribe_to_event_notifications ⇒ Object
Constructor Details
#initialize(constants) ⇒ Profiler
Returns a new instance of Profiler.
11 12 13 |
# File 'lib/runtime_profiler/profiler.rb', line 11 def initialize(constants) self.profiled_constants = constants end |
Instance Attribute Details
#profiled_constants ⇒ Object
Returns the value of attribute profiled_constants.
9 10 11 |
# File 'lib/runtime_profiler/profiler.rb', line 9 def profiled_constants @profiled_constants end |
Instance Method Details
#prepare_for_profiling ⇒ Object
15 16 17 18 |
# File 'lib/runtime_profiler/profiler.rb', line 15 def prepare_for_profiling subscribe_to_event_notifications prepare_methods_to_profile end |
#prepare_methods_to_profile ⇒ Object
40 41 42 43 |
# File 'lib/runtime_profiler/profiler.rb', line 40 def prepare_methods_to_profile profiled_constants.flatten .each { |constant| MethodMeter.observe(constant, RuntimeProfiler.excepted_methods) } end |
#save_profiling_data ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/runtime_profiler/profiler.rb', line 45 def save_profiling_data unsubscribe_to_event_notifications profiling_data = RuntimeProfiler::Data.new \ controller_data: @action_controller_callback.controller_data, sql_data: @active_record_callback.data profiling_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 |