Class: RubyProf::CallInfo
- Inherits:
-
Object
- Object
- RubyProf::CallInfo
- Defined in:
- ext/ruby_prof/ruby_prof.c,
lib/ruby-prof/call_info.rb,
ext/ruby_prof/ruby_prof.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.
Instance Method Summary collapse
-
#add_self_time(call_info) ⇒ nil
adds self time from call_info to self.
-
#add_total_time(call_info) ⇒ nil
adds total time time from call_info to self.
-
#add_wait_time(call_info) ⇒ nil
adds wait time from call_info to self.
- #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 ⇒ Object
- #compute_minimality(parent_methods) ⇒ Object
- #depth ⇒ Object
-
#eliminate! ⇒ Object
eliminate call info from the call tree.
-
#find_call(other) ⇒ Object
find a sepcific call in list of children.
-
#line_no ⇒ Integer
returns the line number of the method.
-
#merge_call_tree(other) ⇒ Object
merge two call trees.
- #minimal? ⇒ Boolean
-
#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.
- #root? ⇒ Boolean
-
#self_time ⇒ Float
Returns the total amount of time spent in this method.
- #stack ⇒ Object
-
#called ⇒ MethodInfo
Returns the target method.
- #to_s ⇒ Object
-
#total_time ⇒ Float
Returns the total amount of time spent in this method and its children.
-
#wait_time ⇒ Float
Returns the total amount of time this method waited for other threads.
Instance Method Details
#add_self_time(call_info) ⇒ nil
adds self time from call_info to self.
443 444 445 446 447 448 449 450 451 |
# File 'ext/ruby_prof/ruby_prof.c', line 443
static VALUE
prof_call_info_add_self_time(VALUE self, VALUE other)
{
prof_call_info_t *result = prof_get_call_info_result(self);
prof_call_info_t *other_info = prof_get_call_info_result(other);
result->self_time += other_info->self_time;
return Qnil;
}
|
#add_total_time(call_info) ⇒ nil
adds total time time from call_info to self.
417 418 419 420 421 422 423 424 425 |
# File 'ext/ruby_prof/ruby_prof.c', line 417
static VALUE
prof_call_info_add_total_time(VALUE self, VALUE other)
{
prof_call_info_t *result = prof_get_call_info_result(self);
prof_call_info_t *other_info = prof_get_call_info_result(other);
result->total_time += other_info->total_time;
return Qnil;
}
|
#add_wait_time(call_info) ⇒ nil
adds wait time from call_info to self.
470 471 472 473 474 475 476 477 478 |
# File 'ext/ruby_prof/ruby_prof.c', line 470
static VALUE
prof_call_info_add_wait_time(VALUE self, VALUE other)
{
prof_call_info_t *result = prof_get_call_info_result(self);
prof_call_info_t *other_info = prof_get_call_info_result(other);
result->wait_time += other_info->wait_time;
return Qnil;
}
|
#call_sequence ⇒ Object
33 34 35 36 37 |
# File 'lib/ruby-prof/call_info.rb', line 33 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.
372 373 374 375 376 377 |
# File 'ext/ruby_prof/ruby_prof.c', line 372
static VALUE
prof_call_info_called(VALUE self)
{
prof_call_info_t *result = prof_get_call_info_result(self);
return INT2NUM(result->called);
}
|
#called= ⇒ Object
Sets the call count to n.
383 384 385 386 387 388 389 |
# File 'ext/ruby_prof/ruby_prof.c', line 383
static VALUE
prof_call_info_set_called(VALUE self, VALUE called)
{
prof_call_info_t *result = prof_get_call_info_result(self);
result->called = NUM2INT(called);
return called;
}
|
#children ⇒ Hash
Returns an array of call info objects of methods that this method called (ie, children).
523 524 525 526 527 528 529 530 531 532 533 |
# File 'ext/ruby_prof/ruby_prof.c', line 523
static VALUE
prof_call_info_children(VALUE self)
{
prof_call_info_t *call_info = prof_get_call_info_result(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 ⇒ Object
14 15 16 17 18 |
# File 'lib/ruby-prof/call_info.rb', line 14 def children_time children.inject(0) do |sum, call_info| sum += call_info.total_time end end |
#compute_minimality(parent_methods) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby-prof/call_info.rb', line 51 def compute_minimality(parent_methods) if parent_methods.include?(target) @minimal = false else @minimal = true parent_methods << target unless children.empty? end children.each {|ci| ci.compute_minimality(parent_methods)} parent_methods.delete(target) if @minimal && !children.empty? end |
#depth ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/ruby-prof/call_info.rb', line 3 def depth result = 0 call_info = self.parent while call_info result += 1 call_info = call_info.parent end result end |
#eliminate! ⇒ Object
eliminate call info from the call tree. adds self and wait time to parent and attaches called methods to parent. merges call trees for methods called from both praent end self.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ruby-prof/call_info.rb', line 65 def eliminate! # puts "eliminating #{self}" return unless parent parent.add_self_time(self) parent.add_wait_time(self) children.each do |kid| if call = parent.find_call(kid) call.merge_call_tree(kid) else parent.children << kid # $stderr.puts "setting parent of #{kid}\nto #{parent}" kid.parent = parent end end parent.children.delete(self) end |
#find_call(other) ⇒ Object
find a sepcific 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 |
#line_no ⇒ Integer
returns the line number of the method
395 396 397 398 399 400 |
# File 'ext/ruby_prof/ruby_prof.c', line 395
static VALUE
prof_call_info_line(VALUE self)
{
prof_call_info_t *result = prof_get_call_info_result(self);
return rb_int_new(result->line);
}
|
#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 |
#minimal? ⇒ Boolean
47 48 49 |
# File 'lib/ruby-prof/call_info.rb', line 47 def minimal? @minimal end |
#parent ⇒ Object
Returns the call_infos parent call_info object (the method that called this method).
484 485 486 487 488 489 490 491 492 |
# File 'ext/ruby_prof/ruby_prof.c', line 484
static VALUE
prof_call_info_parent(VALUE self)
{
prof_call_info_t *result = prof_get_call_info_result(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.
498 499 500 501 502 503 504 505 506 507 |
# File 'ext/ruby_prof/ruby_prof.c', line 498
static VALUE
prof_call_info_set_parent(VALUE self, VALUE new_parent)
{
prof_call_info_t *result = prof_get_call_info_result(self);
if (new_parent == Qnil)
result->parent = NULL;
else
result->parent = prof_get_call_info_result(new_parent);
return prof_call_info_parent(self);
}
|
#root? ⇒ Boolean
39 40 41 |
# File 'lib/ruby-prof/call_info.rb', line 39 def root? self.parent.nil? end |
#self_time ⇒ Float
Returns the total amount of time spent in this method.
431 432 433 434 435 436 437 |
# File 'ext/ruby_prof/ruby_prof.c', line 431
static VALUE
prof_call_info_self_time(VALUE self)
{
prof_call_info_t *result = prof_get_call_info_result(self);
return rb_float_new(convert_measurement(result->self_time));
}
|
#stack ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby-prof/call_info.rb', line 20 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.
357 358 359 360 361 362 363 364 365 366 |
# File 'ext/ruby_prof/ruby_prof.c', line 357
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_result(self);
return prof_method_wrap(result->target);
}
|
#to_s ⇒ Object
43 44 45 |
# File 'lib/ruby-prof/call_info.rb', line 43 def to_s "#{call_sequence}" end |
#total_time ⇒ Float
Returns the total amount of time spent in this method and its children.
406 407 408 409 410 411 |
# File 'ext/ruby_prof/ruby_prof.c', line 406
static VALUE
prof_call_info_total_time(VALUE self)
{
prof_call_info_t *result = prof_get_call_info_result(self);
return rb_float_new(convert_measurement(result->total_time));
}
|
#wait_time ⇒ Float
Returns the total amount of time this method waited for other threads.
457 458 459 460 461 462 463 |
# File 'ext/ruby_prof/ruby_prof.c', line 457
static VALUE
prof_call_info_wait_time(VALUE self)
{
prof_call_info_t *result = prof_get_call_info_result(self);
return rb_float_new(convert_measurement(result->wait_time));
}
|