Class: RubyProf::MethodInfo
- Inherits:
-
Object
- Object
- RubyProf::MethodInfo
- Includes:
- Comparable
- Defined in:
- ext/ruby_prof/rp_method.c,
lib/ruby-prof/method_info.rb,
ext/ruby_prof/rp_method.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
- #clear_cached_values_which_depend_on_recursiveness ⇒ Object
- #detect_recursion ⇒ Object
-
#eliminate! ⇒ Object
remove method from the call graph.
-
#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 ⇒ String
Returns the name of this method in the format Object#method.
- #min_depth ⇒ Object
- #non_recursive ⇒ Object
- #non_recursive? ⇒ Boolean
- #parents ⇒ Object
- #recalc_recursion ⇒ Object
- #recursive? ⇒ Boolean
- #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
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby-prof/method_info.rb', line 7 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 self.full_name <=> other.full_name end end |
#aggregate_children ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ruby-prof/method_info.rb', line 121 def aggregate_children # Group call info's based on their targets groups = self.children.each_with_object({}) do |call_info, hash| key = call_info.target (hash[key] ||= []) << call_info end groups.map do |key, value| AggregateCallInfo.new(value) end end |
#aggregate_parents ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ruby-prof/method_info.rb', line 109 def aggregate_parents # Group call info's based on their parents groups = self.call_infos.each_with_object({}) do |call_info, hash| key = call_info.parent ? call_info.parent.target : self (hash[key] ||= []) << call_info 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.
386 387 388 389 390 391 392 393 394 395 |
# File 'ext/ruby_prof/rp_method.c', line 386
static VALUE
prof_method_call_infos(VALUE self)
{
prof_method_t *method = get_prof_method(self);
if (method->call_infos->object == Qnil)
{
method->call_infos->object = prof_call_infos_wrap(method->call_infos);
}
return method->call_infos->object;
}
|
#called ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ruby-prof/method_info.rb', line 33 def called @called ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.called end end end |
#children ⇒ Object
101 102 103 |
# File 'lib/ruby-prof/method_info.rb', line 101 def children @children ||= call_infos.map(&:children).flatten end |
#children_time ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/ruby-prof/method_info.rb', line 68 def children_time @children_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.children_time unless call_info.recursive sum end end end |
#clear_cached_values_which_depend_on_recursiveness ⇒ Object
29 30 31 |
# File 'lib/ruby-prof/method_info.rb', line 29 def clear_cached_values_which_depend_on_recursiveness @total_time = @self_time = @wait_time = @children_time = nil end |
#detect_recursion ⇒ Object
21 22 23 |
# File 'lib/ruby-prof/method_info.rb', line 21 def detect_recursion call_infos.each(&:detect_recursion) end |
#eliminate! ⇒ Object
remove method from the call graph. should not be called directly.
138 139 140 141 142 |
# File 'lib/ruby-prof/method_info.rb', line 138 def eliminate! # $stderr.puts "eliminating #{self}" call_infos.each{ |call_info| call_info.eliminate! } call_infos.clear end |
#full_name ⇒ String
Returns the full name of this method in the format Object#method.
374 375 376 377 378 379 |
# File 'ext/ruby_prof/rp_method.c', line 374
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_class ⇒ Object
Returns the Ruby klass that owns this method.
325 326 327 328 329 330 |
# File 'ext/ruby_prof/rp_method.c', line 325
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>.
349 350 351 352 353 354 |
# File 'ext/ruby_prof/rp_method.c', line 349
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
296 297 298 299 300 |
# File 'ext/ruby_prof/rp_method.c', line 296
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.
336 337 338 339 340 341 |
# File 'ext/ruby_prof/rp_method.c', line 336
static VALUE
prof_method_id(VALUE self)
{
prof_method_t *result = get_prof_method(self);
return ID2SYM(result->key->mid);
}
|
#method_name ⇒ String
Returns the name of this method in the format Object#method. Singletons methods will be returned in the format <Object::Object>#method.
362 363 364 365 366 367 |
# File 'ext/ruby_prof/rp_method.c', line 362
static VALUE
prof_method_name(VALUE self)
{
prof_method_t *method = get_prof_method(self);
return method_name(method->key->mid);
}
|
#min_depth ⇒ Object
77 78 79 |
# File 'lib/ruby-prof/method_info.rb', line 77 def min_depth @min_depth ||= call_infos.map(&:depth).min end |
#non_recursive ⇒ Object
97 98 99 |
# File 'lib/ruby-prof/method_info.rb', line 97 def non_recursive @non_recursive ||= call_infos.all?(&:non_recursive?) ? 1 : 0 end |
#non_recursive? ⇒ Boolean
93 94 95 |
# File 'lib/ruby-prof/method_info.rb', line 93 def non_recursive? non_recursive == 1 end |
#parents ⇒ Object
105 106 107 |
# File 'lib/ruby-prof/method_info.rb', line 105 def parents @parents ||= call_infos.map(&:parent) end |
#recalc_recursion ⇒ Object
25 26 27 |
# File 'lib/ruby-prof/method_info.rb', line 25 def recalc_recursion call_infos.each(&:recalc_recursion) end |
#recursive? ⇒ Boolean
89 90 91 |
# File 'lib/ruby-prof/method_info.rb', line 89 def recursive? call_infos.detect(&:recursive) end |
#root? ⇒ Boolean
81 82 83 84 85 86 87 |
# File 'lib/ruby-prof/method_info.rb', line 81 def root? @root ||= begin call_infos.find do |call_info| not call_info.root? end.nil? end end |
#self_time ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/ruby-prof/method_info.rb', line 50 def self_time @self_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.self_time unless call_info.recursive sum end end end |
#source_file ⇒ String
return the source file of the method
307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'ext/ruby_prof/rp_method.c', line 307
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
133 134 135 |
# File 'lib/ruby-prof/method_info.rb', line 133 def to_s "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, ct: #{self.children_time})" end |
#total_time ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/ruby-prof/method_info.rb', line 41 def total_time @total_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.total_time unless call_info.recursive sum end end end |
#wait_time ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/ruby-prof/method_info.rb', line 59 def wait_time @wait_time ||= begin call_infos.inject(0) do |sum, call_info| sum += call_info.wait_time unless call_info.recursive sum end end end |