ruby-prof 0.15.5 → 0.15.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,12 +48,11 @@ module RubyProf
48
48
  # Print each method in total time order
49
49
  methods.reverse_each do |method|
50
50
  total_percentage = (method.total_time/total_time) * 100
51
- self_percentage = (method.self_time/total_time) * 100
52
-
53
51
  next if total_percentage < min_percent
54
52
 
55
- @output << "-" * 80 << "\n"
53
+ self_percentage = (method.self_time/total_time) * 100
56
54
 
55
+ @output << "-" * 80 << "\n"
57
56
  print_parents(thread, method)
58
57
 
59
58
  # 1 is for % sign
@@ -71,7 +70,9 @@ module RubyProf
71
70
  end
72
71
  @output << "\n"
73
72
 
73
+ method.recalc_recursion unless method.non_recursive?
74
74
  print_children(method)
75
+ thread.recalc_recursion unless method.non_recursive?
75
76
  end
76
77
  end
77
78
 
@@ -8,28 +8,7 @@ module RubyProf
8
8
  # a hook to do any necessary post-processing on the call graph.
9
9
  def post_process
10
10
  self.threads.each do |thread|
11
- detect_recursion(thread)
12
- end
13
- end
14
-
15
- # This method detect recursive calls in the call graph.
16
- def detect_recursion(thread)
17
- visited_methods = Hash.new do |hash, key|
18
- hash[key] = 0
19
- end
20
-
21
- visitor = CallInfoVisitor.new(thread)
22
- visitor.visit do |call_info, event|
23
- case event
24
- when :enter
25
- if (visited_methods[call_info.target] += 1) > 1
26
- call_info.recursive = true
27
- end
28
- when :exit
29
- if (visited_methods[call_info.target] -= 1) == 0
30
- visited_methods.delete(call_info.target)
31
- end
32
- end
11
+ thread.detect_recursion
33
12
  end
34
13
  end
35
14
 
@@ -2,12 +2,24 @@ module RubyProf
2
2
  class Thread
3
3
  def top_methods
4
4
  self.methods.select do |method_info|
5
- method_info.call_infos.detect do |call_info|
6
- call_info.parent.nil?
7
- end
5
+ method_info.call_infos.detect(&:root?)
8
6
  end
9
7
  end
10
8
 
9
+ def top_call_infos
10
+ top_methods.map(&:call_infos).flatten.select(&:root?)
11
+ end
12
+
13
+ # This method detect recursive calls in the call tree of a given thread
14
+ # It should be called only once for each thread
15
+ def detect_recursion
16
+ top_call_infos.each(&:detect_recursion)
17
+ end
18
+
19
+ def recalc_recursion
20
+ top_call_infos.each(&:recalc_recursion)
21
+ end
22
+
11
23
  def total_time
12
24
  self.top_methods.inject(0) do |sum, method_info|
13
25
  method_info.call_infos.each do |call_info|
@@ -1,3 +1,3 @@
1
1
  module RubyProf
2
- VERSION = "0.15.5"
2
+ VERSION = "0.15.6"
3
3
  end
@@ -14,7 +14,7 @@ class CallInfoVisitorTest < TestCase
14
14
  RubyProf::C1.hello
15
15
  end
16
16
 
17
- visitor = RubyProf::CallInfoVisitor.new(result.threads.first)
17
+ visitor = RubyProf::CallInfoVisitor.new(result.threads.first.top_call_infos)
18
18
 
19
19
  method_names = Array.new
20
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.5
4
+ version: 0.15.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes