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
#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 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/benelux/packer.rb', line 96 def generate_packed_method %Q{ def #{@meth}(*args, &block) 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.thread_timeline.add_mark :'#{@aliaz}_a' mark_a.add_tag :call_id => call_id tags = mark_a.tags ret = #{@methorig}(*args, &block) rescue => ex # We do this so we can use raise ex # ex in the ensure block. ensure mark_z = Benelux.thread_timeline.add_mark :'#{@aliaz}_z' mark_z.tags = tags # In case tags were added between these marks range = Benelux.thread_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)
86 87 88 |
# File 'lib/benelux/packer.rb', line 86 def install_method @klass.module_eval generate_packed_method, __FILE__, 94 end |