ruby-prof 0.13.1 → 1.4.2

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 (209) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +579 -371
  3. data/LICENSE +24 -23
  4. data/README.rdoc +5 -433
  5. data/Rakefile +98 -110
  6. data/bin/ruby-prof +328 -329
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +16 -59
  9. data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
  10. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  11. data/ext/ruby_prof/rp_allocation.c +287 -0
  12. data/ext/ruby_prof/rp_allocation.h +31 -0
  13. data/ext/ruby_prof/rp_call_tree.c +369 -0
  14. data/ext/ruby_prof/rp_call_tree.h +43 -0
  15. data/ext/ruby_prof/rp_call_trees.c +288 -0
  16. data/ext/ruby_prof/rp_call_trees.h +28 -0
  17. data/ext/ruby_prof/rp_measure_allocations.c +50 -65
  18. data/ext/ruby_prof/rp_measure_memory.c +42 -73
  19. data/ext/ruby_prof/rp_measure_process_time.c +65 -71
  20. data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
  21. data/ext/ruby_prof/rp_measurement.c +237 -0
  22. data/ext/ruby_prof/rp_measurement.h +50 -0
  23. data/ext/ruby_prof/rp_method.c +491 -420
  24. data/ext/ruby_prof/rp_method.h +62 -57
  25. data/ext/ruby_prof/rp_profile.c +908 -0
  26. data/ext/ruby_prof/rp_profile.h +35 -0
  27. data/ext/ruby_prof/rp_stack.c +212 -128
  28. data/ext/ruby_prof/rp_stack.h +53 -51
  29. data/ext/ruby_prof/rp_thread.c +362 -268
  30. data/ext/ruby_prof/rp_thread.h +39 -27
  31. data/ext/ruby_prof/ruby_prof.c +52 -695
  32. data/ext/ruby_prof/ruby_prof.h +26 -55
  33. data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
  34. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
  35. data/lib/ruby-prof.rb +52 -67
  36. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  37. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  38. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  39. data/lib/ruby-prof/call_tree.rb +57 -0
  40. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  41. data/lib/ruby-prof/compatibility.rb +99 -169
  42. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  43. data/lib/ruby-prof/measurement.rb +17 -0
  44. data/lib/ruby-prof/method_info.rb +78 -131
  45. data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
  46. data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
  47. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
  48. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
  49. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  50. data/lib/ruby-prof/printers/flat_printer.rb +53 -69
  51. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
  52. data/lib/ruby-prof/printers/graph_printer.rb +113 -116
  53. data/lib/ruby-prof/printers/multi_printer.rb +127 -56
  54. data/lib/ruby-prof/profile.rb +37 -77
  55. data/lib/ruby-prof/rack.rb +62 -15
  56. data/lib/ruby-prof/task.rb +147 -147
  57. data/lib/ruby-prof/thread.rb +10 -12
  58. data/lib/ruby-prof/version.rb +3 -0
  59. data/lib/unprof.rb +10 -10
  60. data/ruby-prof.gemspec +65 -61
  61. data/test/abstract_printer_test.rb +26 -0
  62. data/test/alias_test.rb +126 -0
  63. data/test/basic_test.rb +43 -128
  64. data/test/call_tree_visitor_test.rb +32 -0
  65. data/test/call_trees_test.rb +66 -0
  66. data/test/duplicate_names_test.rb +32 -32
  67. data/test/dynamic_method_test.rb +53 -74
  68. data/test/enumerable_test.rb +21 -16
  69. data/test/exceptions_test.rb +24 -16
  70. data/test/exclude_methods_test.rb +151 -0
  71. data/test/exclude_threads_test.rb +53 -54
  72. data/test/fiber_test.rb +129 -65
  73. data/test/gc_test.rb +90 -0
  74. data/test/inverse_call_tree_test.rb +175 -0
  75. data/test/line_number_test.rb +158 -71
  76. data/test/marshal_test.rb +113 -0
  77. data/test/measure_allocations.rb +30 -0
  78. data/test/measure_allocations_test.rb +375 -25
  79. data/test/measure_allocations_trace_test.rb +375 -0
  80. data/test/measure_memory_trace_test.rb +1101 -0
  81. data/test/measure_process_time_test.rb +785 -62
  82. data/test/measure_times.rb +56 -0
  83. data/test/measure_wall_time_test.rb +434 -254
  84. data/test/multi_printer_test.rb +71 -82
  85. data/test/no_method_class_test.rb +15 -15
  86. data/test/pause_resume_test.rb +175 -166
  87. data/test/prime.rb +54 -54
  88. data/test/prime_script.rb +6 -0
  89. data/test/printer_call_stack_test.rb +27 -0
  90. data/test/printer_call_tree_test.rb +30 -0
  91. data/test/printer_flat_test.rb +99 -0
  92. data/test/printer_graph_html_test.rb +59 -0
  93. data/test/printer_graph_test.rb +40 -0
  94. data/test/printers_test.rb +141 -257
  95. data/test/printing_recursive_graph_test.rb +81 -0
  96. data/test/profile_test.rb +16 -0
  97. data/test/rack_test.rb +93 -0
  98. data/test/recursive_test.rb +206 -215
  99. data/test/singleton_test.rb +38 -38
  100. data/test/stack_printer_test.rb +64 -78
  101. data/test/start_stop_test.rb +109 -112
  102. data/test/test_helper.rb +13 -115
  103. data/test/thread_test.rb +144 -178
  104. data/test/unique_call_path_test.rb +120 -224
  105. data/test/yarv_test.rb +56 -0
  106. metadata +77 -133
  107. data/doc/LICENSE.html +0 -155
  108. data/doc/README_rdoc.html +0 -648
  109. data/doc/Rack.html +0 -167
  110. data/doc/Rack/RubyProf.html +0 -319
  111. data/doc/RubyProf.html +0 -1000
  112. data/doc/RubyProf/AbstractPrinter.html +0 -580
  113. data/doc/RubyProf/AggregateCallInfo.html +0 -570
  114. data/doc/RubyProf/CallInfo.html +0 -512
  115. data/doc/RubyProf/CallInfoPrinter.html +0 -190
  116. data/doc/RubyProf/CallInfoVisitor.html +0 -332
  117. data/doc/RubyProf/CallStackPrinter.html +0 -1600
  118. data/doc/RubyProf/CallTreePrinter.html +0 -413
  119. data/doc/RubyProf/Cmd.html +0 -669
  120. data/doc/RubyProf/DotPrinter.html +0 -312
  121. data/doc/RubyProf/FlatPrinter.html +0 -229
  122. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
  123. data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
  124. data/doc/RubyProf/GraphPrinter.html +0 -209
  125. data/doc/RubyProf/MethodInfo.html +0 -713
  126. data/doc/RubyProf/MultiPrinter.html +0 -407
  127. data/doc/RubyProf/Profile.html +0 -821
  128. data/doc/RubyProf/ProfileTask.html +0 -532
  129. data/doc/RubyProf/Test.html +0 -578
  130. data/doc/RubyProf/Thread.html +0 -262
  131. data/doc/created.rid +0 -32
  132. data/doc/examples/flat_txt.html +0 -191
  133. data/doc/examples/graph_txt.html +0 -305
  134. data/doc/images/add.png +0 -0
  135. data/doc/images/brick.png +0 -0
  136. data/doc/images/brick_link.png +0 -0
  137. data/doc/images/bug.png +0 -0
  138. data/doc/images/bullet_black.png +0 -0
  139. data/doc/images/bullet_toggle_minus.png +0 -0
  140. data/doc/images/bullet_toggle_plus.png +0 -0
  141. data/doc/images/date.png +0 -0
  142. data/doc/images/delete.png +0 -0
  143. data/doc/images/find.png +0 -0
  144. data/doc/images/loadingAnimation.gif +0 -0
  145. data/doc/images/macFFBgHack.png +0 -0
  146. data/doc/images/package.png +0 -0
  147. data/doc/images/page_green.png +0 -0
  148. data/doc/images/page_white_text.png +0 -0
  149. data/doc/images/page_white_width.png +0 -0
  150. data/doc/images/plugin.png +0 -0
  151. data/doc/images/ruby.png +0 -0
  152. data/doc/images/tag_blue.png +0 -0
  153. data/doc/images/tag_green.png +0 -0
  154. data/doc/images/transparent.png +0 -0
  155. data/doc/images/wrench.png +0 -0
  156. data/doc/images/wrench_orange.png +0 -0
  157. data/doc/images/zoom.png +0 -0
  158. data/doc/index.html +0 -647
  159. data/doc/js/darkfish.js +0 -155
  160. data/doc/js/jquery.js +0 -18
  161. data/doc/js/navigation.js +0 -142
  162. data/doc/js/search.js +0 -94
  163. data/doc/js/search_index.js +0 -1
  164. data/doc/js/searcher.js +0 -228
  165. data/doc/rdoc.css +0 -543
  166. data/doc/table_of_contents.html +0 -462
  167. data/examples/empty.png +0 -0
  168. data/examples/flat.txt +0 -55
  169. data/examples/graph.dot +0 -106
  170. data/examples/graph.html +0 -823
  171. data/examples/graph.png +0 -0
  172. data/examples/graph.txt +0 -170
  173. data/examples/minus.png +0 -0
  174. data/examples/multi.flat.txt +0 -23
  175. data/examples/multi.graph.html +0 -906
  176. data/examples/multi.grind.dat +0 -194
  177. data/examples/multi.stack.html +0 -573
  178. data/examples/plus.png +0 -0
  179. data/examples/stack.html +0 -573
  180. data/ext/ruby_prof/rp_call_info.c +0 -407
  181. data/ext/ruby_prof/rp_call_info.h +0 -48
  182. data/ext/ruby_prof/rp_measure.c +0 -48
  183. data/ext/ruby_prof/rp_measure.h +0 -45
  184. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
  185. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
  186. data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
  187. data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
  188. data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
  189. data/ext/ruby_prof/version.h +0 -7
  190. data/lib/ruby-prof/aggregate_call_info.rb +0 -72
  191. data/lib/ruby-prof/call_info.rb +0 -89
  192. data/lib/ruby-prof/call_info_visitor.rb +0 -44
  193. data/lib/ruby-prof/images/empty.png +0 -0
  194. data/lib/ruby-prof/images/minus.png +0 -0
  195. data/lib/ruby-prof/images/plus.png +0 -0
  196. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
  197. data/lib/ruby-prof/test.rb +0 -150
  198. data/test/aggregate_test.rb +0 -136
  199. data/test/call_info_test.rb +0 -78
  200. data/test/call_info_visitor_test.rb +0 -31
  201. data/test/exec_test.rb +0 -14
  202. data/test/measure_cpu_time_test.rb +0 -220
  203. data/test/measure_gc_runs_test.rb +0 -32
  204. data/test/measure_gc_time_test.rb +0 -36
  205. data/test/measure_memory_test.rb +0 -31
  206. data/test/method_elimination_test.rb +0 -84
  207. data/test/module_test.rb +0 -45
  208. data/test/stack_test.rb +0 -138
  209. data/test/test_suite.rb +0 -37
@@ -1,178 +1,144 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- require 'timeout'
6
-
7
- # -- Tests ----
8
- class ThreadTest < Test::Unit::TestCase
9
- def setup
10
- # Need to use wall time for this test due to the sleep calls
11
- RubyProf::measure_mode = RubyProf::WALL_TIME
12
- end
13
-
14
- def test_thread_count
15
- RubyProf.start
16
-
17
- thread = Thread.new do
18
- sleep(1)
19
- end
20
-
21
- thread.join
22
- result = RubyProf.stop
23
- assert_equal(2, result.threads.length)
24
- end
25
-
26
- def test_thread_identity
27
- RubyProf.start
28
- sleep_thread = Thread.new do
29
- sleep(1)
30
- end
31
- sleep_thread.join
32
- result = RubyProf.stop
33
-
34
- thread_ids = result.threads.map {|thread| thread.id}.sort
35
- threads = [Thread.current, sleep_thread]
36
- assert_equal(2, result.threads.length)
37
-
38
- assert(thread_ids.include?(threads[0].object_id))
39
- assert(thread_ids.include?(threads[1].object_id))
40
-
41
- assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[0]))
42
- assert(threads.include?(ObjectSpace._id2ref(thread_ids[0])))
43
-
44
- assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[1]))
45
- assert(threads.include?(ObjectSpace._id2ref(thread_ids[1])))
46
- end
47
-
48
- def test_thread_timings
49
- RubyProf.start
50
- thread = Thread.new do
51
- sleep 0 # force it to hit thread.join, below, first
52
- # thus forcing sleep(1), below, to be counted as (wall) self_time
53
- # since we currently count time "in some other thread" as self.wait_time
54
- # for whatever reason
55
- sleep(1)
56
- end
57
- thread.join
58
- result = RubyProf.stop
59
-
60
- # Check background thread
61
- assert_equal(2, result.threads.length)
62
-
63
- rp_thread = result.threads.detect {|athread| athread.id == thread.object_id}
64
- methods = rp_thread.methods.sort.reverse
65
- assert_equal(2, methods.length)
66
-
67
- method = methods[0]
68
- assert_equal('ThreadTest#test_thread_timings', method.full_name)
69
- assert_equal(1, method.called)
70
- assert_in_delta(1, method.total_time, 0.05)
71
- assert_in_delta(0, method.self_time, 0.05)
72
- assert_in_delta(0, method.wait_time, 0.05)
73
- assert_in_delta(1, method.children_time, 0.05)
74
- assert_equal(1, method.call_infos.length)
75
- call_info = method.call_infos[0]
76
- assert_equal('ThreadTest#test_thread_timings', call_info.call_sequence)
77
- assert_equal(1, call_info.children.length)
78
-
79
- method = methods[1]
80
- assert_equal('Kernel#sleep', method.full_name)
81
- assert_equal(2, method.called)
82
- assert_in_delta(1, method.total_time, 0.05)
83
- assert_in_delta(1.0, method.self_time, 0.05)
84
- assert_in_delta(0, method.wait_time, 0.05)
85
- assert_in_delta(0, method.children_time, 0.05)
86
-
87
- assert_equal(1, method.call_infos.length)
88
- call_info = method.call_infos[0]
89
- assert_equal('ThreadTest#test_thread_timings->Kernel#sleep', call_info.call_sequence)
90
- assert_equal(0, call_info.children.length)
91
-
92
- # Check foreground thread
93
- rp_thread = result.threads.detect {|athread| athread.id == Thread.current.object_id}
94
- methods = rp_thread.methods.sort.reverse
95
- assert_equal(4, methods.length)
96
- methods = methods.sort.reverse
97
-
98
- method = methods[0]
99
- assert_equal('ThreadTest#test_thread_timings', method.full_name)
100
- # the sub calls to Object#new, when popped,
101
- # cause the parent frame to be created for method #test_thread_timings, which means a +1 when it's popped in the end
102
- # xxxx a test that shows it the other way, too (never creates parent frame--if that's even possible)
103
- assert_equal(1, method.called)
104
- assert_in_delta(1, method.total_time, 0.05)
105
- assert_in_delta(0, method.self_time, 0.05)
106
- assert_in_delta(0, method.wait_time, 0.05)
107
- assert_in_delta(1, method.children_time, 0.05)
108
-
109
- assert_equal(1, method.call_infos.length)
110
- call_info = method.call_infos[0]
111
- assert_equal('ThreadTest#test_thread_timings', call_info.call_sequence)
112
- assert_equal(2, call_info.children.length)
113
-
114
- method = methods[1]
115
- assert_equal('Thread#join', method.full_name)
116
- assert_equal(1, method.called)
117
- assert_in_delta(1, method.total_time, 0.05)
118
- assert_in_delta(0, method.self_time, 0.05)
119
- assert_in_delta(1.0, method.wait_time, 0.05)
120
- assert_in_delta(0, method.children_time, 0.05)
121
-
122
- assert_equal(1, method.call_infos.length)
123
- call_info = method.call_infos[0]
124
- assert_equal('ThreadTest#test_thread_timings->Thread#join', call_info.call_sequence)
125
- assert_equal(0, call_info.children.length)
126
-
127
- method = methods[2]
128
- assert_equal('<Class::Thread>#new', method.full_name)
129
- assert_equal(1, method.called)
130
- assert_in_delta(0, method.total_time, 0.05)
131
- assert_in_delta(0, method.self_time, 0.05)
132
- assert_in_delta(0, method.wait_time, 0.05)
133
- assert_in_delta(0, method.children_time, 0.05)
134
-
135
- assert_equal(1, method.call_infos.length)
136
- call_info = method.call_infos[0]
137
- assert_equal('ThreadTest#test_thread_timings-><Class::Thread>#new', call_info.call_sequence)
138
- assert_equal(1, call_info.children.length)
139
-
140
- method = methods[3]
141
- assert_equal('Thread#initialize', method.full_name)
142
- assert_equal(1, method.called)
143
- assert_in_delta(0, method.total_time, 0.05)
144
- assert_in_delta(0, method.self_time, 0.05)
145
- assert_in_delta(0, method.wait_time, 0.05)
146
- assert_in_delta(0, method.children_time, 0.05)
147
-
148
- assert_equal(1, method.call_infos.length)
149
- call_info = method.call_infos[0]
150
- assert_equal('ThreadTest#test_thread_timings-><Class::Thread>#new->Thread#initialize', call_info.call_sequence)
151
- assert_equal(0, call_info.children.length)
152
- end
153
-
154
- # useless test
155
- def test_thread_back_and_forth
156
- result = RubyProf.profile do
157
- a = Thread.new { 100_000.times { sleep 0 }}
158
- b = Thread.new { 100_000.times { sleep 0 }}
159
- a.join
160
- b.join
161
- end
162
- methods = result.threads.map {|thread| thread.methods}
163
- assert(methods.flatten.sort[-1].total_time < 10) # 10s. Amazingly, this can fail in OS X at times. Amazing.
164
- end
165
-
166
- def test_thread
167
- RubyProf.profile do
168
- begin
169
- Timeout::timeout(2) do
170
- while true
171
- next
172
- end
173
- end
174
- rescue Timeout::Error
175
- end
176
- end
177
- end
178
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'timeout'
6
+ require 'benchmark'
7
+
8
+ # -- Tests ----
9
+ class ThreadTest < TestCase
10
+ def setup
11
+ # Need to use wall time for this test due to the sleep calls
12
+ RubyProf::measure_mode = RubyProf::WALL_TIME
13
+ end
14
+
15
+ def test_thread_count
16
+ RubyProf.start
17
+
18
+ thread = Thread.new do
19
+ sleep(1)
20
+ end
21
+
22
+ thread.join
23
+ result = RubyProf.stop
24
+ assert_equal(2, result.threads.length)
25
+ end
26
+
27
+ def test_thread_identity
28
+ RubyProf.start
29
+ sleep_thread = Thread.new do
30
+ sleep(1)
31
+ end
32
+ sleep_thread.join
33
+ result = RubyProf.stop
34
+
35
+ thread_ids = result.threads.map {|thread| thread.id}.sort
36
+ threads = [Thread.current, sleep_thread]
37
+ assert_equal(2, result.threads.length)
38
+
39
+ assert(thread_ids.include?(threads[0].object_id))
40
+ assert(thread_ids.include?(threads[1].object_id))
41
+
42
+ assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[0]))
43
+ assert(threads.include?(ObjectSpace._id2ref(thread_ids[0])))
44
+
45
+ assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[1]))
46
+ assert(threads.include?(ObjectSpace._id2ref(thread_ids[1])))
47
+ end
48
+
49
+ def test_thread_timings
50
+ RubyProf.start
51
+ thread = Thread.new do
52
+ sleep 0
53
+ # force it to hit thread.join, below, first
54
+ # thus forcing sleep(1), below, to be counted as (wall) self_time
55
+ # since we currently count time "in some other thread" as self.wait_time
56
+ # for whatever reason
57
+ sleep(1)
58
+ end
59
+ thread.join
60
+ result = RubyProf.stop
61
+
62
+ # Check background thread
63
+ assert_equal(2, result.threads.length)
64
+
65
+ rp_thread = result.threads.detect {|t| t.id == thread.object_id}
66
+ methods = rp_thread.methods.sort.reverse
67
+ # fails on travis. why?
68
+ # expected_methods = ["ThreadTest#test_thread_timings", "Kernel#sleep"]
69
+ # assert_equal(expected_methods, methods.map(&:full_name))
70
+
71
+ method = methods[0]
72
+ assert_equal('ThreadTest#test_thread_timings', method.full_name)
73
+ assert_equal(1, method.called)
74
+ assert_in_delta(1, method.total_time, 0.05)
75
+ assert_in_delta(0, method.self_time, 0.05)
76
+ assert_in_delta(0, method.wait_time, 0.05)
77
+ assert_in_delta(1, method.children_time, 0.05)
78
+ assert_equal(0, method.call_trees.callers.length)
79
+
80
+ method = methods[1]
81
+ assert_equal('Kernel#sleep', method.full_name)
82
+ assert_equal(2, method.called)
83
+ assert_in_delta(1, method.total_time, 0.05)
84
+ assert_in_delta(1.0, method.self_time, 0.05)
85
+ assert_in_delta(0, method.wait_time, 0.05)
86
+ assert_in_delta(0, method.children_time, 0.05)
87
+
88
+ assert_equal(1, method.call_trees.callers.length)
89
+ assert_equal(0, method.call_trees.callees.length)
90
+
91
+ # Check foreground thread
92
+ rp_thread = result.threads.detect {|athread| athread.id == Thread.current.object_id}
93
+ methods = rp_thread.methods.sort.reverse
94
+ assert_equal(4, methods.length)
95
+ methods = methods.sort.reverse
96
+
97
+ method = methods[0]
98
+ assert_equal('ThreadTest#test_thread_timings', method.full_name)
99
+ # the sub calls to Object#new, when popped,
100
+ # cause the parent frame to be created for method #test_thread_timings, which means a +1 when it's popped in the end
101
+ # xxxx a test that shows it the other way, too (never creates parent frame--if that's even possible)
102
+ assert_equal(1, method.called)
103
+ assert_in_delta(1, method.total_time, 0.05)
104
+ assert_in_delta(0, method.self_time, 0.05)
105
+ assert_in_delta(0, method.wait_time, 0.05)
106
+ assert_in_delta(1, method.children_time, 0.05)
107
+
108
+ assert_equal(0, method.call_trees.callers.length)
109
+ assert_equal(2, method.call_trees.callees.length)
110
+
111
+ method = methods[1]
112
+ assert_equal('Thread#join', method.full_name)
113
+ assert_equal(1, method.called)
114
+ assert_in_delta(1, method.total_time, 0.05)
115
+ assert_in_delta(0, method.self_time, 0.05)
116
+ assert_in_delta(1.0, method.wait_time, 0.05)
117
+ assert_in_delta(0, method.children_time, 0.05)
118
+
119
+ assert_equal(1, method.call_trees.callers.length)
120
+ assert_equal(0, method.call_trees.callees.length)
121
+
122
+ method = methods[2]
123
+ assert_equal('<Class::Thread>#new', method.full_name)
124
+ assert_equal(1, method.called)
125
+ assert_in_delta(0, method.total_time, 0.05)
126
+ assert_in_delta(0, method.self_time, 0.05)
127
+ assert_in_delta(0, method.wait_time, 0.05)
128
+ assert_in_delta(0, method.children_time, 0.05)
129
+
130
+ assert_equal(1, method.call_trees.callers.length)
131
+ assert_equal(1, method.call_trees.callees.length)
132
+
133
+ method = methods[3]
134
+ assert_equal('Thread#initialize', method.full_name)
135
+ assert_equal(1, method.called)
136
+ assert_in_delta(0, method.total_time, 0.05)
137
+ assert_in_delta(0, method.self_time, 0.05)
138
+ assert_in_delta(0, method.wait_time, 0.05)
139
+ assert_in_delta(0, method.children_time, 0.05)
140
+
141
+ assert_equal(1, method.call_trees.callers.length)
142
+ assert_equal(0, method.call_trees.callees.length)
143
+ end
144
+ end
@@ -1,224 +1,120 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- class UniqueCallPath
7
- def method_a(i)
8
- if i==1
9
- method_b
10
- else
11
- method_c
12
- end
13
- end
14
-
15
- def method_b
16
- method_c
17
- end
18
-
19
- def method_c
20
- end
21
-
22
- def method_k(i)
23
- method_a(i)
24
- end
25
- end
26
-
27
-
28
- # -- Tests ----
29
- class UniqueCallPathTest < Test::Unit::TestCase
30
- def test_root_method
31
- unique_call_path = UniqueCallPath.new
32
-
33
- result = RubyProf.profile do
34
- unique_call_path.method_a(1)
35
- end
36
-
37
- root_methods = Array.new
38
- result.threads.each do |thread|
39
- thread.methods.each do | m |
40
- if m.root?
41
- root_methods.push(m)
42
- end
43
- end
44
- end
45
-
46
- assert_equal(1, root_methods.length)
47
- assert_equal("UniqueCallPathTest#test_root_method", root_methods[0].full_name)
48
- end
49
-
50
- def test_root_children
51
- unique_call_path = UniqueCallPath.new
52
-
53
- result = RubyProf.profile do
54
- unique_call_path.method_a(1)
55
- unique_call_path.method_k(2)
56
- end
57
-
58
- root_methods = Array.new
59
- result.threads.each do |thread|
60
- thread.methods.each do | m |
61
- if m.root?
62
- root_methods.push(m)
63
- end
64
- end
65
- end
66
-
67
- assert_equal(1, root_methods.length)
68
-
69
- root_children = Array.new
70
- root_methods[0].children.each do | c |
71
- if c.parent.target.eql?(root_methods[0])
72
- root_children.push(c)
73
- end
74
- end
75
-
76
- children = root_children.sort do |c1, c2|
77
- c1.target.full_name <=> c2.target.full_name
78
- end
79
-
80
- assert_equal(2, children.length)
81
- assert_equal("UniqueCallPath#method_a", children[0].target.full_name)
82
- assert_equal("UniqueCallPath#method_k", children[1].target.full_name)
83
- end
84
-
85
- def test_children_of
86
- unique_call_path = UniqueCallPath.new
87
-
88
- result = RubyProf.profile do
89
- unique_call_path.method_a(1)
90
- unique_call_path.method_k(2)
91
- end
92
-
93
- root_methods = Array.new
94
- result.threads.each do |thread|
95
- thread.methods.each do | m |
96
- if m.root?
97
- root_methods.push(m)
98
- end
99
- end
100
- end
101
-
102
- assert_equal(1, root_methods.length)
103
- method = root_methods[0]
104
- assert_equal('UniqueCallPathTest#test_children_of', method.full_name)
105
-
106
- call_info_a = nil
107
- root_methods[0].children.each do | c |
108
- if c.target.full_name == "UniqueCallPath#method_a"
109
- call_info_a = c
110
- break
111
- end
112
- end
113
-
114
- assert !call_info_a.nil?
115
-
116
- children_of_a = Array.new
117
-
118
- call_info_a.children.each do | c |
119
- if c.parent.eql?(call_info_a)
120
- children_of_a.push(c)
121
- end
122
- end
123
-
124
- if RUBY_VERSION < '1.9'
125
- assert_equal(4, call_info_a.target.children.length)
126
- else
127
- assert_equal(2, call_info_a.target.children.length)
128
- end
129
-
130
- children_of_a = children_of_a.sort do |c1, c2|
131
- c1.target.full_name <=> c2.target.full_name
132
- end
133
- if RUBY_VERSION < '1.9'
134
- assert_equal(2, children_of_a.length)
135
- assert_equal("Fixnum#==", children_of_a[0].target.full_name)
136
- assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
137
- else
138
- assert_equal(1, children_of_a.length)
139
- assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
140
- end
141
-
142
- end
143
-
144
- def test_id2ref
145
- unique_call_path = UniqueCallPath.new
146
-
147
- result = RubyProf.profile do
148
- unique_call_path.method_a(1)
149
- end
150
-
151
- root_methods = Array.new
152
- result.threads.each do |thread|
153
- thread.methods.each do | m |
154
- if m.root?
155
- root_methods.push(m)
156
- end
157
- end
158
- end
159
-
160
- child = root_methods[0].children[0]
161
-
162
- assert_not_equal(0, child.object_id)
163
- #assert_equal(RubyProf::CallInfo.id2ref(child.id).target.full_name, child.target.full_name)
164
- end
165
-
166
- def test_unique_path
167
- unique_call_path = UniqueCallPath.new
168
-
169
- result = RubyProf.profile do
170
- unique_call_path.method_a(1)
171
- unique_call_path.method_k(1)
172
- end
173
-
174
- root_methods = Array.new
175
- result.threads.each do |thread|
176
- thread.methods.each do | m |
177
- if m.root?
178
- root_methods.push(m)
179
- end
180
- end
181
- end
182
-
183
- assert_equal(1, root_methods.length)
184
-
185
- call_info_a = nil
186
- root_methods[0].children.each do | c |
187
- if c.target.full_name == "UniqueCallPath#method_a"
188
- call_info_a = c
189
- break
190
- end
191
- end
192
-
193
- assert !call_info_a.nil?
194
-
195
- children_of_a = Array.new
196
- call_info_a.children.each do |c|
197
- if c.parent.eql?(call_info_a)
198
- children_of_a.push(c)
199
- end
200
- end
201
-
202
- if RUBY_VERSION < '1.9'
203
- assert_equal(4, call_info_a.target.children.length)
204
- else
205
- assert_equal(2, call_info_a.target.children.length)
206
- end
207
-
208
- children_of_a = children_of_a.sort do |c1, c2|
209
- c1.target.full_name <=> c2.target.full_name
210
- end
211
-
212
- if RUBY_VERSION < '1.9'
213
- assert_equal(2, children_of_a.length)
214
- assert_equal(1, children_of_a[0].called)
215
- assert_equal("Fixnum#==", children_of_a[0].target.full_name)
216
- assert_equal(1, children_of_a[1].called)
217
- assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
218
- else
219
- assert_equal(1, children_of_a.length)
220
- assert_equal(1, children_of_a[0].called)
221
- assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
222
- end
223
- end
224
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class UniqueCallPath
7
+ def method_a(i)
8
+ if i==1
9
+ method_b
10
+ else
11
+ method_c
12
+ end
13
+ end
14
+
15
+ def method_b
16
+ method_c
17
+ end
18
+
19
+ def method_c
20
+ end
21
+
22
+ def method_k(i)
23
+ method_a(i)
24
+ end
25
+ end
26
+
27
+
28
+ # -- Tests ----
29
+ class UniqueCallPathTest < TestCase
30
+ def test_root
31
+ unique_call_path = UniqueCallPath.new
32
+
33
+ result = RubyProf.profile do
34
+ unique_call_path.method_a(1)
35
+ end
36
+
37
+ root_call_info = result.threads.first.call_tree
38
+ assert_equal("UniqueCallPathTest#test_root", root_call_info.target.full_name)
39
+ end
40
+
41
+ def test_root_children
42
+ unique_call_path = UniqueCallPath.new
43
+
44
+ result = RubyProf.profile do
45
+ unique_call_path.method_a(1)
46
+ unique_call_path.method_k(2)
47
+ end
48
+
49
+ root_call_info = result.threads.first.call_tree
50
+ children = root_call_info.children.sort do |c1, c2|
51
+ c1.target.full_name <=> c2.target.full_name
52
+ end
53
+
54
+ assert_equal(2, children.length)
55
+ assert_equal("UniqueCallPath#method_a", children[0].target.full_name)
56
+ assert_equal("UniqueCallPath#method_k", children[1].target.full_name)
57
+ end
58
+
59
+ def test_children_of
60
+ unique_call_path = UniqueCallPath.new
61
+
62
+ result = RubyProf.profile do
63
+ unique_call_path.method_a(1)
64
+ unique_call_path.method_k(2)
65
+ end
66
+
67
+ root_call_info = result.threads.first.call_tree
68
+ assert_equal("UniqueCallPathTest#test_children_of", root_call_info.target.full_name)
69
+
70
+ call_info_a = root_call_info.children.detect do |call_tree|
71
+ call_tree.target.full_name == "UniqueCallPath#method_a"
72
+ end
73
+ refute_nil(call_info_a)
74
+
75
+ _children_of_a = call_info_a.children.inject(Array.new) do |array, c|
76
+ if c.parent.eql?(call_info_a)
77
+ array << c
78
+ end
79
+ array
80
+ end
81
+
82
+ assert_equal(1, call_info_a.children.length)
83
+ assert_equal("UniqueCallPath#method_b", call_info_a.children.first.target.full_name)
84
+ end
85
+
86
+ def test_unique_path
87
+ unique_call_path = UniqueCallPath.new
88
+
89
+ result = RubyProf.profile do
90
+ unique_call_path.method_a(1)
91
+ unique_call_path.method_k(1)
92
+ end
93
+
94
+ root_call_info = result.threads.first.call_tree
95
+ assert_equal("UniqueCallPathTest#test_unique_path", root_call_info.target.full_name)
96
+
97
+ call_info_a = root_call_info.children.detect do |call_tree|
98
+ call_tree.target.full_name == "UniqueCallPath#method_a"
99
+ end
100
+ refute_nil(call_info_a)
101
+
102
+ children_of_a = call_info_a.children.reduce(Array.new) do |array, c|
103
+ if c.parent.eql?(call_info_a)
104
+ array << c
105
+ end
106
+ array
107
+ end
108
+
109
+ assert_equal(1, call_info_a.children.length)
110
+ assert_equal(1, children_of_a.length)
111
+
112
+ children_of_a = children_of_a.sort do |c1, c2|
113
+ c1.target.full_name <=> c2.target.full_name
114
+ end
115
+
116
+ assert_equal(1, children_of_a.length)
117
+ assert_equal(1, children_of_a[0].called)
118
+ assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
119
+ end
120
+ end