Class: Benelux::MethodTimer
- Inherits:
-
MethodPacker
- Object
- MethodPacker
- Benelux::MethodTimer
- Defined in:
- lib/benelux/packer.rb
Instance Attribute Summary
Attributes inherited from MethodPacker
#aliaz, #blk, #klass, #meth, #methorig
Attributes included from Selectable::Object
Instance Method Summary collapse
-
#generate_packed_method ⇒ Object
Creates a method definition (for an eval).
-
#install_method ⇒ Object
This method executes the method definition created by generate_method.
Methods inherited from MethodPacker
class_method_defined?, #initialize, #instance_exec, method_defined?, #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 Method Details
#generate_packed_method ⇒ Object
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.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# 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 ⇒ Object
This method executes the method definition created by generate_method. It calls @klass.module_eval
with the modified line number (helpful for exceptions)
106 107 108 |
# File 'lib/benelux/packer.rb', line 106 def install_method @klass.module_eval generate_packed_method, __FILE__, 94 end |