Class: RubyProf::CallInfo

Inherits:
Object
  • Object
show all
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

Instance Method Details

#call_sequenceObject



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

#calledInteger

Returns the total amount of times this method was called.

Returns:

  • (Integer)


550
551
552
553
554
555
# File 'ext/ruby_prof/ruby_prof.c', line 550

static VALUE
prof_call_info_called(VALUE self)
{
    prof_call_info_t *result = prof_get_call_info_result(self);
    return INT2NUM(result->called);
}

#childrenHash

Returns an array of call info objects of methods that this method called (ie, children).

Returns:

  • (Hash)


631
632
633
634
635
636
637
638
639
640
641
# File 'ext/ruby_prof/ruby_prof.c', line 631

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_timeObject



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

#depthObject



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

#line_noInteger

returns the line number of the method

Returns:

  • (Integer)


561
562
563
564
565
566
# File 'ext/ruby_prof/ruby_prof.c', line 561

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);
}

#parentObject

Returns the call_infos parent call_info object (the method that called this method).



607
608
609
610
611
612
613
614
615
# File 'ext/ruby_prof/ruby_prof.c', line 607

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;
}

#root?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ruby-prof/call_info.rb', line 39

def root?
  self.parent.nil?
end

#self_timeFloat

Returns the total amount of time spent in this method.

Returns:

  • (Float)


583
584
585
586
587
588
589
# File 'ext/ruby_prof/ruby_prof.c', line 583

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));
}

#stackObject



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

#calledMethodInfo

Returns the target method.

Returns:



535
536
537
538
539
540
541
542
543
544
# File 'ext/ruby_prof/ruby_prof.c', line 535

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_sObject



43
44
45
# File 'lib/ruby-prof/call_info.rb', line 43

def to_s
  "#{call_sequence}"
end

#total_timeFloat

Returns the total amount of time spent in this method and its children.

Returns:

  • (Float)


572
573
574
575
576
577
# File 'ext/ruby_prof/ruby_prof.c', line 572

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_timeFloat

Returns the total amount of time this method waited for other threads.

Returns:

  • (Float)


595
596
597
598
599
600
601
# File 'ext/ruby_prof/ruby_prof.c', line 595

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));
}