Class: JRubyProf::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby-prof/method.rb

Defined Under Namespace

Classes: CallContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, method_name, static) ⇒ Method

Returns a new instance of Method.



6
7
8
9
# File 'lib/jruby-prof/method.rb', line 6

def initialize(class_name, method_name, static)
  @class_name, @method_name, @static = class_name, method_name, static
  @invocations = []
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



4
5
6
# File 'lib/jruby-prof/method.rb', line 4

def class_name
  @class_name
end

#invocationsObject (readonly)

Returns the value of attribute invocations.



4
5
6
# File 'lib/jruby-prof/method.rb', line 4

def invocations
  @invocations
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



4
5
6
# File 'lib/jruby-prof/method.rb', line 4

def method_name
  @method_name
end

Instance Method Details

#add_invocation(inv) ⇒ Object



19
20
21
# File 'lib/jruby-prof/method.rb', line 19

def add_invocation(inv)
  invocations << inv
end

#child_contextsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/jruby-prof/method.rb', line 68

def child_contexts
  @child_contexts ||= begin
    h = {}
    invocations.each do |inv| 
      inv.children.each do |inv2|
        h[inv2.name] ||= CallContext.new(inv2.name)
        cc = h[inv2.name]
        cc.duration           += inv2.duration
        cc.childrens_duration += inv2.childrens_duration
        cc.count              += inv2.count
      end
    end
    h.values
  end
end

#childrens_durationObject



39
40
41
# File 'lib/jruby-prof/method.rb', line 39

def childrens_duration
  invocations.inject(0) {|m, inv| m + inv.children.inject(0) {|m1, inv1| m1 + inv1.duration }}
end

#countObject



31
32
33
34
35
36
37
# File 'lib/jruby-prof/method.rb', line 31

def count
  if toplevel?
    1
  else
    invocations.inject(0) {|m, inv| m + inv.count}
  end
end

#durationObject



23
24
25
26
27
28
29
# File 'lib/jruby-prof/method.rb', line 23

def duration
  if toplevel?
    childrens_duration
  else
    invocations.inject(0) {|m, inv| m + inv.duration}
  end
end

#inspectObject



100
101
102
# File 'lib/jruby-prof/method.rb', line 100

def inspect
  "#<JRubyProf::Method #{class_name} #{method_name}>"
end

#nameObject



43
44
45
# File 'lib/jruby-prof/method.rb', line 43

def name
  "#{class_name}#{static? ? "." : "#"}#{method_name || "toplevel"}"
end

#parent_contextsObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/jruby-prof/method.rb', line 84

def parent_contexts
  @parent_contexts ||= begin
    h = {}
    invocations.each do |inv| 
      inv2 = inv.parent
      next unless inv2
      h[inv2.name] ||= CallContext.new(inv2.name)
      cc = h[inv2.name]
      cc.duration           += inv.duration
      cc.childrens_duration += inv.childrens_duration
      cc.count              += inv.count
    end
    h.values
  end
end

#static?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/jruby-prof/method.rb', line 11

def static?
  @static
end

#toplevel?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/jruby-prof/method.rb', line 15

def toplevel?
  method_name == nil
end