* debug_counter.h: add the following counters.
  * frame_push: control frame counts (total counts).
  * frame_push_*: control frame counts per every frame type.
  * obj_*: add free'ed counts for each type.

* gc.c: ditto.

* vm_insnhelper.c (vm_push_frame): ditto.

* debug_counter.c (rb_debug_counter_show_results): widen counts field
  to show >10G numbers.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2018-09-28 01:10:43 +00:00
Родитель 0e3e0f8249
Коммит df5ec4107d
4 изменённых файлов: 111 добавлений и 5 удалений

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

@ -34,7 +34,7 @@ rb_debug_counter_show_results(const char *msg)
int i;
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%d %s\n", getpid(), msg);
for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%-30s\t%'12"PRIuSIZE"\n",
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%-30s\t%'14"PRIuSIZE"\n",
debug_counter_names[i],
rb_debug_counter[i]);
}

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

@ -37,6 +37,22 @@ RB_DEBUG_COUNTER(mc_cme_complement)
RB_DEBUG_COUNTER(mc_cme_complement_hit)
RB_DEBUG_COUNTER(mc_search_super)
/*
* control frame push counts.
*
* * frame_push: frame push counts.
*/
RB_DEBUG_COUNTER(frame_push)
RB_DEBUG_COUNTER(frame_push_method)
RB_DEBUG_COUNTER(frame_push_block)
RB_DEBUG_COUNTER(frame_push_class)
RB_DEBUG_COUNTER(frame_push_top)
RB_DEBUG_COUNTER(frame_push_cfunc)
RB_DEBUG_COUNTER(frame_push_ifunc)
RB_DEBUG_COUNTER(frame_push_eval)
RB_DEBUG_COUNTER(frame_push_rescue)
RB_DEBUG_COUNTER(frame_push_dummy)
/* instance variable counts
*
* * ivar_get_ic_hit/miss: ivar_get inline cache (ic) hit/miss counts (VM insn)
@ -84,13 +100,13 @@ RB_DEBUG_COUNTER(lvar_set_slowpath)
* * obj_promote: promoted counts (oldgen)
* * obj_wb_unprotect: wb unprotect counts
*
* * obj_[type]_[attr]: free'ed counts for each type.
* * obj_[type]_[attr]: *free'ed counts* for each type.
* Note that it is not a allocated counts.
* * [type]
* * _obj: T_OBJECT
* * _str: T_STRING
* * _ary: T_ARRAY
* * _hash: T_HASH
* * _struct: T_STRUCT
* * _xxx: T_XXX (hash, struct, ...)
*
* * [attr]
* * _ptr: R?? is not embed.
@ -103,6 +119,11 @@ RB_DEBUG_COUNTER(lvar_set_slowpath)
* * hash_under4: has under 4 entries
* * hash_ge4: has n entries (4<=n<8)
* * hash_ge8: has n entries (8<=n)
* * data_empty: T_DATA but no memory free.
* * data_xfree: free'ed by xfree().
* * data_imm_free: free'ed immediately.
* * data_zombie: free'ed with zombie.
* * imemo_*: T_IMEMO with each type.
*/
RB_DEBUG_COUNTER(obj_newobj)
RB_DEBUG_COUNTER(obj_newobj_slowpath)
@ -131,6 +152,35 @@ RB_DEBUG_COUNTER(obj_hash_ge8)
RB_DEBUG_COUNTER(obj_struct_ptr)
RB_DEBUG_COUNTER(obj_struct_embed)
RB_DEBUG_COUNTER(obj_regexp_ptr)
RB_DEBUG_COUNTER(obj_data_empty)
RB_DEBUG_COUNTER(obj_data_xfree)
RB_DEBUG_COUNTER(obj_data_imm_free)
RB_DEBUG_COUNTER(obj_data_zombie)
RB_DEBUG_COUNTER(obj_match_ptr)
RB_DEBUG_COUNTER(obj_file_ptr)
RB_DEBUG_COUNTER(obj_bignum_ptr)
RB_DEBUG_COUNTER(obj_symbol)
RB_DEBUG_COUNTER(obj_imemo_ment)
RB_DEBUG_COUNTER(obj_imemo_iseq)
RB_DEBUG_COUNTER(obj_imemo_env)
RB_DEBUG_COUNTER(obj_imemo_tmpbuf)
RB_DEBUG_COUNTER(obj_imemo_ast)
RB_DEBUG_COUNTER(obj_imemo_cref)
RB_DEBUG_COUNTER(obj_imemo_svar)
RB_DEBUG_COUNTER(obj_imemo_throw_data)
RB_DEBUG_COUNTER(obj_imemo_ifunc)
RB_DEBUG_COUNTER(obj_imemo_memo)
RB_DEBUG_COUNTER(obj_imemo_parser_strterm)
RB_DEBUG_COUNTER(obj_iclass_ptr)
RB_DEBUG_COUNTER(obj_class_ptr)
RB_DEBUG_COUNTER(obj_module_ptr)
/* heap function counts
*
* * heap_xmalloc/realloc/xfree: call counts

43
gc.c
Просмотреть файл

@ -2222,7 +2222,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
RB_DEBUG_COUNTER_INC(obj_obj_ptr);
}
else {
RB_DEBUG_COUNTER_INC(obj_obj_embed);
RB_DEBUG_COUNTER_INC(obj_obj_embed);
}
break;
case T_MODULE:
@ -2252,6 +2252,9 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
if (RANY(obj)->as.klass.ptr)
xfree(RANY(obj)->as.klass.ptr);
RANY(obj)->as.klass.ptr = NULL;
(void)RB_DEBUG_COUNTER_INC_IF(obj_module_ptr, BUILTIN_TYPE(obj) == T_MODULE);
(void)RB_DEBUG_COUNTER_INC_IF(obj_class_ptr, BUILTIN_TYPE(obj) == T_CLASS);
break;
case T_STRING:
rb_str_free(obj);
@ -2281,6 +2284,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
case T_REGEXP:
if (RANY(obj)->as.regexp.ptr) {
onig_free(RANY(obj)->as.regexp.ptr);
RB_DEBUG_COUNTER_INC(obj_regexp_ptr);
}
break;
case T_DATA:
@ -2304,15 +2308,21 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
if (dfree) {
if (dfree == RUBY_DEFAULT_FREE) {
xfree(data);
RB_DEBUG_COUNTER_INC(obj_data_xfree);
}
else if (free_immediately) {
(*dfree)(data);
RB_DEBUG_COUNTER_INC(obj_data_imm_free);
}
else {
make_zombie(objspace, obj, dfree, data);
RB_DEBUG_COUNTER_INC(obj_data_zombie);
return 1;
}
}
else {
RB_DEBUG_COUNTER_INC(obj_data_empty);
}
}
break;
case T_MATCH:
@ -2322,11 +2332,14 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
if (rm->char_offset)
xfree(rm->char_offset);
xfree(rm);
RB_DEBUG_COUNTER_INC(obj_match_ptr);
}
break;
case T_FILE:
if (RANY(obj)->as.file.fptr) {
make_io_zombie(objspace, obj);
RB_DEBUG_COUNTER_INC(obj_file_ptr);
return 1;
}
break;
@ -2349,6 +2362,8 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
rb_class_remove_from_super_subclasses(obj);
xfree(RANY(obj)->as.klass.ptr);
RANY(obj)->as.klass.ptr = NULL;
RB_DEBUG_COUNTER_INC(obj_iclass_ptr);
break;
case T_FLOAT:
@ -2357,6 +2372,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
case T_BIGNUM:
if (!(RBASIC(obj)->flags & BIGNUM_EMBED_FLAG) && BIGNUM_DIGITS(obj)) {
xfree(BIGNUM_DIGITS(obj));
RB_DEBUG_COUNTER_INC(obj_bignum_ptr);
}
break;
@ -2378,6 +2394,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
case T_SYMBOL:
{
rb_gc_free_dsymbol(obj);
RB_DEBUG_COUNTER_INC(obj_symbol);
}
break;
@ -2385,21 +2402,45 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
switch (imemo_type(obj)) {
case imemo_ment:
rb_free_method_entry(&RANY(obj)->as.imemo.ment);
RB_DEBUG_COUNTER_INC(obj_imemo_ment);
break;
case imemo_iseq:
rb_iseq_free(&RANY(obj)->as.imemo.iseq);
RB_DEBUG_COUNTER_INC(obj_imemo_iseq);
break;
case imemo_env:
GC_ASSERT(VM_ENV_ESCAPED_P(RANY(obj)->as.imemo.env.ep));
xfree((VALUE *)RANY(obj)->as.imemo.env.env);
RB_DEBUG_COUNTER_INC(obj_imemo_env);
break;
case imemo_tmpbuf:
xfree(RANY(obj)->as.imemo.alloc.ptr);
RB_DEBUG_COUNTER_INC(obj_imemo_tmpbuf);
break;
case imemo_ast:
rb_ast_free(&RANY(obj)->as.imemo.ast);
RB_DEBUG_COUNTER_INC(obj_imemo_ast);
break;
case imemo_cref:
RB_DEBUG_COUNTER_INC(obj_imemo_cref);
break;
case imemo_svar:
RB_DEBUG_COUNTER_INC(obj_imemo_svar);
break;
case imemo_throw_data:
RB_DEBUG_COUNTER_INC(obj_imemo_throw_data);
break;
case imemo_ifunc:
RB_DEBUG_COUNTER_INC(obj_imemo_ifunc);
break;
case imemo_memo:
RB_DEBUG_COUNTER_INC(obj_imemo_memo);
break;
case imemo_parser_strterm:
RB_DEBUG_COUNTER_INC(obj_imemo_parser_strterm);
break;
default:
/* unreachable */
break;
}
return 0;

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

@ -214,6 +214,21 @@ vm_push_frame(rb_execution_context_t *ec,
rb_control_frame_t *const cfp = ec->cfp - 1;
int i;
#if USE_DEBUG_COUNTER
RB_DEBUG_COUNTER_INC(frame_push);
switch (type & VM_FRAME_MAGIC_MASK) {
case VM_FRAME_MAGIC_METHOD: RB_DEBUG_COUNTER_INC(frame_push_method); break;
case VM_FRAME_MAGIC_BLOCK: RB_DEBUG_COUNTER_INC(frame_push_block); break;
case VM_FRAME_MAGIC_CLASS: RB_DEBUG_COUNTER_INC(frame_push_class); break;
case VM_FRAME_MAGIC_TOP: RB_DEBUG_COUNTER_INC(frame_push_top); break;
case VM_FRAME_MAGIC_CFUNC: RB_DEBUG_COUNTER_INC(frame_push_cfunc); break;
case VM_FRAME_MAGIC_IFUNC: RB_DEBUG_COUNTER_INC(frame_push_ifunc); break;
case VM_FRAME_MAGIC_EVAL: RB_DEBUG_COUNTER_INC(frame_push_eval); break;
case VM_FRAME_MAGIC_RESCUE: RB_DEBUG_COUNTER_INC(frame_push_rescue); break;
case VM_FRAME_MAGIC_DUMMY: RB_DEBUG_COUNTER_INC(frame_push_dummy); break;
default: rb_bug("unreachable");
}
#endif
vm_check_frame(type, specval, cref_or_me, iseq);
VM_ASSERT(local_size >= 0);