1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix rb_profile_frame_classpath to handle module singletons

Right now `SomeClass.method` is properly named, but `SomeModule.method`
is displayed as `#<Module:0x000055eb5d95adc8>.method` which makes
profiling annoying.
This commit is contained in:
Jean Boussier 2020-05-06 18:49:25 +02:00 committed by Aaron Patterson
parent 00698f26a9
commit cbe4f75ef8
Notes: git 2020-05-08 00:46:59 +09:00
2 changed files with 35 additions and 7 deletions

View file

@ -3,6 +3,16 @@ require 'test/unit'
require '-test-/debug' require '-test-/debug'
class SampleClassForTestProfileFrames class SampleClassForTestProfileFrames
class << self
attr_accessor :sample4
end
self.sample4 = Module.new do
def self.corge(block)
Sample2.new.baz(block)
end
end
class Sample2 class Sample2
def baz(block) def baz(block)
instance_eval "def zab(block) block.call end" instance_eval "def zab(block) block.call end"
@ -10,8 +20,16 @@ class SampleClassForTestProfileFrames
end end
end end
module Sample3
class << self
def qux(block)
SampleClassForTestProfileFrames.sample4.corge(block)
end
end
end
def self.bar(block) def self.bar(block)
Sample2.new.baz(block) Sample3.qux(block)
end end
def foo(block) def foo(block)
@ -29,6 +47,8 @@ class TestProfileFrames < Test::Unit::TestCase
"test_profile_frames", "test_profile_frames",
"zab", "zab",
"baz", "baz",
"corge",
"qux",
"bar", "bar",
"foo", "foo",
"test_profile_frames", "test_profile_frames",
@ -37,6 +57,8 @@ class TestProfileFrames < Test::Unit::TestCase
"test_profile_frames", "test_profile_frames",
"zab", "zab",
"baz", "baz",
"corge",
"qux",
"bar", "bar",
"foo", "foo",
"test_profile_frames", "test_profile_frames",
@ -45,6 +67,8 @@ class TestProfileFrames < Test::Unit::TestCase
"TestProfileFrames#test_profile_frames", "TestProfileFrames#test_profile_frames",
"#{obj.inspect}.zab", "#{obj.inspect}.zab",
"SampleClassForTestProfileFrames::Sample2#baz", "SampleClassForTestProfileFrames::Sample2#baz",
"#{SampleClassForTestProfileFrames.sample4.inspect}.corge",
"SampleClassForTestProfileFrames::Sample3.qux",
"SampleClassForTestProfileFrames.bar", "SampleClassForTestProfileFrames.bar",
"SampleClassForTestProfileFrames#foo", "SampleClassForTestProfileFrames#foo",
"TestProfileFrames#test_profile_frames", "TestProfileFrames#test_profile_frames",
@ -53,17 +77,21 @@ class TestProfileFrames < Test::Unit::TestCase
TestProfileFrames, TestProfileFrames,
obj, obj,
SampleClassForTestProfileFrames::Sample2, SampleClassForTestProfileFrames::Sample2,
SampleClassForTestProfileFrames.sample4,
SampleClassForTestProfileFrames::Sample3,
SampleClassForTestProfileFrames, # singleton method SampleClassForTestProfileFrames, # singleton method
SampleClassForTestProfileFrames, SampleClassForTestProfileFrames,
TestProfileFrames, TestProfileFrames,
] ]
singleton_method_p = [ singleton_method_p = [
false, true, false, true, false, false, false, false, true, false, true, true, true, false, false, false,
] ]
method_names = [ method_names = [
"test_profile_frames", "test_profile_frames",
"zab", "zab",
"baz", "baz",
"corge",
"qux",
"bar", "bar",
"foo", "foo",
"test_profile_frames", "test_profile_frames",
@ -72,14 +100,14 @@ class TestProfileFrames < Test::Unit::TestCase
"TestProfileFrames#test_profile_frames", "TestProfileFrames#test_profile_frames",
"#{obj.inspect}.zab", "#{obj.inspect}.zab",
"SampleClassForTestProfileFrames::Sample2#baz", "SampleClassForTestProfileFrames::Sample2#baz",
"#{SampleClassForTestProfileFrames.sample4.inspect}.corge",
"SampleClassForTestProfileFrames::Sample3.qux",
"SampleClassForTestProfileFrames.bar", "SampleClassForTestProfileFrames.bar",
"SampleClassForTestProfileFrames#foo", "SampleClassForTestProfileFrames#foo",
"TestProfileFrames#test_profile_frames", "TestProfileFrames#test_profile_frames",
] ]
paths = [ file=__FILE__, "(eval)", file, file, file, file ] paths = [ file=__FILE__, "(eval)", file, file, file, file, file, file ]
absolute_paths = [ file, nil, file, file, file, file ] absolute_paths = [ file, nil, file, file, file, file, file, file ]
# pp frames
assert_equal(labels.size, frames.size) assert_equal(labels.size, frames.size)

View file

@ -1425,7 +1425,7 @@ rb_profile_frame_classpath(VALUE frame)
} }
else if (FL_TEST(klass, FL_SINGLETON)) { else if (FL_TEST(klass, FL_SINGLETON)) {
klass = rb_ivar_get(klass, id__attached__); klass = rb_ivar_get(klass, id__attached__);
if (!RB_TYPE_P(klass, T_CLASS)) if (!RB_TYPE_P(klass, T_CLASS) && !RB_TYPE_P(klass, T_MODULE))
return rb_sprintf("#<%s:%p>", rb_class2name(rb_obj_class(klass)), (void*)klass); return rb_sprintf("#<%s:%p>", rb_class2name(rb_obj_class(klass)), (void*)klass);
} }
return rb_class_path(klass); return rb_class_path(klass);