Class: Benelux::MethodCounter

Inherits:
MethodPacker show all
Defined in:
lib/benelux/packer.rb

Instance Attribute Summary collapse

Attributes inherited from MethodPacker

#aliaz, #blk, #klass, #meth, #methorig

Attributes included from Selectable::Object

#tags

Instance Method Summary collapse

Methods inherited from MethodPacker

#initialize, #instance_exec, #run_block

Methods included from Selectable::Object

#add_tags, #add_tags_quick, #init_tags!, #remove_tags, #tag_values

Constructor Details

This class inherits a constructor from Benelux::MethodPacker

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



118
119
120
# File 'lib/benelux/packer.rb', line 118

def counter
  @counter
end

Instance Method Details

#determine_count(args, ret) ⇒ Object



138
139
140
141
# File 'lib/benelux/packer.rb', line 138

def determine_count(args,ret)
  return 1 if @blk.nil?
  self.instance_exec args, ret, &blk
end

#generate_packed_method(callblock = false) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/benelux/packer.rb', line 123

def generate_packed_method(callblock=false)
  %Q{
  def #{@meth}(*args, &block)
    Benelux.current_track :global unless Benelux.known_thread?
    # Get a reference to this MethodCounter instance
    cmd = Benelux.packed_method #{@klass}, :#{@meth}
    ret = #{@methorig}(*args, &block)
    count = cmd.determine_count(args, ret)
    #Benelux.ld "COUNT(:#{@meth}): \#{count}"
    Benelux.thread_timeline.add_count :'#{@meth}', count
    ret
  end
  }
end

#install_methodObject



119
120
121
# File 'lib/benelux/packer.rb', line 119

def install_method
  @klass.module_eval generate_packed_method, __FILE__, 122
end