Class: RubyProf::MethodInfo
- Inherits:
-
Object
- Object
- RubyProf::MethodInfo
- Includes:
- Comparable
- Defined in:
- ext/ruby_prof.c,
ext/ruby_prof.c
Overview
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.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:nodoc:.
-
#called ⇒ Integer
Returns the number of times this method was called.
-
#children ⇒ Hash
Returns a hash table that lists all the methods that this method called (ie, children).
-
#children_time ⇒ Float
Returns the total amount of time spent in this method’s children.
-
#method_class ⇒ Object
Returns the Ruby klass that owns this method.
-
#method_id ⇒ Object
Returns the id of this method.
-
#method_name ⇒ String
Returns the name of this object.
-
#parents ⇒ Hash
Returns a hash table that lists all the methods that called this method (ie, parents).
-
#self_time ⇒ Float
Returns the total amount of time spent in this method.
-
#thread_id ⇒ Object
Returns the id of the thread that executed this method.
-
#total_time ⇒ Float
Returns the total amount of time spent in this method and its children.
Instance Method Details
#<=>(other) ⇒ Object
:nodoc:
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 |
# File 'ext/ruby_prof.c', line 838 static VALUE prof_method_cmp(VALUE self, VALUE other) { /* For call graphs we want to sort methods by their total time, not self time. */ prof_method_t *x = get_prof_method(self); prof_method_t *y = get_prof_method(other); /* Want toplevel to always be first */ if (x->klass == Qnil && x->mid == toplevel_id) return INT2FIX(1); else if (y->klass == Qnil && y->mid == toplevel_id) return INT2FIX(-11); else if (x->total_time < y->total_time) return INT2FIX(-1); else if (x->total_time == y->total_time) return INT2FIX(0); else return INT2FIX(1); } |
#called ⇒ Integer
Returns the number of times this method was called.
648 649 650 651 652 653 654 |
# File 'ext/ruby_prof.c', line 648 static VALUE prof_method_called(VALUE self) { prof_method_t *result = get_prof_method(self); return INT2NUM(result->called); } |
#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.
825 826 827 828 829 830 831 832 833 834 835 |
# File 'ext/ruby_prof.c', line 825 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; } |
#children_time ⇒ Float
Returns the total amount of time spent in this method’s children.
685 686 687 688 689 690 691 |
# File 'ext/ruby_prof.c', line 685 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)); } |
#method_class ⇒ Object
Returns the Ruby klass that owns this method.
709 710 711 712 713 714 715 |
# File 'ext/ruby_prof.c', line 709 static VALUE prof_method_class(VALUE self) { prof_method_t *result = get_prof_method(self); return result->klass; } |
#method_id ⇒ Object
Returns the id of this method.
721 722 723 724 725 726 727 |
# File 'ext/ruby_prof.c', line 721 static VALUE prof_method_id(VALUE self) { prof_method_t *result = get_prof_method(self); return ID2SYM(result->mid); } |
#method_name ⇒ String
Returns the name of this object. The name may be in the form:
Object#method
Module.method
.method
736 737 738 739 740 741 |
# File 'ext/ruby_prof.c', line 736 static VALUE prof_method_name(VALUE self) { prof_method_t *method = get_prof_method(self); return method_name(method->klass, method->mid); } |
#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.
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
# File 'ext/ruby_prof.c', line 759 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; } |
#self_time ⇒ Float
Returns the total amount of time spent in this method.
673 674 675 676 677 678 679 |
# File 'ext/ruby_prof.c', line 673 static VALUE prof_method_self_time(VALUE self) { prof_method_t *result = get_prof_method(self); return rb_float_new(clock2sec(result->self_time)); } |
#thread_id ⇒ Object
Returns the id of the thread that executed this method.
697 698 699 700 701 702 703 |
# File 'ext/ruby_prof.c', line 697 static VALUE prof_thread_id(VALUE self) { prof_method_t *result = get_prof_method(self); return INT2FIX(result->thread_id); } |
#total_time ⇒ Float
Returns the total amount of time spent in this method and its children.
661 662 663 664 665 666 667 |
# File 'ext/ruby_prof.c', line 661 static VALUE prof_method_total_time(VALUE self) { prof_method_t *result = get_prof_method(self); return rb_float_new(clock2sec(result->total_time)); } |