count_nodes(*args)
public
Counts nodes for each node type.
This method is only for MRI developers interested in performance and memory
usage of Ruby programs.
It returns a hash as:
{:NODE_METHOD=>2027, :NODE_FBODY=>1927, :NODE_CFUNC=>1798, ...}
If the optional argument, result_hash, is given, it is overwritten and
returned. This is intended to avoid probe effect.
Note: The contents of the returned hash is implementation defined. It may
be changed in future.
This method is only expected to work with C Ruby.
Show source
static VALUE
count_nodes(int argc, VALUE *argv, VALUE os)
{
size_t nodes[NODE_LAST+1];
size_t i;
VALUE hash = setup_hash(argc, argv);
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) {
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_OP_CDECL);
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_KW_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_DSYM);
COUNT_NODE(NODE_ATTRASGN);
COUNT_NODE(NODE_PRELUDE);
COUNT_NODE(NODE_LAMBDA);
default: node = INT2FIX(i);
}
rb_hash_aset(hash, node, SIZET2NUM(nodes[i]));
}
}
return hash;
}