Actions
Feature #18835
openAdd InstructionSequence#type method
Status:
Open
Assignee:
-
Target version:
-
Description
This method returns a symbol representing the type of the instruction
sequence object.
I'm trying to collect some statistics about instruction sequences for an entire system, but I mostly care about methods and blocks. This feature lets me select only methods and blocks to analyze.
I am using a script like this:
def walk iseq
case iseq.type
when :METHOD, :BLOCK
count = 0
sends = 0
iseq.to_a.last.each do |insn|
count += 1 if insn.is_a?(Array)
case insn
in [:opt_send_without_block, _]
sends += 1
in [:send, _]
sends += 1
in [:invokeblock]
sends += 1
else
end
end
p [count, sends]
end
iseq.each_child { |n| walk(n) }
end
iseq = RubyVM::InstructionSequence.compile_file(ARGV[0])
walk iseq
Then in my shell I can do this:
$ find ~/git/rails/activerecord/lib -name '*.rb' -exec ./miniruby test.rb {} \;
I'm able to calculate instructions per method as well as number of "sends" per iseq. (Of course this isn't 100% accurate because of metaprogramming etc, but I think it lets us get good estimates)
I made a pull request here and I've attached a patch as well.
Files
No data to display
Actions
Like0