Class: RubyProf::MethodInfo
- Inherits:
-
Object
- Object
- RubyProf::MethodInfo
- Includes:
- Comparable
- Defined in:
- ext/ruby_prof/ruby_prof.c,
lib/ruby-prof/method_info.rb,
ext/ruby_prof/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
- #aggregate_children ⇒ Object
- #aggregate_parents ⇒ Object
-
#call_infos ⇒ Array of call_info
Returns an array of call info objects that contain profiling information about the current method.
- #called ⇒ Object
- #children ⇒ Object
- #children_time ⇒ Object
-
#full_name ⇒ String
Returns the full name of this method in the format Object#method.
-
#method_class ⇒ Object
Returns the Ruby klass that owns this method.
-
#klass_name ⇒ String
Returns the name of this method’s class.
-
#line_no ⇒ Integer
returns the line number of the method.
-
#method_id ⇒ Object
Returns the id of this method.
- #method_name() ⇒ Object
- #min_depth ⇒ Object
- #root? ⇒ Boolean
- #self_time ⇒ Object
-
#source_file ⇒ String
return the source file of the method.
- #to_s ⇒ Object
- #total_time ⇒ Object
- #wait_time ⇒ Object
Instance Method Details
#<=>(other) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby-prof/method_info.rb', line 5 def <=>(other) if self.total_time < other.total_time -1 elsif self.total_time > other.total_time 1 elsif self.min_depth < other.min_depth 1 elsif self.min_depth > other.min_depth -1 else -1 * (self.full_name <=> other.full_name) end end |
#aggregate_children ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby-prof/method_info.rb', line 94 def aggregate_children # Group call info's based on their targets groups = self.children.inject(Hash.new) do |hash, call_info| key = call_info.target (hash[key] ||= []) << call_info hash end groups.map do |key, value| AggregateCallInfo.new(value) end end |
#aggregate_parents ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruby-prof/method_info.rb', line 81 def aggregate_parents # Group call info's based on their parents groups = self.call_infos.inject(Hash.new) do |hash, call_info| key = call_info.parent ? call_info.parent.target : self (hash[key] ||= []) << call_info hash end groups.map do |key, value| AggregateCallInfo.new(value) end end |
#call_infos ⇒ Array of call_info
Returns an array of call info objects that contain profiling information about the current method.
863 864 865 866 867 868 |
# File 'ext/ruby_prof/ruby_prof.c', line 863
static VALUE
prof_method_call_infos(VALUE self)
{
prof_method_t *method = get_prof_method(self);
return prof_call_infos_wrap(method->call_infos);
}
|
#called ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ruby-prof/method_info.rb', line 19 def called @called ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.called end end end |
#children ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/ruby-prof/method_info.rb', line 73 def children @children ||= begin call_infos.map do |call_info| call_info.children end.flatten end end |
#children_time ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/ruby-prof/method_info.rb', line 51 def children_time @children_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.children_time end end end |
#full_name ⇒ String
Returns the full name of this method in the format Object#method.
851 852 853 854 855 856 |
# File 'ext/ruby_prof/ruby_prof.c', line 851
static VALUE
prof_full_name(VALUE self)
{
prof_method_t *method = get_prof_method(self);
return full_name(method->key->klass, method->key->mid, method->key->depth);
}
|
#method_class ⇒ Object
Returns the Ruby klass that owns this method.
802 803 804 805 806 807 |
# File 'ext/ruby_prof/ruby_prof.c', line 802
static VALUE
prof_method_klass(VALUE self)
{
prof_method_t *result = get_prof_method(self);
return result->key->klass;
}
|
#klass_name ⇒ String
Returns the name of this method’s class. Singleton classes will have the form <Object::Object>.
826 827 828 829 830 831 |
# File 'ext/ruby_prof/ruby_prof.c', line 826
static VALUE
prof_klass_name(VALUE self)
{
prof_method_t *method = get_prof_method(self);
return klass_name(method->key->klass);
}
|
#line_no ⇒ Integer
returns the line number of the method
773 774 775 776 777 |
# File 'ext/ruby_prof/ruby_prof.c', line 773
static VALUE
prof_method_line(VALUE self)
{
return rb_int_new(get_prof_method(self)->line);
}
|
#method_id ⇒ Object
Returns the id of this method.
813 814 815 816 817 818 |
# File 'ext/ruby_prof/ruby_prof.c', line 813
static VALUE
prof_method_id(VALUE self)
{
prof_method_t *result = get_prof_method(self);
return ID2SYM(result->key->mid);
}
|
#method_name() ⇒ Object
839 840 841 842 843 844 |
# File 'ext/ruby_prof/ruby_prof.c', line 839
static VALUE
prof_method_name(VALUE self, int depth)
{
prof_method_t *method = get_prof_method(self);
return method_name(method->key->mid, depth);
}
|
#min_depth ⇒ Object
59 60 61 62 63 |
# File 'lib/ruby-prof/method_info.rb', line 59 def min_depth @min_depth ||= call_infos.map do |call_info| call_info.depth end.min end |
#root? ⇒ Boolean
65 66 67 68 69 70 71 |
# File 'lib/ruby-prof/method_info.rb', line 65 def root? @root ||= begin call_infos.find do |call_info| not call_info.root? end.nil? end end |
#self_time ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/ruby-prof/method_info.rb', line 35 def self_time @self_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.self_time end end end |
#source_file ⇒ String
return the source file of the method
784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'ext/ruby_prof/ruby_prof.c', line 784
static VALUE prof_method_source_file(VALUE self)
{
const char* sf = get_prof_method(self)->source_file;
if(!sf)
{
return rb_str_new2("ruby_runtime");
}
else
{
return rb_str_new2(sf);
}
}
|
#to_s ⇒ Object
107 108 109 |
# File 'lib/ruby-prof/method_info.rb', line 107 def to_s full_name end |
#total_time ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ruby-prof/method_info.rb', line 27 def total_time @total_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.total_time end end end |
#wait_time ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ruby-prof/method_info.rb', line 43 def wait_time @wait_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.wait_time end end end |