Class | RubyProf::MethodInfo |
In: |
ext/ruby_prof.c
|
Parent: | Object |
The RubyProf::MethodInfo class stores profiling data for a method. One instance of the RubyProf::MethodInfo class is created per method called per thread. Thus, if a method is called in two different thread then there will be two RubyProf::MethodInfo objects created. RubyProf::MethodInfo objects can be accessed via the RubyProf::Result object.
Returns the number of times this method was called.
/* call-seq: called -> int Returns the number of times this method was called. */ static VALUE prof_method_called(VALUE self) { prof_method_t *result = get_prof_method(self); return INT2NUM(result->called); }
Returns a hash table that lists all the methods that this method called (ie, children). The hash table is keyed on method name and contains references to RubyProf::CallInfo objects.
/* call-seq: children -> hash Returns a hash table that lists all the methods that this method called (ie, children). The hash table is keyed on method name and contains references to RubyProf::CallInfo objects.*/ static VALUE prof_method_children(VALUE self) { /* Returns a hash table, keyed on method name, of call info objects for all methods that this method calls (children). */ VALUE children = rb_hash_new(); prof_method_t *result = get_prof_method(self); st_foreach(result->children, prof_method_collect_children, children); return children; }
Returns the total amount of time spent in this method’s children.
/* call-seq: children_time -> float Returns the total amount of time spent in this method's children. */ static VALUE prof_method_children_time(VALUE self) { prof_method_t *result = get_prof_method(self); prof_clock_t children_time = result->total_time - result->self_time; return rb_float_new(clock2sec(children_time)); }
Returns the Ruby klass that owns this method.
/* call-seq: method_class -> klass Returns the Ruby klass that owns this method. */ static VALUE prof_method_class(VALUE self) { prof_method_t *result = get_prof_method(self); return result->klass; }
Returns the id of this method.
/* call-seq: method_id -> ID Returns the id of this method. */ static VALUE prof_method_id(VALUE self) { prof_method_t *result = get_prof_method(self); return ID2SYM(result->mid); }
Returns the name of this object. The name may be in the form:
Object#method Module.method .method
/* call-seq: method_name -> string Returns the name of this object. The name may be in the form: Object#method Module.method .method */ static VALUE prof_method_name(VALUE self) { prof_method_t *method = get_prof_method(self); return method_name(method->klass, method->mid); }
Returns a hash table that lists all the methods that called this method (ie, parents). The hash table is keyed on method name and contains references to RubyProf::MethodInfo objects.
/* call-seq: parents -> hash Returns a hash table that lists all the methods that called this method (ie, parents). The hash table is keyed on method name and contains references to RubyProf::MethodInfo objects.*/ static VALUE prof_method_parents(VALUE self) { VALUE result = rb_hash_new(); VALUE parents = rb_ary_new(); int len = 0; int i = 0; /* Get the list of parents */ prof_method_t *child = get_prof_method(self); st_foreach(child->parents, prof_method_collect_parents, parents); /* Iterate over each parent */ len = RARRAY(parents)->len; for(i = 0; i<len; i++) { prof_call_info_t *call_info; /* First get the parent */ VALUE item = rb_ary_entry(parents, i); prof_method_t *parent = (prof_method_t *)(FIX2INT(item)); /* Now get the call info */ call_info = child_table_lookup(parent->children, child->key); if (call_info == NULL) { /* Should never happen */ rb_raise(rb_eRuntimeError, "Could not find parent call info object for %s", method_name(child->klass, child->mid)); } /* Create a new Ruby CallInfo object and store it into the hash keyed on the parent's name. We use the parent's name because we want to see that printed out for parent records in a call graph. */ rb_hash_aset(result, method_name(parent->klass, parent->mid), call_info_new(call_info)); } return result; }
Returns the total amount of time spent in this method.
/* call-seq: self_time -> float Returns the total amount of time spent in this method. */ static VALUE prof_method_self_time(VALUE self) { prof_method_t *result = get_prof_method(self); return rb_float_new(clock2sec(result->self_time)); }
Returns the id of the thread that executed this method.
/* call-seq: thread_id -> id Returns the id of the thread that executed this method.*/ static VALUE prof_thread_id(VALUE self) { prof_method_t *result = get_prof_method(self); return INT2FIX(result->thread_id); }
Returns the total amount of time spent in this method and its children.
/* call-seq: total_time -> float Returns the total amount of time spent in this method and its children. */ static VALUE prof_method_total_time(VALUE self) { prof_method_t *result = get_prof_method(self); return rb_float_new(clock2sec(result->total_time)); }