Bug #9703
closedInconsistent profile output
Description
The output of the profile lib seems to be partially dependent on how it is required. For example,
ruby -rprofile -e '0==1'
shows one call to Fixnum#== as expected
ruby -e 'require "profile"; 0==1'
does not show any calls to Fixnum#== !!!
ruby -e 'require "profile"; eval("0==1")'
again shows one call to Fixnum#== as expected.
Updated by srawlins (Sam Rawlins) over 10 years ago
This is due to profile.rb
's :specialized_instruction => false
compile option, on line 5. If you comment it out, none of the three cases will show any calls to #==
. Specialized instructions are performance-optimized during compile-time. By default, specialized instructions are enabled. In the second example, 0==1
is parsed before require "profile"
is evaluated, so that #==
is optimized, and not traced. The opposite is true in the first and third examples.
You can also see how 0 == 1
is compiled differently w/ or w/o specialized instructions by comparing:
puts RubyVM::InstructionSequence.compile("0 == 1", "foo.rb", "/foo.rb", 1).disasm
with
puts RubyVM::InstructionSequence.compile("0 == 1", "foo.rb", "/foo.rb", 1, specialized_instruction: false).disasm
If this is not a bug, I think it should be documented, either in Profile, TracePoint, or InstructionSequence. I don't think there is one canonical list of specialized instructions, but a good place to start is iseq_specialized_instruction()
and iseq_compile_each()'s
case NODE_MATCH.
Updated by naruse (Yui NARUSE) almost 7 years ago
- Target version deleted (
2.2.0)
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Status changed from Open to Closed
The profile library was removed in bc76d8a232bed2e245cd3997ebd9826938f7a738.