class Benelux::MethodTimer

Public Instance Methods

generate_packed_method() click to toggle source

Creates a method definition (for an eval). The method is named +@meth+ and it calls +@methorig+.

The new method adds a Mark to the thread timeline before and after +@alias+ is called. It also adds a Range to the timeline based on the two marks.

# File lib/benelux/packer.rb, line 116
def generate_packed_method
  %Q{
  def #{@meth}(*args, &block)
    #p ["#{@meth} 1"]
    call_id = "" << self.object_id.abs.to_s << args.object_id.abs.to_s
    Benelux.current_track :global unless Benelux.known_thread?
    mark_a = Benelux.current_track.timeline.add_mark :'#{@aliaz}_a'
    mark_a.add_tag :call_id => call_id
    tags = mark_a.tags
    ret = #{@methorig}(*args, &block)
    #p ["#{@meth} 2"]
    ret
  rescue => ex  # We do this so we can use
    raise ex    # ex in the ensure block.
  ensure
    mark_z = Benelux.current_track.timeline.add_mark :'#{@aliaz}_z'
    mark_z.tags = tags # In case tags were added between these marks
    range = Benelux.current_track.timeline.add_range :'#{@aliaz}', mark_a, mark_z
    range.exception = ex if defined?(ex) && !ex.nil?
  end
  }
end
install_method() click to toggle source

This method executes the method definition created by generate_method. It calls @klass.module_eval with the modified line number (helpful for exceptions)

# File lib/benelux/packer.rb, line 106
def install_method
  @klass.module_eval generate_packed_method, __FILE__, 94
end