Feature #12747
closedAdd TracePoint#callee_id
Description
Abstract¶
I propose to add TracePoint#callee_id which returns the called name of the method.
def m
end
alias am m
TracePoint.new(:call) do |tp|
p [tp.method_id, tp.callee_id] #=> [:m, :am]
end.enable do
am
end
Background¶
We can get callee id by tp.binding.eval('__callee__'))
,
but it is slow(10x~) and can't get callee id of CFUNC.
class Object
alias aitself itself
end
TracePoint.new(:c_call) do |tp|
p [tp.method_id, tp.binding.eval('__callee__')] #=> [:itself, nil]
end.enable do
aitself
end
Implementation¶
I attached 2 patches.
- 0001-TracePoint-method_id-should-return-method_id-not-cal.patch
- Now, TracePoint#method_id returns not only method id(
__method__
) but callee id.
This patch makes TracePoint#method_id return method id always, so it introduces some incompatibility.
- Now, TracePoint#method_id returns not only method id(
- 0002-Add-TracePoint-callee_id.patch
- Add TracePoint#callee_id.
Usecase¶
power_assert gem wants this method to get column number of each method calls.
Files
Updated by shyouhei (Shyouhei Urabe) about 8 years ago
- Status changed from Open to Assigned
- Assignee set to ko1 (Koichi Sasada)
Updated by ko1 (Koichi Sasada) about 8 years ago
Sorry for late response.
I missed incompatibility.
How about to commit it before next preview and ask feedback from users?
Thansk,
Koichi
Updated by ktsj (Kazuki Tsujimoto) about 8 years ago
- Status changed from Assigned to Closed
Applied in changeset r56592.
-
eval.c, method.h, proc.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c:
TracePoint#method_id should return method_id, not callee_id.
[ruby-core:77241] [Feature #12747] -
test/ruby/test_settracefunc.rb: change accordingly.
Updated by ktsj (Kazuki Tsujimoto) about 8 years ago
Thank you, I committed.
Updated by rhenium (Kazuki Yamaguchi) about 8 years ago
r56593 changed the signature of rb_frame_method_id_and_class() which is exposed to C extensions. For example, this broke ruby-prof gem. Is this intentional?
Updated by ktsj (Kazuki Tsujimoto) about 8 years ago
Thanks Yamaguchi-san, good catch.
I'll revert rb_frame_method_id_and_class.