summaryrefslogtreecommitdiff
path: root/vm_dump.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-04 12:31:05 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-04 12:31:05 +0000
commit23dc0dbc4ad3354a9df899c0105c57bf42e2d243 (patch)
tree9fdcd41591a161885d19cdd96949d743fdc69102 /vm_dump.c
parentb1ad79774de9789a2dd60c19c907356fa823ebd9 (diff)
* vm.c (VM_COLLECT_USAGE_DETAILS): make new VM usage analysis
hooks (old macro name is COLLECT_USAGE_ANALYSIS). This feature is only for VM developers. (I'm not sure I can use `VM developers' (the plural form) in this sentence). If VM_COLLECT_USAGE_DETAILS is not 0, VM enables the following usage collection features: (1) insntruction: collect intruction usages. (2) operand: collect operand usages. (3) register: collect register usages. The results are stored in RubyVM::USAGE_ANALYSIS_INSN for (1, 2), RubyVM::USAGE_ANALYSIS_INSN_BIGRAM for (1) and RubyVM::USAGE_ANALYSIS_REGS for (3). You can stop collecting usages with RubyVM::USAGE_ANALYSIS_INSN_STOP(), RubyVM::USAGE_ANALYSIS_OPERAND_STOP(), RubyVM::USAGE_ANALYSIS_REGISTER_STOP() for (1), (2), (3) respectively. You can also change the hook functions by setting C level global variables `ruby_vm_collect_usage_func_(insn|operand|register)' for (1), (2), (3) respectively. See codes for more details. * tool/instruction.rb: fix macro names. * iseq.c (insn_operand_intern): make it export (used in vm.c). fix to skip several processes if not needed (pointer is 0). * vm_dump.c: move codes for collection features to vm.c. * vm_exec.h: rename macro and function names. * vm_insnhelper.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_dump.c')
-rw-r--r--vm_dump.c139
1 files changed, 0 insertions, 139 deletions
diff --git a/vm_dump.c b/vm_dump.c
index 10061020ce..8e005bd14e 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -395,145 +395,6 @@ rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp
#endif
}
-#ifdef COLLECT_USAGE_ANALYSIS
-/* uh = {
- * insn(Fixnum) => ihash(Hash)
- * }
- * ihash = {
- * -1(Fixnum) => count, # insn usage
- * 0(Fixnum) => ophash, # operand usage
- * }
- * ophash = {
- * val(interned string) => count(Fixnum)
- * }
- */
-void
-vm_analysis_insn(int insn)
-{
- ID usage_hash;
- ID bigram_hash;
- static int prev_insn = -1;
-
- VALUE uh;
- VALUE ihash;
- VALUE cv;
-
- CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
- CONST_ID(bigram_hash, "USAGE_ANALYSIS_INSN_BIGRAM");
- uh = rb_const_get(rb_cRubyVM, usage_hash);
- if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
- ihash = rb_hash_new();
- rb_hash_aset(uh, INT2FIX(insn), ihash);
- }
- if ((cv = rb_hash_aref(ihash, INT2FIX(-1))) == Qnil) {
- cv = INT2FIX(0);
- }
- rb_hash_aset(ihash, INT2FIX(-1), INT2FIX(FIX2INT(cv) + 1));
-
- /* calc bigram */
- if (prev_insn != -1) {
- VALUE bi;
- VALUE ary[2];
- VALUE cv;
-
- ary[0] = INT2FIX(prev_insn);
- ary[1] = INT2FIX(insn);
- bi = rb_ary_new4(2, &ary[0]);
-
- uh = rb_const_get(rb_cRubyVM, bigram_hash);
- if ((cv = rb_hash_aref(uh, bi)) == Qnil) {
- cv = INT2FIX(0);
- }
- rb_hash_aset(uh, bi, INT2FIX(FIX2INT(cv) + 1));
- }
- prev_insn = insn;
-}
-
-/* from disasm.c */
-extern VALUE insn_operand_intern(int insn, int op_no, VALUE op,
- int len, int pos, VALUE child);
-
-void
-vm_analysis_operand(int insn, int n, VALUE op)
-{
- ID usage_hash;
-
- VALUE uh;
- VALUE ihash;
- VALUE ophash;
- VALUE valstr;
- VALUE cv;
-
- CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
-
- uh = rb_const_get(rb_cRubyVM, usage_hash);
- if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
- ihash = rb_hash_new();
- rb_hash_aset(uh, INT2FIX(insn), ihash);
- }
- if ((ophash = rb_hash_aref(ihash, INT2FIX(n))) == Qnil) {
- ophash = rb_hash_new();
- rb_hash_aset(ihash, INT2FIX(n), ophash);
- }
- /* intern */
- valstr = insn_operand_intern(insn, n, op, 0, 0, 0);
-
- /* set count */
- if ((cv = rb_hash_aref(ophash, valstr)) == Qnil) {
- cv = INT2FIX(0);
- }
- rb_hash_aset(ophash, valstr, INT2FIX(FIX2INT(cv) + 1));
-}
-
-void
-vm_analysis_register(int reg, int isset)
-{
- ID usage_hash;
- VALUE uh;
- VALUE rhash;
- VALUE valstr;
- static const char regstrs[][5] = {
- "pc", /* 0 */
- "sp", /* 1 */
- "ep", /* 2 */
- "cfp", /* 3 */
- "self", /* 4 */
- "iseq", /* 5 */
- };
- static const char getsetstr[][4] = {
- "get",
- "set",
- };
- static VALUE syms[sizeof(regstrs) / sizeof(regstrs[0])][2];
-
- VALUE cv;
-
- CONST_ID(usage_hash, "USAGE_ANALYSIS_REGS");
- if (syms[0] == 0) {
- char buff[0x10];
- int i;
-
- for (i = 0; i < sizeof(regstrs) / sizeof(regstrs[0]); i++) {
- int j;
- for (j = 0; j < 2; j++) {
- snfprintf(stderr, buff, 0x10, "%d %s %-4s", i, getsetstr[j],
- regstrs[i]);
- syms[i][j] = ID2SYM(rb_intern(buff));
- }
- }
- }
- valstr = syms[reg][isset];
-
- uh = rb_const_get(rb_cRubyVM, usage_hash);
- if ((cv = rb_hash_aref(uh, valstr)) == Qnil) {
- cv = INT2FIX(0);
- }
- rb_hash_aset(uh, valstr, INT2FIX(FIX2INT(cv) + 1));
-}
-
-
-#endif
-
VALUE
rb_vmdebug_thread_dump_state(VALUE self)
{