ruby-prof 0.13.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
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,62 +1,785 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- class MeasureProcessTimeTest < Test::Unit::TestCase
7
- def setup
8
- # Need to fix this for linux (windows works since PROCESS_TIME is WALL_TIME anyway)
9
- RubyProf::measure_mode = RubyProf::PROCESS_TIME
10
- end
11
-
12
- def test_mode
13
- assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
14
- end
15
-
16
- def test_process_time_enabled_defined
17
- assert(defined?(RubyProf::PROCESS_TIME_ENABLED))
18
- end
19
-
20
- def test_primes
21
- start = Process.times
22
- result = RubyProf.profile do
23
- run_primes(10000)
24
- end
25
- finish = Process.times
26
-
27
- total_time = (finish.utime - start.utime) + (finish.stime - start.stime)
28
-
29
- thread = result.threads.first
30
- assert_in_delta(total_time, thread.total_time, 0.03)
31
-
32
- methods = result.threads.first.methods.sort.reverse
33
-
34
- if RUBY_VERSION =~ /^1\.8/
35
- methods.reject!{|m| m.full_name =~ /^Fixnum/ || m.full_name == 'Object#find_largest'}
36
- end
37
- if RUBY_VERSION =~ /^(1\.9\.2|2\.0)/
38
- assert_equal 15, methods.length
39
- else
40
- assert_equal 16, methods.length
41
- end
42
-
43
- # Check times
44
- assert_equal("MeasureProcessTimeTest#test_primes", methods[0].full_name)
45
- assert_in_delta(total_time, methods[0].total_time, 0.02)
46
- assert_in_delta(0.0, methods[0].wait_time, 0.01)
47
- assert_in_delta(0.0, methods[0].self_time, 0.01)
48
-
49
- assert_equal("Object#run_primes", methods[1].full_name)
50
- assert_in_delta(total_time, methods[1].total_time, 0.02)
51
- assert_in_delta(0.0, methods[1].wait_time, 0.01)
52
- assert_in_delta(0.0, methods[1].self_time, 0.01)
53
-
54
- assert_equal("Object#find_primes", methods[2].full_name)
55
- assert_equal("Array#select", methods[3].full_name)
56
- assert_equal("Object#is_prime", methods[4].full_name)
57
- assert_equal("Integer#upto", methods[5].full_name)
58
- assert_equal("Object#make_random_array", methods[6].full_name)
59
- assert_equal("Array#each_index", methods[7].full_name)
60
- assert_equal("Kernel#rand", methods[8].full_name)
61
- end
62
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './measure_times'
6
+
7
+ class MeasureProcessTimeTest < TestCase
8
+ def setup
9
+ # Need to fix this for linux (windows works since PROCESS_TIME is WALL_TIME anyway)
10
+ RubyProf::measure_mode = RubyProf::PROCESS_TIME
11
+ GC.start
12
+ end
13
+
14
+ def test_mode
15
+ assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
16
+ end
17
+
18
+ def test_class_methods_sleep
19
+ result = RubyProf.profile do
20
+ RubyProf::C1.sleep_wait
21
+ end
22
+
23
+ thread = result.threads.first
24
+ assert_in_delta(0.0, thread.total_time, 0.05)
25
+
26
+ methods = result.threads.first.methods.sort.reverse
27
+ assert_equal(3, methods.length)
28
+
29
+ # Check times
30
+ method = methods[0]
31
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
32
+ assert_in_delta(0.0, method.total_time, 0.05)
33
+ assert_in_delta(0.0, method.wait_time, 0.05)
34
+ assert_in_delta(0.0, method.self_time, 0.05)
35
+ assert_in_delta(0.0, method.children_time, 0.05)
36
+
37
+ method = methods[1]
38
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
39
+ assert_in_delta(0.0, method.total_time, 0.05)
40
+ assert_in_delta(0.0, method.wait_time, 0.05)
41
+ assert_in_delta(0.0, method.self_time, 0.05)
42
+ assert_in_delta(0.0, method.children_time, 0.05)
43
+
44
+ method = methods[2]
45
+ assert_equal('Kernel#sleep', method.full_name)
46
+ assert_in_delta(0.0, method.total_time, 0.05)
47
+ assert_in_delta(0.0, method.wait_time, 0.05)
48
+ assert_in_delta(0.0, method.self_time, 0.05)
49
+ assert_in_delta(0.0, method.children_time, 0.05)
50
+ end
51
+
52
+ def test_class_methods_sleep_threaded
53
+ result = RubyProf.profile do
54
+ background_thread = Thread.new do
55
+ RubyProf::C1.sleep_wait
56
+ end
57
+ background_thread.join
58
+ end
59
+
60
+ assert_equal(2, result.threads.count)
61
+
62
+ thread = result.threads.first
63
+ assert_in_delta(0.0, thread.total_time, 0.05)
64
+
65
+ methods = result.threads.first.methods.sort.reverse
66
+ assert_equal(4, methods.length)
67
+
68
+ # Check times
69
+ method = methods[0]
70
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
71
+ assert_in_delta(0.0, method.total_time, 0.05)
72
+ assert_in_delta(0.0, method.wait_time, 0.05)
73
+ assert_in_delta(0.0, method.self_time, 0.05)
74
+ assert_in_delta(0.0, method.children_time, 0.05)
75
+
76
+ method = methods[1]
77
+ assert_equal('Thread#join', method.full_name)
78
+ assert_in_delta(0.0, method.total_time, 0.05)
79
+ assert_in_delta(0.0, method.wait_time, 0.05)
80
+ assert_in_delta(0.0, method.self_time, 0.05)
81
+ assert_in_delta(0.0, method.children_time, 0.05)
82
+
83
+ method = methods[2]
84
+ assert_equal('<Class::Thread>#new', method.full_name)
85
+ assert_in_delta(0.0, method.total_time, 0.05)
86
+ assert_in_delta(0.0, method.wait_time, 0.05)
87
+ assert_in_delta(0.0, method.self_time, 0.05)
88
+ assert_in_delta(0.0, method.children_time, 0.05)
89
+
90
+ method = methods[3]
91
+ assert_equal('Thread#initialize', method.full_name)
92
+ assert_in_delta(0.0, method.total_time, 0.05)
93
+ assert_in_delta(0.0, method.wait_time, 0.05)
94
+ assert_in_delta(0.0, method.self_time, 0.05)
95
+ assert_in_delta(0.0, method.children_time, 0.05)
96
+
97
+ thread = result.threads.last
98
+ assert_in_delta(0.0, thread.total_time, 0.05)
99
+
100
+ methods = result.threads.first.methods.sort.reverse
101
+ assert_equal(4, methods.length)
102
+
103
+ methods = result.threads.last.methods.sort.reverse
104
+ assert_equal(3, methods.length)
105
+
106
+ # Check times
107
+ method = methods[0]
108
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
109
+ assert_in_delta(0.0, method.total_time, 0.05)
110
+ assert_in_delta(0.0, method.wait_time, 0.05)
111
+ assert_in_delta(0.0, method.self_time, 0.05)
112
+ assert_in_delta(0.0, method.children_time, 0.05)
113
+
114
+ method = methods[1]
115
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
116
+ assert_in_delta(0.0, method.total_time, 0.05)
117
+ assert_in_delta(0.0, method.wait_time, 0.05)
118
+ assert_in_delta(0.0, method.self_time, 0.05)
119
+ assert_in_delta(0.0, method.children_time, 0.05)
120
+
121
+ method = methods[2]
122
+ assert_equal('Kernel#sleep', method.full_name)
123
+ assert_in_delta(0.0, method.total_time, 0.05)
124
+ assert_in_delta(0.0, method.wait_time, 0.05)
125
+ assert_in_delta(0.0, method.self_time, 0.05)
126
+ assert_in_delta(0.0, method.children_time, 0.05)
127
+ end
128
+
129
+ def test_class_methods_busy
130
+ result = RubyProf.profile do
131
+ RubyProf::C1.busy_wait
132
+ end
133
+
134
+ thread = result.threads.first
135
+ assert_in_delta(0.08, thread.total_time, 0.05)
136
+
137
+ methods = result.threads.first.methods.sort.reverse
138
+ assert_equal(3, methods.length)
139
+
140
+ # Check times
141
+ method = methods[0]
142
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
143
+ assert_in_delta(0.1, method.total_time, 0.05)
144
+ assert_in_delta(0.0, method.wait_time, 0.05)
145
+ assert_in_delta(0.0, method.self_time, 0.05)
146
+ assert_in_delta(0.1, method.children_time, 0.05)
147
+
148
+ method = methods[1]
149
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
150
+ assert_in_delta(0.1, method.total_time, 0.05)
151
+ assert_in_delta(0.0, method.wait_time, 0.05)
152
+ assert_in_delta(0.06, method.self_time, 0.05)
153
+ assert_in_delta(0.07, method.children_time, 0.05)
154
+
155
+ method = methods[2]
156
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
157
+ assert_in_delta(0.05, method.total_time, 0.05)
158
+ assert_in_delta(0.0, method.wait_time, 0.05)
159
+ assert_in_delta(0.05, method.self_time, 0.05)
160
+ assert_in_delta(0.0, method.children_time, 0.05)
161
+ end
162
+
163
+ def test_class_methods_busy_threaded
164
+ result = RubyProf.profile do
165
+ background_thread = Thread.new do
166
+ RubyProf::C1.busy_wait
167
+ end
168
+ background_thread.join
169
+ end
170
+
171
+ assert_equal(2, result.threads.count)
172
+
173
+ thread = result.threads.first
174
+ assert_in_delta(0.1, thread.total_time, 0.05)
175
+
176
+ methods = result.threads.first.methods.sort.reverse
177
+ assert_equal(4, methods.length)
178
+
179
+ # Check times
180
+ method = methods[0]
181
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
182
+ assert_in_delta(0.1, method.total_time, 0.05)
183
+ assert_in_delta(0.0, method.wait_time, 0.05)
184
+ assert_in_delta(0.0, method.self_time, 0.05)
185
+ assert_in_delta(0.1, method.children_time, 0.05)
186
+
187
+ method = methods[1]
188
+ assert_equal('Thread#join', method.full_name)
189
+ assert_in_delta(0.1, method.total_time, 0.05)
190
+ assert_in_delta(0.1, method.wait_time, 0.05)
191
+ assert_in_delta(0.0, method.self_time, 0.05)
192
+ assert_in_delta(0.0, method.children_time, 0.05)
193
+
194
+ method = methods[2]
195
+ assert_equal('<Class::Thread>#new', method.full_name)
196
+ assert_in_delta(0.0, method.total_time, 0.05)
197
+ assert_in_delta(0.0, method.wait_time, 0.05)
198
+ assert_in_delta(0.0, method.self_time, 0.05)
199
+ assert_in_delta(0.0, method.children_time, 0.05)
200
+
201
+ method = methods[3]
202
+ assert_equal('Thread#initialize', method.full_name)
203
+ assert_in_delta(0.0, method.total_time, 0.05)
204
+ assert_in_delta(0.0, method.wait_time, 0.05)
205
+ assert_in_delta(0.0, method.self_time, 0.05)
206
+ assert_in_delta(0.0, method.children_time, 0.05)
207
+
208
+ thread = result.threads.last
209
+ assert_in_delta(0.1, thread.total_time, 0.05)
210
+
211
+ methods = result.threads.first.methods.sort.reverse
212
+ assert_equal(4, methods.length)
213
+
214
+ methods = result.threads.last.methods.sort.reverse
215
+ assert_equal(3, methods.length)
216
+
217
+ # Check times
218
+ method = methods[0]
219
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
220
+ assert_in_delta(0.1, method.total_time, 0.05)
221
+ assert_in_delta(0.0, method.wait_time, 0.05)
222
+ assert_in_delta(0.0, method.self_time, 0.05)
223
+ assert_in_delta(0.1, method.children_time, 0.05)
224
+
225
+ method = methods[1]
226
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
227
+ assert_in_delta(0.1, method.total_time, 0.05)
228
+ assert_in_delta(0.0, method.wait_time, 0.05)
229
+ assert_in_delta(0.05, method.self_time, 0.05)
230
+ assert_in_delta(0.05, method.children_time, 0.05)
231
+
232
+ method = methods[2]
233
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
234
+ assert_in_delta(0.05, method.total_time, 0.05)
235
+ assert_in_delta(0.0, method.wait_time, 0.05)
236
+ assert_in_delta(0.05, method.self_time, 0.05)
237
+ assert_in_delta(0.0, method.children_time, 0.05)
238
+ end
239
+
240
+ def test_instance_methods_sleep
241
+ result = RubyProf.profile do
242
+ RubyProf::C1.new.sleep_wait
243
+ end
244
+
245
+ thread = result.threads.first
246
+ assert_in_delta(0.0, thread.total_time, 0.05)
247
+
248
+ methods = result.threads.first.methods.sort.reverse
249
+ assert_equal(5, methods.length)
250
+
251
+ # Check times
252
+ method = methods[0]
253
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
254
+ assert_in_delta(0.0, method.total_time, 0.05)
255
+ assert_in_delta(0.0, method.wait_time, 0.05)
256
+ assert_in_delta(0.0, method.self_time, 0.05)
257
+ assert_in_delta(0.0, method.children_time, 0.05)
258
+
259
+ method = methods[1]
260
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
261
+ assert_in_delta(0.0, method.total_time, 0.05)
262
+ assert_in_delta(0.0, method.wait_time, 0.05)
263
+ assert_in_delta(0.0, method.self_time, 0.05)
264
+ assert_in_delta(0.0, method.children_time, 0.05)
265
+
266
+ method = methods[2]
267
+ assert_equal('Kernel#sleep', method.full_name)
268
+ assert_in_delta(0.0, method.total_time, 0.05)
269
+ assert_in_delta(0.0, method.wait_time, 0.05)
270
+ assert_in_delta(0.0, method.self_time, 0.05)
271
+ assert_in_delta(0.0, method.children_time, 0.05)
272
+
273
+ method = methods[3]
274
+ assert_equal('Class#new', method.full_name)
275
+ assert_in_delta(0.0, method.total_time, 0.05)
276
+ assert_in_delta(0.0, method.wait_time, 0.05)
277
+ assert_in_delta(0.0, method.self_time, 0.05)
278
+ assert_in_delta(0.0, method.children_time, 0.05)
279
+
280
+ method = methods[4]
281
+ assert_equal('BasicObject#initialize', method.full_name)
282
+ assert_in_delta(0.0, method.total_time, 0.05)
283
+ assert_in_delta(0.0, method.wait_time, 0.05)
284
+ assert_in_delta(0.0, method.self_time, 0.05)
285
+ assert_in_delta(0.0, method.children_time, 0.05)
286
+ end
287
+
288
+ def test_instance_methods_sleep_block
289
+ result = RubyProf.profile do
290
+ 1.times { RubyProf::C1.new.sleep_wait }
291
+ end
292
+
293
+ methods = result.threads.first.methods.sort.reverse
294
+ assert_equal(6, methods.length)
295
+
296
+ # Check times
297
+ method = methods[0]
298
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
299
+ assert_in_delta(0.0, method.total_time, 0.05)
300
+ assert_in_delta(0.0, method.wait_time, 0.05)
301
+ assert_in_delta(0.0, method.self_time, 0.05)
302
+ assert_in_delta(0.0, method.children_time, 0.05)
303
+
304
+ method = methods[1]
305
+ assert_equal('Integer#times', method.full_name)
306
+ assert_in_delta(0.0, method.total_time, 0.05)
307
+ assert_in_delta(0.0, method.wait_time, 0.05)
308
+ assert_in_delta(0.0, method.self_time, 0.05)
309
+ assert_in_delta(0.0, method.children_time, 0.05)
310
+
311
+ method = methods[2]
312
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
313
+ assert_in_delta(0.0, method.total_time, 0.05)
314
+ assert_in_delta(0.0, method.wait_time, 0.05)
315
+ assert_in_delta(0.0, method.self_time, 0.05)
316
+ assert_in_delta(0.0, method.children_time, 0.05)
317
+
318
+ method = methods[3]
319
+ assert_equal('Kernel#sleep', method.full_name)
320
+ assert_in_delta(0.0, method.total_time, 0.05)
321
+ assert_in_delta(0.0, method.wait_time, 0.05)
322
+ assert_in_delta(0.0, method.self_time, 0.05)
323
+ assert_in_delta(0.0, method.children_time, 0.05)
324
+
325
+ method = methods[4]
326
+ assert_equal('Class#new', method.full_name)
327
+ assert_in_delta(0.0, method.total_time, 0.05)
328
+ assert_in_delta(0.0, method.wait_time, 0.05)
329
+ assert_in_delta(0.0, method.self_time, 0.05)
330
+ assert_in_delta(0.0, method.children_time, 0.05)
331
+
332
+ method = methods[5]
333
+ assert_equal('BasicObject#initialize', method.full_name)
334
+ assert_in_delta(0.0, method.total_time, 0.05)
335
+ assert_in_delta(0.0, method.wait_time, 0.05)
336
+ assert_in_delta(0.0, method.self_time, 0.05)
337
+ assert_in_delta(0.0, method.children_time, 0.05)
338
+ end
339
+
340
+ def test_instance_methods_sleep_threaded
341
+ result = RubyProf.profile do
342
+ background_thread = Thread.new do
343
+ RubyProf::C1.new.sleep_wait
344
+ end
345
+ background_thread.join
346
+ end
347
+
348
+ assert_equal(2, result.threads.count)
349
+
350
+ thread = result.threads.first
351
+ assert_in_delta(0.0, thread.total_time, 0.05)
352
+
353
+ methods = result.threads.first.methods.sort.reverse
354
+ assert_equal(4, methods.length)
355
+
356
+ # Check times
357
+ method = methods[0]
358
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
359
+ assert_in_delta(0.0, method.total_time, 0.05)
360
+ assert_in_delta(0.0, method.wait_time, 0.05)
361
+ assert_in_delta(0.0, method.self_time, 0.05)
362
+ assert_in_delta(0.0, method.children_time, 0.05)
363
+
364
+ method = methods[1]
365
+ assert_equal('Thread#join', method.full_name)
366
+ assert_in_delta(0.0, method.total_time, 0.05)
367
+ assert_in_delta(0.0, method.wait_time, 0.05)
368
+ assert_in_delta(0.0, method.self_time, 0.05)
369
+ assert_in_delta(0.0, method.children_time, 0.05)
370
+
371
+ method = methods[2]
372
+ assert_equal('<Class::Thread>#new', method.full_name)
373
+ assert_in_delta(0.0, method.total_time, 0.05)
374
+ assert_in_delta(0.0, method.wait_time, 0.05)
375
+ assert_in_delta(0.0, method.self_time, 0.05)
376
+ assert_in_delta(0.0, method.children_time, 0.05)
377
+
378
+ method = methods[3]
379
+ assert_equal('Thread#initialize', method.full_name)
380
+ assert_in_delta(0.0, method.total_time, 0.05)
381
+ assert_in_delta(0.0, method.wait_time, 0.05)
382
+ assert_in_delta(0.0, method.self_time, 0.05)
383
+ assert_in_delta(0.0, method.children_time, 0.05)
384
+
385
+ thread = result.threads.last
386
+ assert_in_delta(0.0, thread.total_time, 0.05)
387
+
388
+ methods = result.threads.first.methods.sort.reverse
389
+ assert_equal(4, methods.length)
390
+
391
+ methods = result.threads.last.methods.sort.reverse
392
+ assert_equal(5, methods.length)
393
+
394
+ # Check times
395
+ method = methods[0]
396
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
397
+ assert_in_delta(0.0, method.total_time, 0.05)
398
+ assert_in_delta(0.0, method.wait_time, 0.05)
399
+ assert_in_delta(0.0, method.self_time, 0.05)
400
+ assert_in_delta(0.0, method.children_time, 0.05)
401
+
402
+ method = methods[1]
403
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
404
+ assert_in_delta(0.0, method.total_time, 0.05)
405
+ assert_in_delta(0.0, method.wait_time, 0.05)
406
+ assert_in_delta(0.0, method.self_time, 0.05)
407
+ assert_in_delta(0.0, method.children_time, 0.05)
408
+
409
+ method = methods[2]
410
+ assert_equal('Kernel#sleep', method.full_name)
411
+ assert_in_delta(0.0, method.total_time, 0.05)
412
+ assert_in_delta(0.0, method.wait_time, 0.05)
413
+ assert_in_delta(0.0, method.self_time, 0.05)
414
+ assert_in_delta(0.0, method.children_time, 0.05)
415
+
416
+ method = methods[3]
417
+ assert_equal('Class#new', method.full_name)
418
+ assert_in_delta(0.0, method.total_time, 0.05)
419
+ assert_in_delta(0.0, method.wait_time, 0.05)
420
+ assert_in_delta(0.0, method.self_time, 0.05)
421
+ assert_in_delta(0.0, method.children_time, 0.05)
422
+
423
+ method = methods[4]
424
+ assert_equal('BasicObject#initialize', method.full_name)
425
+ assert_in_delta(0.0, method.total_time, 0.05)
426
+ assert_in_delta(0.0, method.wait_time, 0.05)
427
+ assert_in_delta(0.0, method.self_time, 0.05)
428
+ assert_in_delta(0.0, method.children_time, 0.05)
429
+ end
430
+
431
+ def test_instance_methods_busy
432
+ result = RubyProf.profile do
433
+ RubyProf::C1.new.busy_wait
434
+ end
435
+
436
+ thread = result.threads.first
437
+ assert_in_delta(0.2, thread.total_time, 0.05)
438
+
439
+ methods = result.threads.first.methods.sort.reverse
440
+ assert_equal(5, methods.length)
441
+
442
+ # Check times
443
+ method = methods[0]
444
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
445
+ assert_in_delta(0.2, method.total_time, 0.05)
446
+ assert_in_delta(0.0, method.wait_time, 0.05)
447
+ assert_in_delta(0.0, method.self_time, 0.05)
448
+ assert_in_delta(0.2, method.children_time, 0.05)
449
+
450
+ method = methods[1]
451
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
452
+ assert_in_delta(0.2, method.total_time, 0.05)
453
+ assert_in_delta(0.0, method.wait_time, 0.05)
454
+ assert_in_delta(0.09, method.self_time, 0.05)
455
+ assert_in_delta(0.11, method.children_time, 0.05)
456
+
457
+ method = methods[2]
458
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
459
+ assert_in_delta(0.11, method.total_time, 0.05)
460
+ assert_in_delta(0.0, method.wait_time, 0.05)
461
+ assert_in_delta(0.11, method.self_time, 0.05)
462
+ assert_in_delta(0.0, method.children_time, 0.05)
463
+
464
+ method = methods[3]
465
+ assert_equal('Class#new', method.full_name)
466
+ assert_in_delta(0.0, method.total_time, 0.05)
467
+ assert_in_delta(0.0, method.wait_time, 0.05)
468
+ assert_in_delta(0.0, method.self_time, 0.05)
469
+ assert_in_delta(0.0, method.children_time, 0.05)
470
+
471
+ method = methods[4]
472
+ assert_equal('BasicObject#initialize', method.full_name)
473
+ assert_in_delta(0.0, method.total_time, 0.05)
474
+ assert_in_delta(0.0, method.wait_time, 0.05)
475
+ assert_in_delta(0.0, method.self_time, 0.05)
476
+ assert_in_delta(0.0, method.children_time, 0.05)
477
+ end
478
+
479
+ def test_instance_methods_busy_block
480
+ result = RubyProf.profile do
481
+ 1.times { RubyProf::C1.new.busy_wait }
482
+ end
483
+
484
+ methods = result.threads.first.methods.sort.reverse
485
+ assert_equal(6, methods.length)
486
+
487
+ # Check times
488
+ method = methods[0]
489
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
490
+ assert_in_delta(0.2, method.total_time, 0.05)
491
+ assert_in_delta(0.0, method.wait_time, 0.05)
492
+ assert_in_delta(0.0, method.self_time, 0.05)
493
+ assert_in_delta(0.2, method.children_time, 0.05)
494
+
495
+ method = methods[1]
496
+ assert_equal('Integer#times', method.full_name)
497
+ assert_in_delta(0.2, method.total_time, 0.05)
498
+ assert_in_delta(0.0, method.wait_time, 0.05)
499
+ assert_in_delta(0.0, method.self_time, 0.05)
500
+ assert_in_delta(0.2, method.children_time, 0.05)
501
+
502
+ method = methods[2]
503
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
504
+ assert_in_delta(0.2, method.total_time, 0.05)
505
+ assert_in_delta(0.0, method.wait_time, 0.05)
506
+ assert_in_delta(0.09, method.self_time, 0.05)
507
+ assert_in_delta(0.11, method.children_time, 0.05)
508
+
509
+ method = methods[3]
510
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
511
+ assert_in_delta(0.11, method.total_time, 0.05)
512
+ assert_in_delta(0.0, method.wait_time, 0.05)
513
+ assert_in_delta(0.11, method.self_time, 0.05)
514
+ assert_in_delta(0.0, method.children_time, 0.05)
515
+
516
+ method = methods[4]
517
+ assert_equal('Class#new', method.full_name)
518
+ assert_in_delta(0.0, method.total_time, 0.05)
519
+ assert_in_delta(0.0, method.wait_time, 0.05)
520
+ assert_in_delta(0.0, method.self_time, 0.05)
521
+ assert_in_delta(0.0, method.children_time, 0.05)
522
+
523
+ method = methods[5]
524
+ assert_equal('BasicObject#initialize', method.full_name)
525
+ assert_in_delta(0.0, method.total_time, 0.05)
526
+ assert_in_delta(0.0, method.wait_time, 0.05)
527
+ assert_in_delta(0.0, method.self_time, 0.05)
528
+ assert_in_delta(0.0, method.children_time, 0.05)
529
+ end
530
+
531
+ def test_instance_methods_busy_threaded
532
+ result = RubyProf.profile do
533
+ background_thread = Thread.new do
534
+ RubyProf::C1.new.busy_wait
535
+ end
536
+ background_thread.join
537
+ end
538
+
539
+ assert_equal(2, result.threads.count)
540
+
541
+ thread = result.threads.first
542
+ assert_in_delta(0.2, thread.total_time, 0.05)
543
+
544
+ methods = result.threads.first.methods.sort.reverse
545
+ assert_equal(4, methods.length)
546
+
547
+ # Check times
548
+ method = methods[0]
549
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
550
+ assert_in_delta(0.2, method.total_time, 0.05)
551
+ assert_in_delta(0.0, method.wait_time, 0.05)
552
+ assert_in_delta(0.0, method.self_time, 0.05)
553
+ assert_in_delta(0.2, method.children_time, 0.05)
554
+
555
+ method = methods[1]
556
+ assert_equal('Thread#join', method.full_name)
557
+ assert_in_delta(0.2, method.total_time, 0.05)
558
+ assert_in_delta(0.2, method.wait_time, 0.05)
559
+ assert_in_delta(0.0, method.self_time, 0.05)
560
+ assert_in_delta(0.0, method.children_time, 0.05)
561
+
562
+ method = methods[2]
563
+ assert_equal('<Class::Thread>#new', method.full_name)
564
+ assert_in_delta(0.0, method.total_time, 0.05)
565
+ assert_in_delta(0.0, method.wait_time, 0.05)
566
+ assert_in_delta(0.0, method.self_time, 0.05)
567
+ assert_in_delta(0.0, method.children_time, 0.05)
568
+
569
+ method = methods[3]
570
+ assert_equal('Thread#initialize', method.full_name)
571
+ assert_in_delta(0.0, method.total_time, 0.05)
572
+ assert_in_delta(0.0, method.wait_time, 0.05)
573
+ assert_in_delta(0.0, method.self_time, 0.05)
574
+ assert_in_delta(0.0, method.children_time, 0.05)
575
+
576
+ thread = result.threads.last
577
+ assert_in_delta(0.2, thread.total_time, 0.05)
578
+
579
+ methods = result.threads.first.methods.sort.reverse
580
+ assert_equal(4, methods.length)
581
+
582
+ methods = result.threads.last.methods.sort.reverse
583
+ assert_equal(5, methods.length)
584
+
585
+ # Check times
586
+ method = methods[0]
587
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
588
+ assert_in_delta(0.2, method.total_time, 0.05)
589
+ assert_in_delta(0.0, method.wait_time, 0.05)
590
+ assert_in_delta(0.0, method.self_time, 0.05)
591
+ assert_in_delta(0.2, method.children_time, 0.05)
592
+
593
+ method = methods[1]
594
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
595
+ assert_in_delta(0.2, method.total_time, 0.05)
596
+ assert_in_delta(0.0, method.wait_time, 0.05)
597
+ assert_in_delta(0.1, method.self_time, 0.05)
598
+ assert_in_delta(0.1, method.children_time, 0.05)
599
+
600
+ method = methods[2]
601
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
602
+ assert_in_delta(0.1, method.total_time, 0.05)
603
+ assert_in_delta(0.0, method.wait_time, 0.05)
604
+ assert_in_delta(0.1, method.self_time, 0.05)
605
+ assert_in_delta(0.0, method.children_time, 0.05)
606
+
607
+ method = methods[3]
608
+ assert_equal('Class#new', method.full_name)
609
+ assert_in_delta(0.0, method.total_time, 0.05)
610
+ assert_in_delta(0.0, method.wait_time, 0.05)
611
+ assert_in_delta(0.0, method.self_time, 0.05)
612
+ assert_in_delta(0.0, method.children_time, 0.05)
613
+
614
+ method = methods[4]
615
+ assert_equal('BasicObject#initialize', method.full_name)
616
+ assert_in_delta(0.0, method.total_time, 0.05)
617
+ assert_in_delta(0.0, method.wait_time, 0.05)
618
+ assert_in_delta(0.0, method.self_time, 0.05)
619
+ assert_in_delta(0.0, method.children_time, 0.05)
620
+ end
621
+
622
+ def test_module_methods_sleep
623
+ result = RubyProf.profile do
624
+ RubyProf::C2.sleep_wait
625
+ end
626
+
627
+ thread = result.threads.first
628
+ assert_in_delta(0.0, thread.total_time, 0.05)
629
+
630
+ methods = result.threads.first.methods.sort.reverse
631
+ assert_equal(3, methods.length)
632
+
633
+ # Check times
634
+ method = methods[0]
635
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
636
+ assert_in_delta(0.0, method.total_time, 0.05)
637
+ assert_in_delta(0.0, method.wait_time, 0.05)
638
+ assert_in_delta(0.0, method.self_time, 0.05)
639
+ assert_in_delta(0.0, method.children_time, 0.05)
640
+
641
+ method = methods[1]
642
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
643
+ assert_in_delta(0.0, method.total_time, 0.05)
644
+ assert_in_delta(0.0, method.wait_time, 0.05)
645
+ assert_in_delta(0.0, method.self_time, 0.05)
646
+ assert_in_delta(0.0, method.children_time, 0.05)
647
+
648
+ method = methods[2]
649
+ assert_equal('Kernel#sleep', method.full_name)
650
+ assert_in_delta(0.0, method.total_time, 0.05)
651
+ assert_in_delta(0.0, method.wait_time, 0.05)
652
+ assert_in_delta(0.0, method.self_time, 0.05)
653
+ assert_in_delta(0.0, method.children_time, 0.05)
654
+ end
655
+
656
+ def test_module_methods_busy
657
+ result = RubyProf.profile do
658
+ RubyProf::C2.busy_wait
659
+ end
660
+
661
+ thread = result.threads.first
662
+ assert_in_delta(0.3, thread.total_time, 0.05)
663
+
664
+ methods = result.threads.first.methods.sort.reverse
665
+ assert_equal(3, methods.length)
666
+
667
+ # Check times
668
+ method = methods[0]
669
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
670
+ assert_in_delta(0.3, method.total_time, 0.05)
671
+ assert_in_delta(0.0, method.wait_time, 0.05)
672
+ assert_in_delta(0.0, method.self_time, 0.05)
673
+ assert_in_delta(0.3, method.children_time, 0.05)
674
+
675
+ method = methods[1]
676
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
677
+ assert_in_delta(0.3, method.total_time, 0.05)
678
+ assert_in_delta(0.0, method.wait_time, 0.05)
679
+ assert_in_delta(0.15, method.self_time, 0.05)
680
+ assert_in_delta(0.15, method.children_time, 0.05)
681
+
682
+ method = methods[2]
683
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
684
+ assert_in_delta(0.15, method.total_time, 0.05)
685
+ assert_in_delta(0.0, method.wait_time, 0.05)
686
+ assert_in_delta(0.15, method.self_time, 0.05)
687
+ assert_in_delta(0.0, method.children_time, 0.05)
688
+ end
689
+
690
+ def test_module_instance_methods_sleep
691
+ result = RubyProf.profile do
692
+ RubyProf::C2.new.sleep_wait
693
+ end
694
+
695
+ thread = result.threads.first
696
+ assert_in_delta(0.0, thread.total_time, 0.05)
697
+
698
+ methods = result.threads.first.methods.sort.reverse
699
+ assert_equal(5, methods.length)
700
+
701
+ # Check times
702
+ method = methods[0]
703
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
704
+ assert_in_delta(0.0, method.total_time, 0.05)
705
+ assert_in_delta(0.0, method.wait_time, 0.05)
706
+ assert_in_delta(0.0, method.self_time, 0.05)
707
+ assert_in_delta(0.0, method.children_time, 0.05)
708
+
709
+ method = methods[1]
710
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
711
+ assert_in_delta(0.0, method.total_time, 0.05)
712
+ assert_in_delta(0.0, method.wait_time, 0.05)
713
+ assert_in_delta(0.0, method.self_time, 0.05)
714
+ assert_in_delta(0.0, method.children_time, 0.05)
715
+
716
+ method = methods[2]
717
+ assert_equal('Kernel#sleep', method.full_name)
718
+ assert_in_delta(0.0, method.total_time, 0.05)
719
+ assert_in_delta(0.0, method.wait_time, 0.05)
720
+ assert_in_delta(0.0, method.self_time, 0.05)
721
+ assert_in_delta(0.0, method.children_time, 0.05)
722
+
723
+ method = methods[3]
724
+ assert_equal('Class#new', method.full_name)
725
+ assert_in_delta(0.0, method.total_time, 0.05)
726
+ assert_in_delta(0.0, method.wait_time, 0.05)
727
+ assert_in_delta(0.0, method.self_time, 0.05)
728
+ assert_in_delta(0.0, method.children_time, 0.05)
729
+
730
+ method = methods[4]
731
+ assert_equal('BasicObject#initialize', method.full_name)
732
+ assert_in_delta(0.0, method.total_time, 0.05)
733
+ assert_in_delta(0.0, method.wait_time, 0.05)
734
+ assert_in_delta(0.0, method.self_time, 0.05)
735
+ assert_in_delta(0.0, method.children_time, 0.05)
736
+ end
737
+
738
+ def test_module_instance_methods_busy
739
+ result = RubyProf.profile do
740
+ RubyProf::C2.new.busy_wait
741
+ end
742
+
743
+ thread = result.threads.first
744
+ assert_in_delta(0.3, thread.total_time, 0.05)
745
+
746
+ methods = result.threads.first.methods.sort.reverse
747
+ assert_equal(5, methods.length)
748
+
749
+ # Check times
750
+ method = methods[0]
751
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
752
+ assert_in_delta(0.3, method.total_time, 0.05)
753
+ assert_in_delta(0.0, method.wait_time, 0.05)
754
+ assert_in_delta(0.0, method.self_time, 0.05)
755
+ assert_in_delta(0.3, method.children_time, 0.05)
756
+
757
+ method = methods[1]
758
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
759
+ assert_in_delta(0.3, method.total_time, 0.05)
760
+ assert_in_delta(0.0, method.wait_time, 0.05)
761
+ assert_in_delta(0.15, method.self_time, 0.05)
762
+ assert_in_delta(0.15, method.children_time, 0.05)
763
+
764
+ method = methods[2]
765
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
766
+ assert_in_delta(0.15, method.total_time, 0.05)
767
+ assert_in_delta(0.0, method.wait_time, 0.05)
768
+ assert_in_delta(0.15, method.self_time, 0.05)
769
+ assert_in_delta(0.0, method.children_time, 0.05)
770
+
771
+ method = methods[3]
772
+ assert_equal('Class#new', method.full_name)
773
+ assert_in_delta(0.0, method.total_time, 0.05)
774
+ assert_in_delta(0.0, method.wait_time, 0.05)
775
+ assert_in_delta(0.0, method.self_time, 0.05)
776
+ assert_in_delta(0.0, method.children_time, 0.05)
777
+
778
+ method = methods[4]
779
+ assert_equal('BasicObject#initialize', method.full_name)
780
+ assert_in_delta(0.0, method.total_time, 0.05)
781
+ assert_in_delta(0.0, method.wait_time, 0.05)
782
+ assert_in_delta(0.0, method.self_time, 0.05)
783
+ assert_in_delta(0.0, method.children_time, 0.05)
784
+ end
785
+ end