Feature #6649

Add new set_trace_func events "b-call", "b-return"

Added by Koichi Sasada about 3 years ago. Updated almost 3 years ago.

[ruby-core:45878]
Status:Rejected
Priority:Normal
Assignee:Yukihiro Matsumoto

Description

=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, butm2' 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) 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

History

#1 Updated by Koichi Sasada about 3 years ago

  • Description updated (diff)

#2 Updated by Thomas Sawyer about 3 years ago

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.

I assume referring to ruby-core:5528

#3 Updated by Koichi Sasada about 3 years ago

(2012/06/26 23:32), trans (Thomas Sawyer) wrote:

I assume referring to ruby-core:5528

Sound interesting.

Can I see the reference of TracePoint? I found README.rdoc and
lib/tracepoint,rb, but I can't find the specification what methods tp
(block parameter: TracePoint.trace(type) do |tp| ... end) has.

--
// SASADA Koichi at atdot dot net

#4 Updated by Thomas Sawyer about 3 years ago

This should help. I added some YARD docs. See http://rubydoc.info/github/rubyworks/tracepoint/master/frames

#5 Updated by Koichi Sasada about 3 years ago

(2012/06/27 21:54), trans (Thomas Sawyer) wrote:

This should help. I added some YARD docs. See http://rubydoc.info/github/rubyworks/tracepoint/master/frames

Thanks. I understand the API of TracePoint.

How about to close this ticket and 5528, and re-new ticket about
TracePoint API for Ruby 2.0?

My rough idea:

  • Add TracePoint class

    • The class name should be considered.
      • I have no idea about it.
    • ::TracePoint or RubyVM::TracePoint or Thread::TracePoint?
  • Add event-separated hooks

    • TracePoint.trace(event_name) { ... } seems good.
    • But how to choose Thread local or system global?
      • Now, we have Kernel#set_trace_func and Thread#set_trace_func
    • One idea is Kernel#trace_point(event_name) and Thread#trace_point(event_name)
  • Add basic methods (attributes)

    • binding
    • event # event signatures should be symbol, I think.
      • :call, :return
      • :ccall, :creturn
      • :bcall, :breturn # new!
      • :class, :end
      • :raise
      • :line
    • file
    • line
    • klass/id are not in TracePoint. No need to have?
  • I think "call?" or other methods are not needed because
    we can define in Ruby. Are they indispensable?

--
// SASADA Koichi at atdot dot net

#6 Updated by Yusuke Endoh almost 3 years ago

  • Status changed from Open to Assigned

#7 Updated by Koichi Sasada almost 3 years ago

  • Status changed from Assigned to Rejected

Nobody has interest about it.
I close (reject) this ticket and make new ticket of
https://bugs.ruby-lang.org/issues/6649#note-5,
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/45949
with implementation.

If you have any idea, please teach me.

Also available in: Atom PDF