Sha256: de1b3fa8e2ac5a5fd648f24975f4924f8e6de7f5c39f5d1a35c96b09a2728cd9
Contents?: true
Size: 780 Bytes
Versions: 21
Compression:
Stored size: 780 Bytes
Contents
module Servel::Instrumentation def instrument(*method_names) return unless ENV["DEBUG"] == "1" Array(method_names).each do |method_name| original_method_name = "#{method_name}_without_instrumentation" alias_method original_method_name, method_name cumulative_time_spent = 0 define_method(method_name) do |*args| start = Time.now return_value = __send__(original_method_name, *args) finish = Time.now time_spent = ((finish - start) * 1000.0) cumulative_time_spent += time_spent puts "Running #{self.class.name}<#{object_id}>##{method_name}: #{time_spent.round(3)}ms (cumulative: #{cumulative_time_spent.round(3)}ms)" return_value end end end end
Version data entries
21 entries across 21 versions & 1 rubygems
Version | Path |
---|---|
servel-0.12.0 | lib/servel/instrumentation.rb |