Class: RubyProf::MethodInfo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/ruby_prof/ruby_prof.c,
lib/ruby-prof/method_info.rb,
ext/ruby_prof/ruby_prof.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

Instance Method Details

#<=>(other) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby-prof/method_info.rb', line 5

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
    -1 * (self.full_name <=> other.full_name)
  end
end

#aggregate_childrenObject



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ruby-prof/method_info.rb', line 96

def aggregate_children
  # Group call info's based on their targets
  groups = self.children.inject(Hash.new) do |hash, call_info|
    key = call_info.target
    (hash[key] ||= []) << call_info
    hash
  end

  groups.map do |key, value|
    AggregateCallInfo.new(value)
  end
end

#aggregate_parentsObject



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

def aggregate_parents
  # Group call info's based on their parents
  groups = self.call_infos.inject(Hash.new) do |hash, call_info|
    key = call_info.parent ? call_info.parent.target : self
    (hash[key] ||= []) << call_info
    hash
  end

  groups.map do |key, value|
    AggregateCallInfo.new(value)
  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)


753
754
755
756
757
758
# File 'ext/ruby_prof/ruby_prof.c', line 753

static VALUE
prof_method_call_infos(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return prof_call_infos_wrap(method->call_infos);
}

#calledObject



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

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

#childrenObject



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

def children
  @children ||= begin
    call_infos.map do |call_info|
      call_info.children
    end.flatten
  end
end

#children_timeObject



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

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

#dumpObject



113
114
115
116
117
118
119
120
121
# File 'lib/ruby-prof/method_info.rb', line 113

def dump
  res = ""
  res << "MINFO: #{klass_name}##{method_name} total_time: #{total_time} (#{full_name})\n"
  call_infos.each do |ci|
    pinfo = ci.root? ? "TOPLEVEL" : (p=ci.parent.target; "#{p.klass_name}##{p.method_name} (#{ci.parent.object_id}) (#{p.full_name})")
    res << "CINFO[#{ci.object_id}] called #{ci.called} times from #{pinfo}\n"
  end
  res
end

#eliminate!Object

remove method from the call graph. should not be called directly.



124
125
126
127
128
# File 'lib/ruby-prof/method_info.rb', line 124

def eliminate!
  # $stderr.puts "eliminating #{self}"
  call_infos.each{ |call_info| call_info.eliminate! }
  call_infos.clear
end

#full_nameString

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

Returns:

  • (String)


741
742
743
744
745
746
# File 'ext/ruby_prof/ruby_prof.c', line 741

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.



692
693
694
695
696
697
# File 'ext/ruby_prof/ruby_prof.c', line 692

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)


716
717
718
719
720
721
# File 'ext/ruby_prof/ruby_prof.c', line 716

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)


663
664
665
666
667
# File 'ext/ruby_prof/ruby_prof.c', line 663

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

#method_idObject

Returns the id of this method.



703
704
705
706
707
708
# File 'ext/ruby_prof/ruby_prof.c', line 703

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)


729
730
731
732
733
734
# File 'ext/ruby_prof/ruby_prof.c', line 729

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
64
65
# File 'lib/ruby-prof/method_info.rb', line 61

def min_depth
  @min_depth ||= call_infos.map do |call_info|
    call_info.depth
  end.min
end

#root?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
# File 'lib/ruby-prof/method_info.rb', line 67

def root?
  @root ||= begin
    call_infos.find do |call_info|
      not call_info.root?
    end.nil?
  end
end

#self_timeObject



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

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

#source_fileString

return the source file of the method

Returns:

  • (String)


674
675
676
677
678
679
680
681
682
683
684
685
# File 'ext/ruby_prof/ruby_prof.c', line 674

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_sObject



109
110
111
# File 'lib/ruby-prof/method_info.rb', line 109

def to_s
  full_name
end

#total_timeObject



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

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

#wait_timeObject



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

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