Class: RubyProf::CallInfo
- Inherits:
-
Object
- Object
- RubyProf::CallInfo
- Defined in:
- ext/ruby_prof/rp_call_info.c,
lib/ruby-prof/call_info.rb,
ext/ruby_prof/rp_call_info.c
Overview
RubyProf::CallInfo is a helper class used by RubyProf::MethodInfo to keep track of which child methods were called and how long they took to execute.
Class Method Summary collapse
Instance Method Summary collapse
- #call_sequence ⇒ Object
-
#called ⇒ Integer
Returns the total amount of times this method was called.
-
#called= ⇒ Object
Sets the call count to n.
-
#children ⇒ Hash
Returns an array of call info objects of methods that this method called (ie, children).
- #children_time(i = 0) ⇒ Object
-
#depth ⇒ Integer
returns the depth of this call info in the call graph.
- #descendent_of(other) ⇒ Object
-
#find_call(other) ⇒ Object
find a specific call in list of children.
- #inspect ⇒ Object
-
#line_no ⇒ Integer
returns the line number of the method.
- #measure_values ⇒ Object
-
#measure_values_memoized ⇒ Object
part of this class is defined in C code.
-
#merge_call_tree(other) ⇒ Object
merge two call trees.
-
#parent ⇒ Object
Returns the call_infos parent call_info object (the method that called this method).
-
#parent= ⇒ Object
Changes the parent of self to new_parent and returns it.
-
#recursive? ⇒ Boolean
Returns the true if this call info is a recursive invocation.
- #root? ⇒ Boolean
- #self_time(i = 0) ⇒ Object
- #stack ⇒ Object
-
#called ⇒ MethodInfo
Returns the target method.
- #to_s ⇒ Object
- #total_time(i = 0) ⇒ Object
- #wait_time(i = 0) ⇒ Object
Class Method Details
.roots_of(call_infos) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/ruby-prof/call_info.rb', line 65 def self.roots_of(call_infos) roots = [] sorted = call_infos.sort_by(&:depth).reverse while call_info = sorted.shift roots << call_info unless sorted.any?{|p| call_info.descendent_of(p)} end roots end |
Instance Method Details
#call_sequence ⇒ Object
47 48 49 50 51 |
# File 'lib/ruby-prof/call_info.rb', line 47 def call_sequence @call_sequence ||= begin stack.map {|method| method.full_name}.join('->') end end |
#called ⇒ Integer
Returns the total amount of times this method was called.
163 164 165 166 167 168 |
# File 'ext/ruby_prof/rp_call_info.c', line 163
static VALUE
prof_call_info_called(VALUE self)
{
prof_call_info_t *result = prof_get_call_info(self);
return INT2NUM(result->called);
}
|
#called= ⇒ Object
Sets the call count to n.
174 175 176 177 178 179 180 |
# File 'ext/ruby_prof/rp_call_info.c', line 174
static VALUE
prof_call_info_set_called(VALUE self, VALUE called)
{
prof_call_info_t *result = prof_get_call_info(self);
result->called = NUM2INT(called);
return called;
}
|
#children ⇒ Hash
Returns an array of call info objects of methods that this method called (ie, children).
258 259 260 261 262 263 264 265 266 267 268 |
# File 'ext/ruby_prof/rp_call_info.c', line 258
static VALUE
prof_call_info_children(VALUE self)
{
prof_call_info_t *call_info = prof_get_call_info(self);
if (call_info->children == Qnil)
{
call_info->children = rb_ary_new();
st_foreach(call_info->call_infos, prof_call_info_collect_children, call_info->children);
}
return call_info->children;
}
|
#children_time(i = 0) ⇒ Object
28 29 30 31 32 |
# File 'lib/ruby-prof/call_info.rb', line 28 def children_time(i = 0) children.inject(0) do |sum, call_info| sum += call_info.total_time(i) end end |
#depth ⇒ Integer
returns the depth of this call info in the call graph
197 198 199 200 201 202 |
# File 'ext/ruby_prof/rp_call_info.c', line 197
static VALUE
prof_call_info_depth(VALUE self)
{
prof_call_info_t *result = prof_get_call_info(self);
return rb_int_new(result->depth);
}
|
#descendent_of(other) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/ruby-prof/call_info.rb', line 57 def descendent_of(other) p = self.parent while p && p != other && p.depth > other.depth p = p.parent end p == other end |
#find_call(other) ⇒ Object
find a specific call in list of children. returns nil if not found. note: there can’t be more than one child with a given target method. in other words: x.children.grep{|y|y.target==m}.size <= 1 for all method infos m and call infos x
85 86 87 88 89 |
# File 'lib/ruby-prof/call_info.rb', line 85 def find_call(other) matching = children.select { |kid| kid.target == other.target } raise "inconsistent call tree" unless matching.size <= 1 matching.first end |
#inspect ⇒ Object
78 79 80 |
# File 'lib/ruby-prof/call_info.rb', line 78 def inspect super + "(#{target.full_name}, d: #{depth}, c: #{called}, tt: #{total_time}, st: #{self_time}, ct: #{children_time})" end |
#line_no ⇒ Integer
returns the line number of the method
208 209 210 211 212 213 |
# File 'ext/ruby_prof/rp_call_info.c', line 208
static VALUE
prof_call_info_line(VALUE self)
{
prof_call_info_t *result = prof_get_call_info(self);
return rb_int_new(result->line);
}
|
#measure_values ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'ext/ruby_prof/rp_call_info.c', line 338
VALUE
prof_call_info_measure_values(VALUE self)
{
prof_call_info_t *call_info = prof_get_call_info(self);
VALUE ary = rb_ary_new2(call_info->measures_len);
for(size_t i = 0; i < call_info->measures_len; i++) {
VALUE sub_ary = rb_ary_new2(3);
rb_ary_store(sub_ary, 0, DBL2NUM(call_info->measure_values[i].total));
rb_ary_store(sub_ary, 1, DBL2NUM(call_info->measure_values[i].self));
rb_ary_store(sub_ary, 2, DBL2NUM(call_info->measure_values[i].wait));
rb_ary_store(ary, i, sub_ary);
}
return ary;
}
|
#measure_values_memoized ⇒ Object
part of this class is defined in C code. it provides the following attributes pertaining to tree structure: depth: tree level (0 == root) parent: parent call info (can be nil) children: array of call info children (can be empty) target: method info (containing an array of call infos)
12 13 14 |
# File 'lib/ruby-prof/call_info.rb', line 12 def measure_values_memoized @measure_values ||= measure_values end |
#merge_call_tree(other) ⇒ Object
merge two call trees. adds self, wait, and total time of other to self and merges children of other into children of self.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ruby-prof/call_info.rb', line 92 def merge_call_tree(other) # $stderr.puts "merging #{self}\nand #{other}" self.called += other.called add_self_time(other) add_wait_time(other) add_total_time(other) other.children.each do |other_kid| if kid = find_call(other_kid) # $stderr.puts "merging kids" kid.merge_call_tree(other_kid) else other_kid.parent = self children << other_kid end end other.children.clear other.target.call_infos.delete(other) end |
#parent ⇒ Object
Returns the call_infos parent call_info object (the method that called this method).
219 220 221 222 223 224 225 226 227 |
# File 'ext/ruby_prof/rp_call_info.c', line 219
static VALUE
prof_call_info_parent(VALUE self)
{
prof_call_info_t *result = prof_get_call_info(self);
if (result->parent)
return prof_call_info_wrap(result->parent);
else
return Qnil;
}
|
#parent= ⇒ Object
Changes the parent of self to new_parent and returns it.
233 234 235 236 237 238 239 240 241 242 |
# File 'ext/ruby_prof/rp_call_info.c', line 233
static VALUE
prof_call_info_set_parent(VALUE self, VALUE new_parent)
{
prof_call_info_t *result = prof_get_call_info(self);
if (new_parent == Qnil)
result->parent = NULL;
else
result->parent = prof_get_call_info(new_parent);
return prof_call_info_parent(self);
}
|
#recursive? ⇒ Boolean
Returns the true if this call info is a recursive invocation
186 187 188 189 190 191 |
# File 'ext/ruby_prof/rp_call_info.c', line 186
static VALUE
prof_call_info_recursive(VALUE self)
{
prof_call_info_t *result = prof_get_call_info(self);
return result->recursive ? Qtrue : Qfalse;
}
|
#root? ⇒ Boolean
53 54 55 |
# File 'lib/ruby-prof/call_info.rb', line 53 def root? self.parent.nil? end |
#self_time(i = 0) ⇒ Object
20 21 22 |
# File 'lib/ruby-prof/call_info.rb', line 20 def self_time(i = 0) measure_values_memoized[i][1] end |
#stack ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby-prof/call_info.rb', line 34 def stack @stack ||= begin methods = Array.new call_info = self while call_info methods << call_info.target call_info = call_info.parent end methods.reverse end end |
#called ⇒ MethodInfo
Returns the target method.
148 149 150 151 152 153 154 155 156 157 |
# File 'ext/ruby_prof/rp_call_info.c', line 148
static VALUE
prof_call_info_target(VALUE self)
{
/* Target is a pointer to a method_info - so we have to be careful
about the GC. We will wrap the method_info but provide no
free method so the underlying object is not freed twice! */
prof_call_info_t *result = prof_get_call_info(self);
return prof_method_wrap(result->target);
}
|
#to_s ⇒ Object
74 75 76 |
# File 'lib/ruby-prof/call_info.rb', line 74 def to_s "#{target.full_name} (c: #{called}, tt: #{total_time}, st: #{self_time}, ct: #{children_time})" end |
#total_time(i = 0) ⇒ Object
16 17 18 |
# File 'lib/ruby-prof/call_info.rb', line 16 def total_time(i = 0) measure_values_memoized[i][0] end |
#wait_time(i = 0) ⇒ Object
24 25 26 |
# File 'lib/ruby-prof/call_info.rb', line 24 def wait_time(i = 0) measure_values_memoized[i][2] end |