Method: RubyVM.stat
- Defined in:
- vm.c
.stat ⇒ Hash .stat(hsh) ⇒ Hash .stat(Symbol) ⇒ Numeric
Returns a Hash containing implementation-dependent counters inside the VM.
This hash includes information about method/constant caches:
{
:constant_cache_invalidations=>2,
:constant_cache_misses=>14,
:global_cvar_state=>27
}
If USE_DEBUG_COUNTER is enabled, debug counters will be included.
The contents of the hash are implementation specific and may be changed in the future.
This method is only expected to work on C Ruby.
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
# File 'vm.c', line 691 static VALUE vm_stat(int argc, VALUE *argv, VALUE self) { static VALUE sym_constant_cache_invalidations, sym_constant_cache_misses, sym_global_cvar_state, sym_next_shape_id; static VALUE sym_shape_cache_size; VALUE arg = Qnil; VALUE hash = Qnil, key = Qnil; if (rb_check_arity(argc, 0, 1) == 1) { arg = argv[0]; if (SYMBOL_P(arg)) key = arg; else if (RB_TYPE_P(arg, T_HASH)) hash = arg; else rb_raise(rb_eTypeError, "non-hash or symbol given"); } else { hash = rb_hash_new(); } #define S(s) sym_##s = ID2SYM(rb_intern_const(#s)) S(constant_cache_invalidations); S(constant_cache_misses); S(global_cvar_state); S(next_shape_id); S(shape_cache_size); #undef S #define SET(name, attr) if (key == sym_##name) return SERIALT2NUM(attr); else if (hash != Qnil) rb_hash_aset(hash, sym_##name, SERIALT2NUM(attr)); SET(constant_cache_invalidations, ruby_vm_constant_cache_invalidations); SET(constant_cache_misses, ruby_vm_constant_cache_misses); SET(global_cvar_state, ruby_vm_global_cvar_state); SET(next_shape_id, (rb_serial_t)GET_SHAPE_TREE()->next_shape_id); SET(shape_cache_size, (rb_serial_t)GET_SHAPE_TREE()->cache_size); #undef SET #if USE_DEBUG_COUNTER ruby_debug_counter_show_at_exit(FALSE); for (size_t i = 0; i < RB_DEBUG_COUNTER_MAX; i++) { const VALUE name = rb_sym_intern_ascii_cstr(rb_debug_counter_names[i]); const VALUE boxed_value = SIZET2NUM(rb_debug_counter[i]); if (key == name) { return boxed_value; } else if (hash != Qnil) { rb_hash_aset(hash, name, boxed_value); } } #endif if (!NIL_P(key)) { /* matched key should return above */ rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key)); } return hash; } |