From: "tenderlovemaking (Aaron Patterson)" Date: 2022-06-16T22:30:36+00:00 Subject: [ruby-core:108968] [Ruby master Feature#18835] Add InstructionSequence#type method Issue #18835 has been reported by tenderlovemaking (Aaron Patterson). ---------------------------------------- Feature #18835: Add InstructionSequence#type method https://bugs.ruby-lang.org/issues/18835 * Author: tenderlovemaking (Aaron Patterson) * Status: Open * Priority: Normal ---------------------------------------- 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: ```ruby 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](https://github.com/ruby/ruby/pull/5809) and I've attached a patch as well. ---Files-------------------------------- 0001-Add-InstructionSequence-type-method.patch (2.16 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: