ruby-prof 0.18.0 → 1.2.0

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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +44 -1
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +111 -128
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_aggregate_call_tree.c +41 -0
  9. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  10. data/ext/ruby_prof/rp_allocation.c +259 -0
  11. data/ext/ruby_prof/rp_allocation.h +31 -0
  12. data/ext/ruby_prof/rp_call_tree.c +353 -0
  13. data/ext/ruby_prof/rp_call_tree.h +43 -0
  14. data/ext/ruby_prof/rp_call_trees.c +266 -0
  15. data/ext/ruby_prof/rp_call_trees.h +29 -0
  16. data/ext/ruby_prof/rp_measure_allocations.c +25 -51
  17. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  18. data/ext/ruby_prof/rp_measure_process_time.c +37 -43
  19. data/ext/ruby_prof/rp_measure_wall_time.c +40 -21
  20. data/ext/ruby_prof/rp_measurement.c +221 -0
  21. data/ext/ruby_prof/rp_measurement.h +50 -0
  22. data/ext/ruby_prof/rp_method.c +279 -439
  23. data/ext/ruby_prof/rp_method.h +33 -45
  24. data/ext/ruby_prof/rp_profile.c +902 -0
  25. data/ext/ruby_prof/rp_profile.h +36 -0
  26. data/ext/ruby_prof/rp_stack.c +163 -132
  27. data/ext/ruby_prof/rp_stack.h +18 -28
  28. data/ext/ruby_prof/rp_thread.c +192 -124
  29. data/ext/ruby_prof/rp_thread.h +18 -8
  30. data/ext/ruby_prof/ruby_prof.c +36 -778
  31. data/ext/ruby_prof/ruby_prof.h +11 -45
  32. data/ext/ruby_prof/vc/ruby_prof.vcxproj +18 -12
  33. data/lib/ruby-prof.rb +4 -21
  34. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  35. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  36. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  37. data/lib/ruby-prof/call_tree.rb +57 -0
  38. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  39. data/lib/ruby-prof/compatibility.rb +37 -107
  40. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  41. data/lib/ruby-prof/measurement.rb +17 -0
  42. data/lib/ruby-prof/method_info.rb +47 -90
  43. data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
  44. data/lib/ruby-prof/printers/call_info_printer.rb +24 -12
  45. data/lib/ruby-prof/printers/call_stack_printer.rb +66 -152
  46. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  47. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  48. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  49. data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
  50. data/lib/ruby-prof/printers/graph_printer.rb +11 -14
  51. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  52. data/lib/ruby-prof/profile.rb +10 -3
  53. data/lib/ruby-prof/thread.rb +5 -20
  54. data/lib/ruby-prof/version.rb +1 -1
  55. data/ruby-prof.gemspec +9 -2
  56. data/test/abstract_printer_test.rb +0 -27
  57. data/test/alias_test.rb +126 -0
  58. data/test/basic_test.rb +1 -86
  59. data/test/call_tree_visitor_test.rb +32 -0
  60. data/test/call_trees_test.rb +66 -0
  61. data/test/dynamic_method_test.rb +0 -2
  62. data/test/exclude_methods_test.rb +17 -12
  63. data/test/fiber_test.rb +214 -23
  64. data/test/gc_test.rb +105 -0
  65. data/test/inverse_call_tree_test.rb +175 -0
  66. data/test/line_number_test.rb +118 -40
  67. data/test/marshal_test.rb +115 -0
  68. data/test/measure_allocations.rb +30 -0
  69. data/test/measure_allocations_test.rb +361 -12
  70. data/test/measure_allocations_trace_test.rb +375 -0
  71. data/test/measure_memory_trace_test.rb +1101 -0
  72. data/test/measure_process_time_test.rb +757 -33
  73. data/test/measure_times.rb +56 -0
  74. data/test/measure_wall_time_test.rb +329 -149
  75. data/test/multi_printer_test.rb +1 -34
  76. data/test/pause_resume_test.rb +24 -15
  77. data/test/prime.rb +1 -1
  78. data/test/prime_script.rb +6 -0
  79. data/test/printer_call_stack_test.rb +28 -0
  80. data/test/printer_call_tree_test.rb +31 -0
  81. data/test/printer_flat_test.rb +68 -0
  82. data/test/printer_graph_html_test.rb +60 -0
  83. data/test/printer_graph_test.rb +41 -0
  84. data/test/printers_test.rb +32 -166
  85. data/test/printing_recursive_graph_test.rb +26 -72
  86. data/test/recursive_test.rb +68 -77
  87. data/test/stack_printer_test.rb +2 -15
  88. data/test/start_stop_test.rb +22 -25
  89. data/test/test_helper.rb +6 -261
  90. data/test/thread_test.rb +11 -54
  91. data/test/unique_call_path_test.rb +25 -107
  92. data/test/yarv_test.rb +1 -0
  93. metadata +43 -41
  94. data/examples/flat.txt +0 -50
  95. data/examples/graph.dot +0 -84
  96. data/examples/graph.html +0 -823
  97. data/examples/graph.txt +0 -139
  98. data/examples/multi.flat.txt +0 -23
  99. data/examples/multi.graph.html +0 -760
  100. data/examples/multi.grind.dat +0 -114
  101. data/examples/multi.stack.html +0 -547
  102. data/examples/stack.html +0 -547
  103. data/ext/ruby_prof/rp_call_info.c +0 -425
  104. data/ext/ruby_prof/rp_call_info.h +0 -53
  105. data/ext/ruby_prof/rp_measure.c +0 -40
  106. data/ext/ruby_prof/rp_measure.h +0 -45
  107. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  108. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  109. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  110. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  111. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  112. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  113. data/lib/ruby-prof/call_info.rb +0 -115
  114. data/lib/ruby-prof/call_info_visitor.rb +0 -40
  115. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  116. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  117. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  118. data/test/aggregate_test.rb +0 -136
  119. data/test/block_test.rb +0 -74
  120. data/test/call_info_test.rb +0 -78
  121. data/test/call_info_visitor_test.rb +0 -31
  122. data/test/issue137_test.rb +0 -63
  123. data/test/measure_cpu_time_test.rb +0 -212
  124. data/test/measure_gc_runs_test.rb +0 -32
  125. data/test/measure_gc_time_test.rb +0 -36
  126. data/test/measure_memory_test.rb +0 -33
  127. data/test/method_elimination_test.rb +0 -84
  128. data/test/module_test.rb +0 -45
  129. data/test/stack_test.rb +0 -138
@@ -25,45 +25,43 @@ end
25
25
  # --- expected test output ---
26
26
  =begin
27
27
  Measure Mode: wall_time
28
- Thread ID: 70238775664960
29
- Fiber ID: 70238784046840
30
- Total Time: 2.040249824523926
31
- Sort by: total_time
28
+ Thread ID: 1307675084040
29
+ Fiber ID: 1307708787440
30
+ Total Time: 2.0939999999973224
31
+ Sort by:
32
32
 
33
- %total %self total self wait child calls Name
33
+ %total %self total self wait child calls name
34
34
  --------------------------------------------------------------------------------
35
- 100.00% 0.00% 2.040 0.000 0.000 2.040 1 PrintingRecursiveGraphTest#setup
36
- 2.040 0.000 0.000 2.040 1/1 PRGT#run
35
+ 1.657 0.000 0.000 1.657 2/2 Integer#times
36
+ 79.13% 0.00% 1.657 0.000 0.000 1.657 2 PRGT#g
37
+ 1.657 0.000 0.000 1.657 2/5 Integer#times
37
38
  --------------------------------------------------------------------------------
38
- 2.040 0.000 0.000 2.040 1/1 PrintingRecursiveGraphTest#setup
39
- 100.00% 0.00% 2.040 0.000 0.000 2.040 1 PRGT#run
40
- 2.040 0.000 0.000 2.040 1/5 Integer#times
39
+ 2.094 2.094 0.000 0.000 12/12 Integer#times
40
+ 100.00% 100.00% 2.094 2.094 0.000 0.000 12 Kernel#sleep
41
41
  --------------------------------------------------------------------------------
42
- 0.409 0.000 0.000 0.409 2/5 Prgt#f
43
- 1.631 0.000 0.000 1.631 2/5 PRGT#g
44
- 2.040 0.000 0.000 2.040 1/5 PRGT#run
45
- 100.00% 0.00% 2.040 0.000 0.000 2.040 5 *Integer#times
46
- 2.040 2.040 0.000 0.000 12/12 Kernel#sleep
47
- 1.631 0.000 0.000 1.631 2/2 PRGT#g
48
- 0.409 0.000 0.000 0.409 2/2 PRGT#f
42
+ 0.437 0.000 0.000 0.437 2/2 Integer#times
43
+ 20.87% 0.00% 0.437 0.000 0.000 0.437 2 PRGT#f
44
+ 0.437 0.000 0.000 0.437 2/5 Integer#times
49
45
  --------------------------------------------------------------------------------
50
- 2.040 2.040 0.000 0.000 12/12 Integer#times
51
- 99.99% 99.99% 2.040 2.040 0.000 0.000 12 Kernel#sleep
46
+ 0.437 0.000 0.000 0.437 2/5 PRGT#f
47
+ 1.657 0.000 0.000 1.657 2/5 PRGT#g
48
+ 2.094 0.000 0.000 2.094 1/5 PRGT#run
49
+ 100.00% 0.00% 2.094 0.000 0.000 2.094 5 *Integer#times
50
+ 2.094 2.094 0.000 0.000 12/12 Kernel#sleep
51
+ 1.657 0.000 0.000 1.657 2/2 PRGT#g
52
+ 0.437 0.000 0.000 0.437 2/2 PRGT#f
52
53
  --------------------------------------------------------------------------------
53
- 1.631 0.000 0.000 1.631 2/2 Integer#times
54
- 79.94% 0.00% 1.631 0.000 0.000 1.631 2 PRGT#g
55
- 1.631 0.000 0.000 1.631 2/5 Integer#times
54
+ 2.094 0.000 0.000 2.094 1/1 PrintingRecursiveGraphTest#setup
55
+ 100.00% 0.00% 2.094 0.000 0.000 2.094 1 PRGT#run
56
+ 2.094 0.000 0.000 2.094 1/5 Integer#times
56
57
  --------------------------------------------------------------------------------
57
- 0.409 0.000 0.000 0.409 2/2 Integer#times
58
- 20.05% 0.00% 0.409 0.000 0.000 0.409 2 PRGT#f
59
- 0.409 0.000 0.000 0.409 2/5 Integer#times
58
+ 100.00% 0.00% 2.094 0.000 0.000 2.094 1 PrintingRecursiveGraphTest#setup
59
+ 2.094 0.000 0.000 2.094 1/1 PRGT#run
60
60
 
61
61
  * indicates recursively called methods
62
62
  =end
63
63
 
64
64
  class PrintingRecursiveGraphTest < TestCase
65
- include PrinterTestHelper
66
-
67
65
  def setup
68
66
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
69
67
  RubyProf::measure_mode = RubyProf::WALL_TIME
@@ -74,54 +72,10 @@ class PrintingRecursiveGraphTest < TestCase
74
72
 
75
73
  def test_printing_rescursive_graph
76
74
  printer = RubyProf::GraphPrinter.new(@result)
77
-
78
75
  buffer = ''
79
76
  printer.print(StringIO.new(buffer))
80
-
81
77
  puts buffer if ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1"
82
78
 
83
- parsed_output = MetricsArray.parse(buffer)
84
-
85
- assert( integer_times = parsed_output.metrics_for("*Integer#times") )
86
-
87
- actual_parents = integer_times.parents.map(&:name)
88
- expected_parents = %w(PRGT#f PRGT#g PRGT#run)
89
- assert_equal expected_parents, actual_parents
90
-
91
- actual_children = integer_times.children.map(&:name)
92
- expected_children = %w(Kernel#sleep PRGT#g PRGT#f)
93
- assert_equal expected_children, actual_children
94
-
95
- assert( fp = integer_times.parent("PRGT#f") )
96
- assert_in_delta(fp.total, fp.child, 0.01)
97
- assert_equal("2/5", fp.calls)
98
-
99
- assert( gp = integer_times.parent("PRGT#g") )
100
- assert_in_delta(gp.total, gp.child, 0.01)
101
- assert_equal("2/5", gp.calls)
102
-
103
- assert( rp = integer_times.parent("PRGT#run") )
104
- assert_in_delta(rp.total, rp.child, 0.01)
105
- assert_equal("1/5", rp.calls)
106
-
107
- assert_in_delta(4*fp.total, gp.total, 0.05)
108
- assert_in_delta(fp.total + gp.total, rp.total, 0.05)
109
- assert_in_delta(integer_times.metrics.total, rp.total, 0.05)
110
-
111
- assert( fc = integer_times.child("PRGT#f") )
112
- assert_in_delta(fc.total, fc.child, 0.01)
113
- assert_equal("2/2", fc.calls)
114
-
115
- assert( gc = integer_times.child("PRGT#g") )
116
- assert_in_delta(gc.total, gc.child, 0.01)
117
- assert_equal("2/2", gc.calls)
118
-
119
- assert( ks = integer_times.child("Kernel#sleep") )
120
- assert_in_delta(ks.total, ks.self_t, 0.01)
121
- assert_equal("12/12", ks.calls)
122
-
123
- assert_in_delta(4*fc.total, gc.total, 0.05)
124
- assert_in_delta(fp.total + gc.total, ks.total, 0.05)
125
- assert_in_delta(integer_times.metrics.total, ks.total, 0.05)
79
+ refute_nil(buffer)
126
80
  end
127
81
  end
@@ -7,12 +7,10 @@ module SimpleRecursion
7
7
  # Simple recursive test
8
8
  def simple(n)
9
9
  sleep(1)
10
- n -= 1
11
10
  return if n == 0
12
- simple(n)
11
+ simple(n-1)
13
12
  end
14
13
 
15
-
16
14
  # More complicated recursive test
17
15
  def render_partial(i)
18
16
  sleep(1)
@@ -44,12 +42,9 @@ class RecursiveTest < TestCase
44
42
 
45
43
  def test_simple
46
44
  result = RubyProf.profile do
47
- simple(2)
45
+ simple(1)
48
46
  end
49
47
 
50
- # Remove Fixnum+, Fixnum== for less than Ruby 1.9
51
- result.eliminate_methods!(%w(Fixnum#== Fixnum#-))
52
-
53
48
  methods = result.threads.first.methods.sort.reverse
54
49
  assert_equal(3, methods.length)
55
50
 
@@ -57,56 +52,58 @@ class RecursiveTest < TestCase
57
52
  method = methods[0]
58
53
  assert_equal('RecursiveTest#test_simple', method.full_name)
59
54
  assert_equal(1, method.called)
55
+ refute(method.recursive?)
60
56
  assert_in_delta(2, method.total_time, 0.1)
61
57
  assert_in_delta(0, method.self_time, 0.01)
62
58
  assert_in_delta(0, method.wait_time, 0.01)
63
59
  assert_in_delta(2, method.children_time, 0.1)
64
60
 
65
- assert_equal(1, method.call_infos.length)
66
- call_info = method.call_infos[0]
67
- assert(!call_info.recursive?)
68
- assert_equal('RecursiveTest#test_simple', call_info.call_sequence)
69
- assert_equal(1, call_info.children.length)
61
+ assert_equal(0, method.call_trees.callers.length)
62
+
63
+ assert_equal(1, method.call_trees.callees.length)
64
+ call_tree = method.call_trees.callees[0]
65
+ assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
70
66
 
71
67
  # Method 1: SimpleRecursion#simple
72
68
  method = methods[1]
73
69
  assert_equal('SimpleRecursion#simple', method.full_name)
74
70
  assert_equal(2, method.called)
71
+ assert(method.recursive?)
75
72
  assert_in_delta(2, method.total_time, 0.1)
76
73
  assert_in_delta(0, method.self_time, 0.1)
77
74
  assert_in_delta(0, method.wait_time, 0.1)
78
75
  assert_in_delta(2, method.children_time, 0.1)
79
76
 
80
- assert_equal(2, method.call_infos.length)
77
+ assert_equal(2, method.call_trees.callers.length)
78
+ call_tree = method.call_trees.callers[0]
79
+ assert_equal('RecursiveTest#test_simple', call_tree.parent.target.full_name)
81
80
 
82
- call_info = method.call_infos.first
83
- assert_equal(2, call_info.children.length)
84
- assert_equal('RecursiveTest#test_simple->SimpleRecursion#simple', call_info.call_sequence)
85
- assert(!call_info.recursive?)
81
+ call_tree = method.call_trees.callers[1]
82
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
86
83
 
87
- call_info = method.call_infos.last
88
- assert_equal(1, call_info.children.length)
89
- assert_equal('RecursiveTest#test_simple->SimpleRecursion#simple->SimpleRecursion#simple', call_info.call_sequence)
90
- assert(call_info.recursive?)
84
+ assert_equal(2, method.call_trees.callees.length)
85
+ call_tree = method.call_trees.callees[0]
86
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
91
87
 
88
+ call_tree = method.call_trees.callees[1]
89
+ assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
90
+
91
+ # Method 2: Kernel#sleep
92
92
  method = methods[2]
93
93
  assert_equal('Kernel#sleep', method.full_name)
94
94
  assert_equal(2, method.called)
95
+ refute(method.recursive?)
95
96
  assert_in_delta(2, method.total_time, 0.1)
96
97
  assert_in_delta(2, method.self_time, 0.1)
97
98
  assert_in_delta(0, method.wait_time, 0.1)
98
99
  assert_in_delta(0, method.children_time, 0.1)
99
100
 
100
- assert_equal(2, method.call_infos.length)
101
- call_info = method.call_infos[0]
102
- assert_equal('RecursiveTest#test_simple->SimpleRecursion#simple->Kernel#sleep', call_info.call_sequence)
103
- assert_equal(0, call_info.children.length)
104
- assert(!call_info.recursive?)
101
+ assert_equal(1, method.call_trees.callers.length)
102
+ call_tree = method.call_trees.callers[0]
103
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
104
+ assert_equal(0, method.call_trees.callees.length)
105
105
 
106
- call_info = method.call_infos[1]
107
- assert_equal('RecursiveTest#test_simple->SimpleRecursion#simple->SimpleRecursion#simple->Kernel#sleep', call_info.call_sequence)
108
- assert_equal(0, call_info.children.length)
109
- assert(!call_info.recursive?)
106
+ assert_equal(0, method.call_trees.callees.length)
110
107
  end
111
108
 
112
109
  def test_cycle
@@ -120,96 +117,90 @@ class RecursiveTest < TestCase
120
117
  method = methods[0]
121
118
  assert_equal('RecursiveTest#test_cycle', method.full_name)
122
119
  assert_equal(1, method.called)
120
+ refute(method.recursive?)
123
121
  assert_in_delta(5, method.total_time, 0.1)
124
122
  assert_in_delta(0, method.self_time, 0.01)
125
123
  assert_in_delta(0, method.wait_time, 0.01)
126
124
  assert_in_delta(5, method.children_time, 0.1)
127
125
 
128
- assert_equal(1, method.call_infos.length)
129
- call_info = method.call_infos[0]
130
- assert_equal('RecursiveTest#test_cycle', call_info.call_sequence)
131
- assert_equal(1, call_info.children.length)
132
- assert(!call_info.recursive?)
126
+ assert_equal(0, method.call_trees.callers.length)
127
+
128
+ assert_equal(1, method.call_trees.callees.length)
129
+ call_tree = method.call_trees.callees[0]
130
+ assert_equal('SimpleRecursion#render', call_tree.target.full_name)
133
131
 
134
132
  method = methods[1]
135
133
  assert_equal('SimpleRecursion#render', method.full_name)
136
134
  assert_equal(1, method.called)
135
+ refute(method.recursive?)
137
136
  assert_in_delta(5, method.total_time, 0.1)
138
137
  assert_in_delta(0, method.self_time, 0.01)
139
138
  assert_in_delta(0, method.wait_time, 0.01)
140
139
  assert_in_delta(5, method.children_time, 0.1)
141
140
 
142
- assert_equal(1, method.call_infos.length)
143
- call_info = method.call_infos[0]
144
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render', call_info.call_sequence)
145
- assert_equal(1, call_info.children.length)
146
- assert(!call_info.recursive?)
141
+ assert_equal(1, method.call_trees.callers.length)
142
+ call_tree = method.call_trees.callers[0]
143
+ assert_equal('RecursiveTest#test_cycle', call_tree.parent.target.full_name)
144
+
145
+ assert_equal(1, method.call_trees.callees.length)
146
+ call_tree = method.call_trees.callees[0]
147
+ assert_equal('Integer#times', call_tree.target.full_name)
147
148
 
148
149
  method = methods[2]
149
150
  assert_equal('Integer#times', method.full_name)
150
151
  assert_equal(2, method.called)
152
+ assert(method.recursive?)
151
153
  assert_in_delta(5, method.total_time, 0.1)
152
154
  assert_in_delta(0, method.self_time, 0.1)
153
155
  assert_in_delta(0, method.wait_time, 0.1)
154
156
  assert_in_delta(5, method.children_time, 0.1)
155
157
 
156
- assert_equal(2, method.call_infos.length)
157
- call_info = method.call_infos[0]
158
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times', call_info.call_sequence)
159
- assert_equal(1, call_info.children.length)
160
- assert(!call_info.recursive?)
158
+ assert_equal(2, method.call_trees.callers.length)
159
+ call_tree = method.call_trees.callers[0]
160
+ assert_equal('SimpleRecursion#render', call_tree.parent.target.full_name)
161
+
162
+ call_tree = method.call_trees.callers[1]
163
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
161
164
 
162
- call_info = method.call_infos[1]
163
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial->Integer#times', call_info.call_sequence)
164
- assert_equal(1, call_info.children.length)
165
- assert(call_info.recursive?)
165
+ assert_equal(1, method.call_trees.callees.length)
166
+ call_tree = method.call_trees.callees[0]
167
+ assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
166
168
 
167
169
  method = methods[3]
168
170
  assert_equal('SimpleRecursion#render_partial', method.full_name)
169
171
  assert_equal(5, method.called)
172
+ assert(method.recursive?)
170
173
  assert_in_delta(5, method.total_time, 0.1)
171
174
  assert_in_delta(0, method.self_time, 0.1)
172
175
  assert_in_delta(0, method.wait_time, 0.01)
173
176
  assert_in_delta(5, method.children_time, 0.05)
174
177
 
175
- assert_equal(3, method.call_infos.length)
176
- call_info = method.call_infos[0]
177
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial', call_info.call_sequence)
178
- assert_equal(3, call_info.children.length)
179
- assert(!call_info.recursive?)
178
+ assert_equal(2, method.call_trees.callers.length)
179
+ call_tree = method.call_trees.callers[0]
180
+ assert_equal('Integer#times', call_tree.parent.target.full_name)
181
+
182
+ call_tree = method.call_trees.callers[1]
183
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
184
+
185
+ assert_equal(3, method.call_trees.callees.length)
186
+ call_tree = method.call_trees.callees[0]
187
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
180
188
 
181
- call_info = method.call_infos[1]
182
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial->SimpleRecursion#render_partial', call_info.call_sequence)
183
- assert_equal(1, call_info.children.length)
184
- assert(call_info.recursive?)
189
+ call_tree = method.call_trees.callees[1]
190
+ assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
185
191
 
186
- call_info = method.call_infos[2]
187
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial->Integer#times->SimpleRecursion#render_partial', call_info.call_sequence)
188
- assert_equal(1, call_info.children.length)
189
- assert(call_info.recursive?)
192
+ call_tree = method.call_trees.callees[2]
193
+ assert_equal('Integer#times', call_tree.target.full_name)
190
194
 
191
195
  method = methods[4]
192
196
  assert_equal('Kernel#sleep', method.full_name)
193
197
  assert_equal(5, method.called)
198
+ refute(method.recursive?)
194
199
  assert_in_delta(5, method.total_time, 0.1)
195
200
  assert_in_delta(5, method.self_time, 0.1)
196
201
  assert_in_delta(0, method.wait_time, 0.01)
197
202
  assert_in_delta(0, method.children_time, 0.01)
198
203
 
199
- assert_equal(3, method.call_infos.length)
200
- call_info = method.call_infos[0]
201
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial->Kernel#sleep', call_info.call_sequence)
202
- assert_equal(0, call_info.children.length)
203
- assert(!call_info.recursive?)
204
-
205
- call_info = method.call_infos[1]
206
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial->SimpleRecursion#render_partial->Kernel#sleep', call_info.call_sequence)
207
- assert_equal(0, call_info.children.length)
208
- assert(!call_info.recursive?)
209
-
210
- call_info = method.call_infos[2]
211
- assert_equal('RecursiveTest#test_cycle->SimpleRecursion#render->Integer#times->SimpleRecursion#render_partial->Integer#times->SimpleRecursion#render_partial->Kernel#sleep', call_info.call_sequence)
212
- assert_equal(0, call_info.children.length)
213
- assert(!call_info.recursive?)
204
+ assert_equal(0, method.call_trees.callees.length)
214
205
  end
215
206
  end
@@ -41,7 +41,7 @@ class StackPrinterTest < TestCase
41
41
  expected_time = end_time - start_time
42
42
 
43
43
  file_contents = nil
44
- assert_nothing_raised { file_contents = print(result) }
44
+ file_contents = print(result)
45
45
  re = /Thread: (\d+)(, Fiber: (\d+))? \([\.0-9]+.[\.0-9]+% ~ ([\.0-9]+)\)/
46
46
  assert_match(re, file_contents)
47
47
  file_contents =~ re
@@ -49,23 +49,10 @@ class StackPrinterTest < TestCase
49
49
  assert_in_delta(expected_time, actual_time, 0.1)
50
50
  end
51
51
 
52
- def test_method_elimination
53
- RubyProf.start
54
- 5.times{STPT.new.a}
55
- result = RubyProf.stop
56
- assert_nothing_raised {
57
- # result.dump
58
- result.eliminate_methods!([/Integer#times/])
59
- # $stderr.puts "================================"
60
- # result.dump
61
- print(result)
62
- }
63
- end
64
-
65
52
  private
66
53
  def print(result)
67
54
  test = caller.first =~ /in `(.*)'/ ? $1 : "test"
68
- testfile_name = "#{RubyProf.tmpdir}/ruby_prof_#{test}.html"
55
+ testfile_name = "#{Dir.tmpdir}/ruby_prof_#{test}.html"
69
56
  # puts "printing to #{testfile_name}"
70
57
  printer = RubyProf::CallStackPrinter.new(result)
71
58
  File.open(testfile_name, "w") {|f| printer.print(f, :threshold => 0, :min_percent => 0, :title => "ruby_prof #{test}")}
@@ -39,24 +39,15 @@ class StartStopTest < TestCase
39
39
  end
40
40
  end
41
41
 
42
-
43
42
  def test_different_methods
44
43
  method1
45
44
 
46
45
  # Ruby prof should be stopped
47
46
  assert_equal(false, RubyProf.running?)
48
47
 
49
-
50
- # Length should be 4:
51
- # StartStopTest#method1
52
- # StartStopTest#method2
53
- # StartStopTest#method3
54
- # Kernel#sleep
55
-
56
48
  methods = @result.threads.first.methods.sort.reverse
57
49
  assert_equal(4, methods.length)
58
50
 
59
- # Check StackTest#test_call_sequence
60
51
  method = methods[0]
61
52
  assert_equal('StartStopTest#method1', method.full_name)
62
53
  assert_equal(1, method.called)
@@ -64,11 +55,10 @@ class StartStopTest < TestCase
64
55
  assert_in_delta(0, method.wait_time, 0.02)
65
56
  assert_in_delta(0, method.self_time, 0.02)
66
57
  assert_in_delta(2, method.children_time, 0.05)
67
- assert_equal(1, method.call_infos.length)
68
58
 
69
- call_info = method.call_infos[0]
70
- assert_equal('StartStopTest#method1', call_info.call_sequence)
71
- assert_equal(1, call_info.children.length)
59
+ assert_equal(1, method.call_trees.callees.length)
60
+ call_tree = method.call_trees.callees[0]
61
+ assert_equal('StartStopTest#method2', call_tree.target.full_name)
72
62
 
73
63
  method = methods[1]
74
64
  assert_equal('StartStopTest#method2', method.full_name)
@@ -77,11 +67,14 @@ class StartStopTest < TestCase
77
67
  assert_in_delta(0, method.wait_time, 0.02)
78
68
  assert_in_delta(0, method.self_time, 0.02)
79
69
  assert_in_delta(2, method.children_time, 0.05)
80
- assert_equal(1, method.call_infos.length)
81
70
 
82
- call_info = method.call_infos[0]
83
- assert_equal('StartStopTest#method1->StartStopTest#method2', call_info.call_sequence)
84
- assert_equal(1, call_info.children.length)
71
+ assert_equal(1, method.call_trees.callers.length)
72
+ call_tree = method.call_trees.callers[0]
73
+ assert_equal('StartStopTest#method1', call_tree.parent.target.full_name)
74
+
75
+ assert_equal(1, method.call_trees.callees.length)
76
+ call_tree = method.call_trees.callees[0]
77
+ assert_equal('StartStopTest#method3', call_tree.target.full_name)
85
78
 
86
79
  method = methods[2]
87
80
  assert_equal('StartStopTest#method3', method.full_name)
@@ -90,11 +83,14 @@ class StartStopTest < TestCase
90
83
  assert_in_delta(0, method.wait_time, 0.02)
91
84
  assert_in_delta(0, method.self_time, 0.02)
92
85
  assert_in_delta(2, method.children_time, 0.02)
93
- assert_equal(1, method.call_infos.length)
94
86
 
95
- call_info = method.call_infos[0]
96
- assert_equal('StartStopTest#method1->StartStopTest#method2->StartStopTest#method3', call_info.call_sequence)
97
- assert_equal(1, call_info.children.length)
87
+ assert_equal(1, method.call_trees.callers.length)
88
+ call_tree = method.call_trees.callers[0]
89
+ assert_equal('StartStopTest#method2', call_tree.parent.target.full_name)
90
+
91
+ assert_equal(1, method.call_trees.callees.length)
92
+ call_tree = method.call_trees.callees[0]
93
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
98
94
 
99
95
  method = methods[3]
100
96
  assert_equal('Kernel#sleep', method.full_name)
@@ -103,10 +99,11 @@ class StartStopTest < TestCase
103
99
  assert_in_delta(0, method.wait_time, 0.02)
104
100
  assert_in_delta(2, method.self_time, 0.02)
105
101
  assert_in_delta(0, method.children_time, 0.02)
106
- assert_equal(1, method.call_infos.length)
107
102
 
108
- call_info = method.call_infos[0]
109
- assert_equal('StartStopTest#method1->StartStopTest#method2->StartStopTest#method3->Kernel#sleep', call_info.call_sequence)
110
- assert_equal(0, call_info.children.length)
103
+ assert_equal(1, method.call_trees.callers.length)
104
+ call_tree = method.call_trees.callers[0]
105
+ assert_equal('StartStopTest#method3', call_tree.parent.target.full_name)
106
+
107
+ assert_equal(0, method.call_trees.callees.length)
111
108
  end
112
109
  end