diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-21 08:18:15 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-21 08:18:15 +0000 |
commit | 76c4cca19c0c27b1c3ca6f597384707cccf3de06 (patch) | |
tree | bcb13fed3f68e50cbca8a4bd475157d9bfeb7dca /vm_insnhelper.c | |
parent | 51de3aa2b27859305c74d5664724192602c4608f (diff) | |
download | ruby-76c4cca19c0c27b1c3ca6f597384707cccf3de06.tar.gz |
add performance counting mechanism for MRI debug/tuning purpose.
* How to enable this feature?
* define USE_DEBUG_COUNTER as 1.
* you can disable to output the result with
RUBY_DEBUG_COUNTER_DISABLE environment variable
even if USE_DEBUG_COUNTER == 1.
* How to add new counter?
* add COUNTER(<name>) line on debug_counter.h.
* include "debug_counter.h"
* insert RB_DEBUG_COUNTER_INC(<name>) line on your favorite place.
* counter output example:
[RUBY_DEBUG_COUNTER] mc_inline_hit 999
[RUBY_DEBUG_COUNTER] mc_inline_miss 3
[RUBY_DEBUG_COUNTER] mc_global_hit 23
[RUBY_DEBUG_COUNTER] mc_global_miss 273
[RUBY_DEBUG_COUNTER] mc_global_state_miss 3
[RUBY_DEBUG_COUNTER] mc_class_serial_miss 0
[RUBY_DEBUG_COUNTER] mc_cme_complement 0
[RUBY_DEBUG_COUNTER] mc_cme_complement_hit 0
[RUBY_DEBUG_COUNTER] mc_search_super 1384
[RUBY_DEBUG_COUNTER] ivar_get_hit 0
[RUBY_DEBUG_COUNTER] ivar_get_miss 0
[RUBY_DEBUG_COUNTER] ivar_set_hit 0
[RUBY_DEBUG_COUNTER] ivar_set_miss 0
[RUBY_DEBUG_COUNTER] ivar_get 431
[RUBY_DEBUG_COUNTER] ivar_set 465
* mc_... is related to method caching.
* ivar_... is related to instance variable accesses.
* compare with dtrace/system tap features, there are completely
no performacne penalties when it is disabled.
* This feature is supported only on __GNUC__ compilers.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 48a63d0089..9e8ea9c9a8 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -16,6 +16,7 @@ #include "probes.h" #include "probes_helper.h" #include "ruby/config.h" +#include "debug_counter.h" /* control stack frame */ @@ -894,6 +895,7 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); val = Qnil; } + RB_DEBUG_COUNTER_INC(ivar_get_hit); return val; } else { @@ -918,6 +920,8 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) } } #endif /* USE_IC_FOR_IVAR */ + RB_DEBUG_COUNTER_INC(ivar_get_miss); + if (is_attr) return rb_attr_get(obj, id); return rb_ivar_get(obj, id); @@ -941,6 +945,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_ if (index < ROBJECT_NUMIV(obj)) { RB_OBJ_WRITE(obj, &ptr[index], val); + RB_DEBUG_COUNTER_INC(ivar_set_hit); return val; /* inline cache hit */ } } @@ -963,6 +968,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_ } } #endif /* USE_IC_FOR_IVAR */ + RB_DEBUG_COUNTER_INC(ivar_set_miss); return rb_ivar_set(obj, id, val); } @@ -1220,13 +1226,17 @@ vm_search_method(const struct rb_call_info *ci, struct rb_call_cache *cc, VALUE VALUE klass = CLASS_OF(recv); #if OPT_INLINE_METHOD_CACHE - if (LIKELY(GET_GLOBAL_METHOD_STATE() == cc->method_state && RCLASS_SERIAL(klass) == cc->class_serial)) { + if (LIKELY(RB_DEBUG_COUNTER_INC_UNLESS(mc_global_state_miss, + GET_GLOBAL_METHOD_STATE() == cc->method_state) && + RB_DEBUG_COUNTER_INC_UNLESS(mc_class_serial_miss, + RCLASS_SERIAL(klass) == cc->class_serial))) { /* cache hit! */ VM_ASSERT(cc->call != NULL); + RB_DEBUG_COUNTER_INC(mc_inline_hit); return; } + RB_DEBUG_COUNTER_INC(mc_inline_miss); #endif - cc->me = rb_callable_method_entry(klass, ci->mid); VM_ASSERT(callable_method_entry_p(cc->me)); cc->call = vm_call_general; |