Skip to content

Conversation

@tenderlove
Copy link
Member

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

@tenderlove
Copy link
Member Author

@nobu I think I addressed your comments. Thank you for reviewing!

@tenderlove tenderlove requested a review from nobu April 16, 2022 18:09
This method returns a symbol representing the type of the instruction
sequence object.
@hsbt hsbt force-pushed the expose-iseq-type branch from 67f4e73 to 57d2fd1 Compare October 25, 2023 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants