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.33.0 lib/servel/instrumentation.rb
servel-0.32.0 lib/servel/instrumentation.rb
servel-0.31.0 lib/servel/instrumentation.rb
servel-0.30.0 lib/servel/instrumentation.rb
servel-0.29.0 lib/servel/instrumentation.rb
servel-0.28.0 lib/servel/instrumentation.rb
servel-0.27.0 lib/servel/instrumentation.rb
servel-0.26.0 lib/servel/instrumentation.rb
servel-0.25.0 lib/servel/instrumentation.rb
servel-0.24.0 lib/servel/instrumentation.rb
servel-0.23.0 lib/servel/instrumentation.rb
servel-0.22.0 lib/servel/instrumentation.rb
servel-0.21.0 lib/servel/instrumentation.rb
servel-0.20.0 lib/servel/instrumentation.rb
servel-0.19.0 lib/servel/instrumentation.rb
servel-0.18.0 lib/servel/instrumentation.rb
servel-0.17.0 lib/servel/instrumentation.rb
servel-0.16.0 lib/servel/instrumentation.rb
servel-0.15.0 lib/servel/instrumentation.rb
servel-0.13.0 lib/servel/instrumentation.rb