static VALUE count_tdata_objects(int argc, VALUE *argv, VALUE self) { VALUE hash = setup_hash(argc, argv); rb_objspace_each_objects(cto_i, (void *)hash); return hash; }
static VALUE count_objects_size(int argc, VALUE *argv, VALUE os) { size_t counts[T_MASK+1]; size_t total = 0; enum ruby_value_type i; VALUE hash = setup_hash(argc, argv); for (i = 0; i <= T_MASK; i++) { counts[i] = 0; } rb_objspace_each_objects(cos_i, &counts[0]); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } for (i = 0; i <= T_MASK; i++) { if (counts[i]) { VALUE type = type2sym(i); total += counts[i]; rb_hash_aset(hash, type, SIZET2NUM(counts[i])); } } rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total)); return hash; }
static VALUE memsize_of_all_m(int argc, VALUE *argv, VALUE self) { struct total_data data = {0, 0}; if (argc > 0) { rb_scan_args(argc, argv, "01", &data.klass); } rb_objspace_each_objects(total_i, &data); return SIZET2NUM(data.total); }
static VALUE count_imemo_objects(int argc, VALUE *argv, VALUE self) { VALUE hash = setup_hash(argc, argv); if (imemo_type_ids[0] == 0) { imemo_type_ids[0] = rb_intern("imemo_none"); imemo_type_ids[1] = rb_intern("imemo_cref"); imemo_type_ids[2] = rb_intern("imemo_svar"); imemo_type_ids[3] = rb_intern("imemo_throw_data"); imemo_type_ids[4] = rb_intern("imemo_ifunc"); imemo_type_ids[5] = rb_intern("imemo_memo"); imemo_type_ids[6] = rb_intern("imemo_ment"); imemo_type_ids[7] = rb_intern("imemo_iseq"); } rb_objspace_each_objects(count_imemo_objects_i, (void *)hash); return hash; }
static VALUE count_tdata_objects(int argc, VALUE *argv, VALUE self) { VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (TYPE(hash) != T_HASH) rb_raise(rb_eTypeError, "non-hash given"); } if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } rb_objspace_each_objects(cto_i, (void *)hash); return hash; }
static VALUE count_symbols(int argc, VALUE *argv, VALUE os) { struct dynamic_symbol_counts dynamic_counts = {0, 0}; VALUE hash = setup_hash(argc, argv); size_t immortal_symbols = rb_sym_immortal_count(); rb_objspace_each_objects(cs_i, &dynamic_counts); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } rb_hash_aset(hash, ID2SYM(rb_intern("mortal_dynamic_symbol")), SIZET2NUM(dynamic_counts.mortal)); rb_hash_aset(hash, ID2SYM(rb_intern("immortal_dynamic_symbol")), SIZET2NUM(dynamic_counts.immortal)); rb_hash_aset(hash, ID2SYM(rb_intern("immortal_static_symbol")), SIZET2NUM(immortal_symbols - dynamic_counts.immortal)); rb_hash_aset(hash, ID2SYM(rb_intern("immortal_symbol")), SIZET2NUM(immortal_symbols)); return hash; }
static VALUE count_objects_size(int argc, VALUE *argv, VALUE os) { size_t counts[T_MASK+1]; size_t total = 0; enum ruby_value_type i; VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (!RB_TYPE_P(hash, T_HASH)) rb_raise(rb_eTypeError, "non-hash given"); } for (i = 0; i <= T_MASK; i++) { counts[i] = 0; } rb_objspace_each_objects(cos_i, &counts[0]); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } for (i = 0; i <= T_MASK; i++) { if (counts[i]) { VALUE type = type2sym(i); total += counts[i]; rb_hash_aset(hash, type, SIZET2NUM(counts[i])); } } rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total)); return hash; }
static VALUE count_nodes(int argc, VALUE *argv, VALUE os) { size_t nodes[NODE_LAST+1]; size_t i; VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (TYPE(hash) != T_HASH) rb_raise(rb_eTypeError, "non-hash given"); } for (i = 0; i <= NODE_LAST; i++) { nodes[i] = 0; } rb_objspace_each_objects(cn_i, &nodes[0]); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } for (i=0; i<NODE_LAST; i++) { if (nodes[i] != 0) { VALUE node; switch (i) { #define COUNT_NODE(n) case n: node = ID2SYM(rb_intern(#n)); break; COUNT_NODE(NODE_SCOPE); COUNT_NODE(NODE_BLOCK); COUNT_NODE(NODE_IF); COUNT_NODE(NODE_CASE); COUNT_NODE(NODE_WHEN); COUNT_NODE(NODE_OPT_N); COUNT_NODE(NODE_WHILE); COUNT_NODE(NODE_UNTIL); COUNT_NODE(NODE_ITER); COUNT_NODE(NODE_FOR); COUNT_NODE(NODE_BREAK); COUNT_NODE(NODE_NEXT); COUNT_NODE(NODE_REDO); COUNT_NODE(NODE_RETRY); COUNT_NODE(NODE_BEGIN); COUNT_NODE(NODE_RESCUE); COUNT_NODE(NODE_RESBODY); COUNT_NODE(NODE_ENSURE); COUNT_NODE(NODE_AND); COUNT_NODE(NODE_OR); COUNT_NODE(NODE_MASGN); COUNT_NODE(NODE_LASGN); COUNT_NODE(NODE_DASGN); COUNT_NODE(NODE_DASGN_CURR); COUNT_NODE(NODE_GASGN); COUNT_NODE(NODE_IASGN); COUNT_NODE(NODE_IASGN2); COUNT_NODE(NODE_CDECL); COUNT_NODE(NODE_CVASGN); COUNT_NODE(NODE_CVDECL); COUNT_NODE(NODE_OP_ASGN1); COUNT_NODE(NODE_OP_ASGN2); COUNT_NODE(NODE_OP_ASGN_AND); COUNT_NODE(NODE_OP_ASGN_OR); COUNT_NODE(NODE_CALL); COUNT_NODE(NODE_FCALL); COUNT_NODE(NODE_VCALL); COUNT_NODE(NODE_SUPER); COUNT_NODE(NODE_ZSUPER); COUNT_NODE(NODE_ARRAY); COUNT_NODE(NODE_ZARRAY); COUNT_NODE(NODE_VALUES); COUNT_NODE(NODE_HASH); COUNT_NODE(NODE_RETURN); COUNT_NODE(NODE_YIELD); COUNT_NODE(NODE_LVAR); COUNT_NODE(NODE_DVAR); COUNT_NODE(NODE_GVAR); COUNT_NODE(NODE_IVAR); COUNT_NODE(NODE_CONST); COUNT_NODE(NODE_CVAR); COUNT_NODE(NODE_NTH_REF); COUNT_NODE(NODE_BACK_REF); COUNT_NODE(NODE_MATCH); COUNT_NODE(NODE_MATCH2); COUNT_NODE(NODE_MATCH3); COUNT_NODE(NODE_LIT); COUNT_NODE(NODE_STR); COUNT_NODE(NODE_DSTR); COUNT_NODE(NODE_XSTR); COUNT_NODE(NODE_DXSTR); COUNT_NODE(NODE_EVSTR); COUNT_NODE(NODE_DREGX); COUNT_NODE(NODE_DREGX_ONCE); COUNT_NODE(NODE_ARGS); COUNT_NODE(NODE_ARGS_AUX); COUNT_NODE(NODE_OPT_ARG); COUNT_NODE(NODE_POSTARG); COUNT_NODE(NODE_ARGSCAT); COUNT_NODE(NODE_ARGSPUSH); COUNT_NODE(NODE_SPLAT); COUNT_NODE(NODE_TO_ARY); COUNT_NODE(NODE_BLOCK_ARG); COUNT_NODE(NODE_BLOCK_PASS); COUNT_NODE(NODE_DEFN); COUNT_NODE(NODE_DEFS); COUNT_NODE(NODE_ALIAS); COUNT_NODE(NODE_VALIAS); COUNT_NODE(NODE_UNDEF); COUNT_NODE(NODE_CLASS); COUNT_NODE(NODE_MODULE); COUNT_NODE(NODE_SCLASS); COUNT_NODE(NODE_COLON2); COUNT_NODE(NODE_COLON3); COUNT_NODE(NODE_DOT2); COUNT_NODE(NODE_DOT3); COUNT_NODE(NODE_FLIP2); COUNT_NODE(NODE_FLIP3); COUNT_NODE(NODE_SELF); COUNT_NODE(NODE_NIL); COUNT_NODE(NODE_TRUE); COUNT_NODE(NODE_FALSE); COUNT_NODE(NODE_ERRINFO); COUNT_NODE(NODE_DEFINED); COUNT_NODE(NODE_POSTEXE); COUNT_NODE(NODE_ALLOCA); COUNT_NODE(NODE_BMETHOD); COUNT_NODE(NODE_MEMO); COUNT_NODE(NODE_IFUNC); COUNT_NODE(NODE_DSYM); COUNT_NODE(NODE_ATTRASGN); COUNT_NODE(NODE_PRELUDE); COUNT_NODE(NODE_LAMBDA); COUNT_NODE(NODE_OPTBLOCK); #undef COUNT_NODE default: node = INT2FIX(nodes[i]); } rb_hash_aset(hash, node, SIZET2NUM(nodes[i])); } } return hash; }
static VALUE count_objects_size(int argc, VALUE *argv, VALUE os) { size_t counts[T_MASK+1]; size_t total = 0; size_t i; VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (TYPE(hash) != T_HASH) rb_raise(rb_eTypeError, "non-hash given"); } for (i = 0; i <= T_MASK; i++) { counts[i] = 0; } rb_objspace_each_objects(cos_i, &counts[0]); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } for (i = 0; i <= T_MASK; i++) { if (counts[i]) { VALUE type; switch (i) { #define COUNT_TYPE(t) case t: type = ID2SYM(rb_intern(#t)); break; COUNT_TYPE(T_NONE); COUNT_TYPE(T_OBJECT); COUNT_TYPE(T_CLASS); COUNT_TYPE(T_MODULE); COUNT_TYPE(T_FLOAT); COUNT_TYPE(T_STRING); COUNT_TYPE(T_REGEXP); COUNT_TYPE(T_ARRAY); COUNT_TYPE(T_HASH); COUNT_TYPE(T_STRUCT); COUNT_TYPE(T_BIGNUM); COUNT_TYPE(T_FILE); COUNT_TYPE(T_DATA); COUNT_TYPE(T_MATCH); COUNT_TYPE(T_COMPLEX); COUNT_TYPE(T_RATIONAL); COUNT_TYPE(T_NIL); COUNT_TYPE(T_TRUE); COUNT_TYPE(T_FALSE); COUNT_TYPE(T_SYMBOL); COUNT_TYPE(T_FIXNUM); COUNT_TYPE(T_UNDEF); COUNT_TYPE(T_NODE); COUNT_TYPE(T_ICLASS); COUNT_TYPE(T_ZOMBIE); #undef COUNT_TYPE default: type = INT2NUM(i); break; } total += counts[i]; rb_hash_aset(hash, type, SIZET2NUM(counts[i])); } } rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total)); return hash; }