diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2019-03-11 15:07:52 -0400 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2019-08-08 14:22:56 +0900 |
commit | 1c7d3a13caa718ef52ec6b55988b1459a002f965 (patch) | |
tree | 1807804755fbd24a369ac495bc43a7bcf36b5132 /vm.c | |
parent | 70fd099220446e39bb80eb0bb32870ce12134619 (diff) | |
download | bundler-1c7d3a13caa718ef52ec6b55988b1459a002f965.tar.gz |
Add *_start and *_running methods to VM_COLLECT_USAGE_DETAILS API
Add RubyVM::USAGE_ANALYSIS_INSN_START, RubyVM::USAGE_ANALYSIS_OPERAND_START,
and RubyVM::USAGE_ANALYSIS_REGISTER_START to begin collecting VM instructions.
Add RubyVM::USAGE_ANALYSIS_INSN_RUNNING, RubyVM::USAGE_ANALYSIS_OPERAND_RUNNING,
and RubyVM::USAGE_ANALYSIS_REGISTER_RUNNING to check if VM instructions
are being collected.
Closes: https://github.com/ruby/ruby/pull/2258
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 66 |
1 files changed, 63 insertions, 3 deletions
@@ -2890,9 +2890,15 @@ nsdr(void) } #if VM_COLLECT_USAGE_DETAILS +static VALUE usage_analysis_insn_start(VALUE self); +static VALUE usage_analysis_operand_start(VALUE self); +static VALUE usage_analysis_register_start(VALUE self); static VALUE usage_analysis_insn_stop(VALUE self); static VALUE usage_analysis_operand_stop(VALUE self); static VALUE usage_analysis_register_stop(VALUE self); +static VALUE usage_analysis_insn_running(VALUE self); +static VALUE usage_analysis_operand_running(VALUE self); +static VALUE usage_analysis_register_running(VALUE self); #endif void @@ -3113,9 +3119,15 @@ Init_VM(void) define_usage_analysis_hash(REGS); define_usage_analysis_hash(INSN_BIGRAM); + rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_INSN_START", usage_analysis_insn_start, 0); + rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_OPERAND_START", usage_analysis_operand_start, 0); + rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_REGISTER_START", usage_analysis_register_start, 0); rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_INSN_STOP", usage_analysis_insn_stop, 0); rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_OPERAND_STOP", usage_analysis_operand_stop, 0); rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_REGISTER_STOP", usage_analysis_register_stop, 0); + rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_INSN_RUNNING", usage_analysis_insn_running, 0); + rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_OPERAND_RUNNING", usage_analysis_operand_running, 0); + rb_define_singleton_method(rb_cRubyVM, "USAGE_ANALYSIS_REGISTER_RUNNING", usage_analysis_register_running, 0); #endif /* ::RubyVM::OPTS, which shows vm build options */ @@ -3455,9 +3467,33 @@ vm_analysis_register(int reg, int isset) #undef HASH_ASET -static void (*ruby_vm_collect_usage_func_insn)(int insn) = vm_analysis_insn; -static void (*ruby_vm_collect_usage_func_operand)(int insn, int n, VALUE op) = vm_analysis_operand; -static void (*ruby_vm_collect_usage_func_register)(int reg, int isset) = vm_analysis_register; +static void (*ruby_vm_collect_usage_func_insn)(int insn) = NULL; +static void (*ruby_vm_collect_usage_func_operand)(int insn, int n, VALUE op) = NULL; +static void (*ruby_vm_collect_usage_func_register)(int reg, int isset) = NULL; + +/* :nodoc: */ +static VALUE +usage_analysis_insn_start(VALUE self) +{ + ruby_vm_collect_usage_func_insn = vm_analysis_insn; + return Qnil; +} + +/* :nodoc: */ +static VALUE +usage_analysis_operand_start(VALUE self) +{ + ruby_vm_collect_usage_func_operand = vm_analysis_operand; + return Qnil; +} + +/* :nodoc: */ +static VALUE +usage_analysis_register_start(VALUE self) +{ + ruby_vm_collect_usage_func_register = vm_analysis_register; + return Qnil; +} /* :nodoc: */ static VALUE @@ -3483,6 +3519,30 @@ usage_analysis_register_stop(VALUE self) return Qnil; } +/* :nodoc: */ +static VALUE +usage_analysis_insn_running(VALUE self) +{ + if (ruby_vm_collect_usage_func_insn == 0) return Qfalse; + return Qtrue; +} + +/* :nodoc: */ +static VALUE +usage_analysis_operand_running(VALUE self) +{ + if (ruby_vm_collect_usage_func_operand == 0) return Qfalse; + return Qtrue; +} + +/* :nodoc: */ +static VALUE +usage_analysis_register_running(VALUE self) +{ + if (ruby_vm_collect_usage_func_register == 0) return Qfalse; + return Qtrue; +} + #else MAYBE_UNUSED(static void (*ruby_vm_collect_usage_func_insn)(int insn)) = NULL; |