Project

General

Profile

Feature #6649

Updated by ko1 (Koichi Sasada) over 12 years ago

=begin 
 = Abstract 

 Add new events "b-call", "b-return" for set_trace_func(). 
 When block is invoked, then "b-call" is called. 
 When block is finished, then "b-return" is called. 

 = Background 

 set_trace_func() has several events: 

 * "line" 
 * "call", "return" 
 * "c-call", "c-return" 
 * "class", "end" 
 * "raise" 

 With above events, we can trace execution.    However, we can't trace block invocation because there are no events related to block invocation and return from block. 

 For example, performance profiler using set_trace_func() has problem in such case: 

   def m1 
     yield 
   end 
  
   def m2 
     m1 do 
       # long time process 
     end 
   end 

 A method `m1' doesn't consume time, but `m2' consume long time (within block). 
 However, the profiler detects that the method `m1' consumes long time. 


 = Proposal 

 Add "b-call" and "b-return" events for set_trace_func.    "b-call" is for block invocation.    "b-return" is for returning from block. 

 Parameters: 

 * event: "b-call" or "b-return" 
 * file: filename of block 
 * line: start/end line number of block 
 * id: block owner method id 
 * binding: binding of block 
 * klass: block owner class 

 = Concerns 

 * This proposal breaks 100% compatibility.    It seems problem (*1). 
 * It will make some runtime overhead (slow down). 
 * parameters id and klass is appropriate? 

 (*1) *1: Making an alternative API which can replace set_trace_func() (correctly speaking, set_trace_func() can be implemented with this new API) is another proposal. 

   # as usual, the method name is temporary name 
   set_trace_func2(lamda{|info| 
     info.event 
     ... 
   } 

 =end 

Back