class ProfileTools::Profiler
Aggregates profile stats into the collector
Attributes
collector[R]
Public Class Methods
new()
click to toggle source
# File lib/profile_tools/profiler.rb, line 8 def initialize @call_depth = 0 end
Public Instance Methods
instrument(class_and_method_name = 'ProfileTools::Profiler { || ... }
click to toggle source
# File lib/profile_tools/profiler.rb, line 12 def instrument(class_and_method_name = 'ProfileTools::Profiler#instrument') result = nil if increment_call_depth == 1 @collector = new_collector @collector.init_method(class_and_method_name) instrument_with_notifications(class_and_method_name) do result = yield end else instrument_with_collector(class_and_method_name) do result = yield end end decrement_call_depth result end
Private Instance Methods
decrement_call_depth()
click to toggle source
# File lib/profile_tools/profiler.rb, line 49 def decrement_call_depth @call_depth -= 1 end
increment_call_depth()
click to toggle source
# File lib/profile_tools/profiler.rb, line 45 def increment_call_depth @call_depth += 1 end
instrument_with_collector(class_and_method_name) { || ... }
click to toggle source
# File lib/profile_tools/profiler.rb, line 39 def instrument_with_collector(class_and_method_name) @collector.instrument(class_and_method_name) do yield end end
instrument_with_notifications(class_and_method_name) { || ... }
click to toggle source
# File lib/profile_tools/profiler.rb, line 31 def instrument_with_notifications(class_and_method_name) ActiveSupport::Notifications.instrument(EVENT, collector: @collector) do instrument_with_collector(class_and_method_name) do yield end end end
new_collector()
click to toggle source
# File lib/profile_tools/profiler.rb, line 53 def new_collector ::ProfileTools::Collector.new.tap do |collector| ::ProfileTools.profiled_methods.each { |display_name| collector.init_method(display_name) } end end