Class: RubyProf::MethodInfo

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

Instance Method Summary collapse

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_childrenObject


93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ruby-prof/method_info.rb', line 93

def aggregate_children
  # group call infos 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, self)
  end
end

#aggregate_parentsObject


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ruby-prof/method_info.rb', line 81

def aggregate_parents
  # group call infos 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, self)
  end
end

#call_infosArray of call_info

Returns an array of call info objects that contain profiling information about the current method.

Returns:

  • (Array of call_info)

627
628
629
630
631
632
633
634
635
# File 'ext/ruby_prof/rp_method.c', line 627

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

#calledObject


21
22
23
24
25
26
27
# File 'lib/ruby-prof/method_info.rb', line 21

def called
  @called ||= begin
    call_infos.inject(0) do |sum, call_info|
      sum + call_info.called
    end
  end
end

#calltree_nameString

Returns the full name of this method in the calltree format.

Returns:

  • (String)

676
677
678
679
680
681
# File 'ext/ruby_prof/rp_method.c', line 676

static VALUE
prof_calltree_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return prof_method_t_calltree_name(method);
}

#childrenObject


73
74
75
# File 'lib/ruby-prof/method_info.rb', line 73

def children
  @children ||= call_infos.map(&:children).flatten
end

#children_time(i = 0) ⇒ Object


52
53
54
55
56
57
58
59
# File 'lib/ruby-prof/method_info.rb', line 52

def children_time(i = 0)
  @children_time ||= begin
    call_infos.inject(0) do |sum, call_info|
      sum += call_info.children_time(i) if !call_info.recursive?
      sum
    end
  end
end

#full_nameString

Returns the full name of this method in the format Object#method.

Returns:

  • (String)

615
616
617
618
619
620
# File 'ext/ruby_prof/rp_method.c', line 615

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_classObject

Returns the Ruby klass that owns this method.


566
567
568
569
570
571
# File 'ext/ruby_prof/rp_method.c', line 566

static VALUE
prof_method_klass(VALUE self)
{
    prof_method_t *result = get_prof_method(self);
    return result->key->klass;
}

#klass_nameString

Returns the name of this method's class. Singleton classes will have the form <Object::Object>.

Returns:

  • (String)

590
591
592
593
594
595
# File 'ext/ruby_prof/rp_method.c', line 590

static VALUE
prof_klass_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return klass_name(method->key->klass);
}

#line_noInteger

returns the line number of the method

Returns:

  • (Integer)

543
544
545
546
547
548
# File 'ext/ruby_prof/rp_method.c', line 543

static VALUE
prof_method_line(VALUE self)
{
    int line = get_prof_method(self)->line;
    return rb_int_new(line);
}

#method_idObject

Returns the id of this method.


577
578
579
580
581
582
# File 'ext/ruby_prof/rp_method.c', line 577

static VALUE
prof_method_id(VALUE self)
{
    prof_method_t *result = get_prof_method(self);
    return ID2SYM(result->key->mid);
}

#method_nameString

Returns the name of this method in the format Object#method. Singletons methods will be returned in the format <Object::Object>#method.

Returns:

  • (String)

603
604
605
606
607
608
# File 'ext/ruby_prof/rp_method.c', line 603

static VALUE
prof_method_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return method_name(method->key->mid);
}

#min_depthObject


61
62
63
# File 'lib/ruby-prof/method_info.rb', line 61

def min_depth
  @min_depth ||= call_infos.map(&:depth).min
end

#parentsObject


77
78
79
# File 'lib/ruby-prof/method_info.rb', line 77

def parents
  @parents ||= call_infos.map(&:parent)
end

#recursive?Boolean

Returns the true if this method is recursive

Returns:

  • (Boolean)

641
642
643
644
645
646
# File 'ext/ruby_prof/rp_method.c', line 641

static VALUE
prof_method_recursive(VALUE self)
{
  prof_method_t *method = get_prof_method(self);
  return method->recursive ? Qtrue : Qfalse;
}

#root?Boolean

Returns:

  • (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(i = 0) ⇒ Object


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

def self_time(i = 0)
  @self_time ||= []
  @self_time[i] ||= self_time_unmemoized(i)
end

#self_timeObject

Returns the sum of the self time of this method's call infos.


687
688
689
690
691
692
# File 'ext/ruby_prof/rp_method.c', line 687

static VALUE
prof_method_self_time_unmemoized(VALUE self, VALUE idx)
{
    prof_method_t *method = get_prof_method(self);
    return rb_float_new(prof_method_t_self_time(method, NUM2INT(idx)));
}

#source_fileString

return the source file of the method

Returns:

  • (String)

555
556
557
558
559
# File 'ext/ruby_prof/rp_method.c', line 555

static VALUE prof_method_source_file(VALUE self)
{
    const char* sf = prof_method_t_source_file(get_prof_method(self));
    return rb_str_new2(sf);
}

#source_klassObject

Returns the Ruby klass of the natural source-level definition.


652
653
654
655
656
657
# File 'ext/ruby_prof/rp_method.c', line 652

static VALUE
prof_source_klass(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return resolve_source_klass(method);
}

#calltree_nameString

Returns the full name of this method in an approximate source-level format.

Returns:

  • (String)

664
665
666
667
668
669
670
# File 'ext/ruby_prof/rp_method.c', line 664

static VALUE
prof_source_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    volatile VALUE source_klass = resolve_source_klass(method);
    return source_name(source_klass, method->relation, method->key->mid);
}

#to_sObject


105
106
107
# File 'lib/ruby-prof/method_info.rb', line 105

def to_s
  "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})"
end

#total_time(i = 0) ⇒ Object


29
30
31
32
33
34
35
36
# File 'lib/ruby-prof/method_info.rb', line 29

def total_time(i = 0)
  @total_time ||= begin
    call_infos.inject(0) do |sum, call_info|
      sum += call_info.total_time(i) if !call_info.recursive?
      sum
    end
  end
end

#wait_time(i = 0) ⇒ Object


43
44
45
46
47
48
49
50
# File 'lib/ruby-prof/method_info.rb', line 43

def wait_time(i = 0)
  @wait_time ||= begin
    call_infos.inject(0) do |sum, call_info|
      sum += call_info.wait_time(i) if !call_info.recursive?
      sum
    end
  end
end