add several counters to analyze ivar inline caches.

* debug_counter.h: add (and renamed) several counters:
  ivar_get_ic_hit
  ivar_get_ic_miss
  ivar_get_ic_miss_serial
  ivar_get_ic_miss_unset
  ivar_get_ic_miss_noobject
  ivar_set_ic_hit
  ivar_set_ic_miss
  ivar_set_ic_miss_serial
  ivar_set_ic_miss_unset
  ivar_set_ic_miss_oorange
  ivar_set_ic_miss_noobject
  ivar_get_base
  ivar_set_base

  See related source code to know what counters mean.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-03-15 08:25:58 +00:00
Родитель 0b1f6aed94
Коммит 10b800133e
3 изменённых файлов: 33 добавлений и 17 удалений

Просмотреть файл

@ -22,12 +22,19 @@ RB_DEBUG_COUNTER(mc_class_serial_miss)
RB_DEBUG_COUNTER(mc_cme_complement)
RB_DEBUG_COUNTER(mc_cme_complement_hit)
RB_DEBUG_COUNTER(mc_search_super)
RB_DEBUG_COUNTER(ivar_get_hit)
RB_DEBUG_COUNTER(ivar_get_miss)
RB_DEBUG_COUNTER(ivar_set_hit)
RB_DEBUG_COUNTER(ivar_set_miss)
RB_DEBUG_COUNTER(ivar_get)
RB_DEBUG_COUNTER(ivar_set)
RB_DEBUG_COUNTER(ivar_get_ic_hit)
RB_DEBUG_COUNTER(ivar_get_ic_miss)
RB_DEBUG_COUNTER(ivar_get_ic_miss_serial)
RB_DEBUG_COUNTER(ivar_get_ic_miss_unset)
RB_DEBUG_COUNTER(ivar_get_ic_miss_noobject)
RB_DEBUG_COUNTER(ivar_set_ic_hit)
RB_DEBUG_COUNTER(ivar_set_ic_miss)
RB_DEBUG_COUNTER(ivar_set_ic_miss_serial)
RB_DEBUG_COUNTER(ivar_set_ic_miss_unset)
RB_DEBUG_COUNTER(ivar_set_ic_miss_oorange)
RB_DEBUG_COUNTER(ivar_set_ic_miss_noobject)
RB_DEBUG_COUNTER(ivar_get_base)
RB_DEBUG_COUNTER(ivar_set_base)
#endif
#ifndef RUBY_DEBUG_COUNTER_H

Просмотреть файл

@ -1210,7 +1210,7 @@ VALUE
rb_ivar_get(VALUE obj, ID id)
{
VALUE iv = rb_ivar_lookup(obj, id, Qundef);
RB_DEBUG_COUNTER_INC(ivar_get);
RB_DEBUG_COUNTER_INC(ivar_get_base);
if (iv == Qundef) {
if (RTEST(ruby_verbose))
@ -1317,7 +1317,7 @@ rb_ivar_set(VALUE obj, ID id, VALUE val)
struct ivar_update ivup;
uint32_t i, len;
RB_DEBUG_COUNTER_INC(ivar_set);
RB_DEBUG_COUNTER_INC(ivar_set_base);
rb_check_frozen(obj);

Просмотреть файл

@ -884,7 +884,10 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr)
#if USE_IC_FOR_IVAR
if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) {
VALUE val = Qundef;
if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass))) {
if (LIKELY(is_attr ?
RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_unset, cc->aux.index > 0) :
RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_serial,
ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass)))) {
st_index_t index = !is_attr ? ic->ic_value.index : (cc->aux.index - 1);
if (LIKELY(index < ROBJECT_NUMIV(obj))) {
val = ROBJECT_IVPTR(obj)[index];
@ -892,10 +895,10 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr)
undef_check:
if (UNLIKELY(val == Qundef)) {
if (!is_attr && RTEST(ruby_verbose))
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
val = Qnil;
}
RB_DEBUG_COUNTER_INC(ivar_get_hit);
RB_DEBUG_COUNTER_INC(ivar_get_ic_hit);
return val;
}
else {
@ -919,8 +922,11 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr)
goto undef_check;
}
}
else {
RB_DEBUG_COUNTER_INC(ivar_get_ic_miss_noobject);
}
#endif /* USE_IC_FOR_IVAR */
RB_DEBUG_COUNTER_INC(ivar_get_miss);
RB_DEBUG_COUNTER_INC(ivar_get_ic_miss);
if (is_attr)
return rb_attr_get(obj, id);
@ -938,14 +944,14 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_
st_data_t index;
if (LIKELY(
(!is_attr && ic->ic_serial == RCLASS_SERIAL(klass)) ||
(is_attr && cc->aux.index > 0))) {
(!is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_serial, ic->ic_serial == RCLASS_SERIAL(klass))) ||
( is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_unset, cc->aux.index > 0)))) {
VALUE *ptr = ROBJECT_IVPTR(obj);
index = !is_attr ? ic->ic_value.index : cc->aux.index-1;
if (index < ROBJECT_NUMIV(obj)) {
if (RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_oorange, index < ROBJECT_NUMIV(obj))) {
RB_OBJ_WRITE(obj, &ptr[index], val);
RB_DEBUG_COUNTER_INC(ivar_set_hit);
RB_DEBUG_COUNTER_INC(ivar_set_ic_hit);
return val; /* inline cache hit */
}
}
@ -967,8 +973,11 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_
/* fall through */
}
}
else {
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss_noobject);
}
#endif /* USE_IC_FOR_IVAR */
RB_DEBUG_COUNTER_INC(ivar_set_miss);
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss);
return rb_ivar_set(obj, id, val);
}