Project

General

Profile

Actions

Feature #6649

closed

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

Added by ko1 (Koichi Sasada) almost 12 years ago. Updated over 11 years ago.

Status:
Rejected
Target version:
-
[ruby-core:45878]

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, 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) 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

Updated by ko1 (Koichi Sasada) almost 12 years ago

  • Description updated (diff)

Updated by trans (Thomas Sawyer) almost 12 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] (https://bugs.ruby-lang.org/issues/5528)

Updated by ko1 (Koichi Sasada) almost 12 years ago

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

I assume referring to [ruby-core:5528] (https://bugs.ruby-lang.org/issues/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

Updated by ko1 (Koichi Sasada) over 11 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

Updated by mame (Yusuke Endoh) over 11 years ago

  • Status changed from Open to Assigned

Updated by ko1 (Koichi Sasada) over 11 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0