ruby-prof 0.16.2 → 1.1.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 (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +532 -467
  3. data/LICENSE +24 -24
  4. data/README.rdoc +5 -454
  5. data/Rakefile +110 -113
  6. data/bin/ruby-prof +380 -340
  7. data/bin/ruby-prof-check-trace +45 -45
  8. data/ext/ruby_prof/extconf.rb +36 -64
  9. data/ext/ruby_prof/rp_allocation.c +279 -0
  10. data/ext/ruby_prof/rp_allocation.h +31 -0
  11. data/ext/ruby_prof/rp_call_info.c +271 -407
  12. data/ext/ruby_prof/rp_call_info.h +35 -48
  13. data/ext/ruby_prof/rp_measure_allocations.c +52 -76
  14. data/ext/ruby_prof/rp_measure_memory.c +42 -77
  15. data/ext/ruby_prof/rp_measure_process_time.c +67 -71
  16. data/ext/ruby_prof/rp_measure_wall_time.c +62 -45
  17. data/ext/ruby_prof/rp_measurement.c +230 -0
  18. data/ext/ruby_prof/rp_measurement.h +50 -0
  19. data/ext/ruby_prof/rp_method.c +630 -411
  20. data/ext/ruby_prof/rp_method.h +70 -52
  21. data/ext/ruby_prof/rp_profile.c +895 -0
  22. data/ext/ruby_prof/rp_profile.h +37 -0
  23. data/ext/ruby_prof/rp_stack.c +196 -128
  24. data/ext/ruby_prof/rp_stack.h +56 -51
  25. data/ext/ruby_prof/rp_thread.c +337 -273
  26. data/ext/ruby_prof/rp_thread.h +36 -27
  27. data/ext/ruby_prof/ruby_prof.c +48 -671
  28. data/ext/ruby_prof/ruby_prof.h +17 -56
  29. data/ext/ruby_prof/vc/ruby_prof.sln +20 -21
  30. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +38 -5
  31. data/lib/ruby-prof.rb +52 -58
  32. data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  34. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  35. data/lib/ruby-prof/call_info.rb +57 -126
  36. data/lib/ruby-prof/call_info_visitor.rb +38 -40
  37. data/lib/ruby-prof/compatibility.rb +109 -178
  38. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  39. data/lib/ruby-prof/measurement.rb +14 -0
  40. data/lib/ruby-prof/method_info.rb +90 -129
  41. data/lib/ruby-prof/printers/abstract_printer.rb +127 -85
  42. data/lib/ruby-prof/printers/call_info_printer.rb +51 -41
  43. data/lib/ruby-prof/printers/call_stack_printer.rb +182 -260
  44. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -130
  45. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  46. data/lib/ruby-prof/printers/flat_printer.rb +52 -70
  47. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -244
  48. data/lib/ruby-prof/printers/graph_printer.rb +114 -116
  49. data/lib/ruby-prof/printers/multi_printer.rb +127 -58
  50. data/lib/ruby-prof/profile.rb +33 -55
  51. data/lib/ruby-prof/rack.rb +171 -95
  52. data/lib/ruby-prof/task.rb +147 -147
  53. data/lib/ruby-prof/thread.rb +35 -41
  54. data/lib/ruby-prof/version.rb +3 -3
  55. data/lib/unprof.rb +10 -10
  56. data/ruby-prof.gemspec +58 -57
  57. data/test/abstract_printer_test.rb +26 -0
  58. data/test/alias_test.rb +129 -0
  59. data/test/basic_test.rb +129 -128
  60. data/test/call_info_visitor_test.rb +31 -31
  61. data/test/duplicate_names_test.rb +32 -32
  62. data/test/dynamic_method_test.rb +53 -55
  63. data/test/enumerable_test.rb +21 -21
  64. data/test/exceptions_test.rb +24 -16
  65. data/test/exclude_methods_test.rb +146 -0
  66. data/test/exclude_threads_test.rb +53 -53
  67. data/test/fiber_test.rb +73 -79
  68. data/test/gc_test.rb +96 -0
  69. data/test/line_number_test.rb +161 -71
  70. data/test/marshal_test.rb +119 -0
  71. data/test/measure_allocations.rb +30 -0
  72. data/test/measure_allocations_test.rb +385 -26
  73. data/test/measure_allocations_trace_test.rb +385 -0
  74. data/test/measure_memory_trace_test.rb +756 -0
  75. data/test/measure_process_time_test.rb +849 -63
  76. data/test/measure_times.rb +54 -0
  77. data/test/measure_wall_time_test.rb +459 -255
  78. data/test/multi_printer_test.rb +71 -83
  79. data/test/no_method_class_test.rb +15 -15
  80. data/test/parser_timings.rb +24 -0
  81. data/test/pause_resume_test.rb +166 -166
  82. data/test/prime.rb +56 -54
  83. data/test/printer_call_stack_test.rb +28 -0
  84. data/test/printer_call_tree_test.rb +31 -0
  85. data/test/printer_flat_test.rb +68 -0
  86. data/test/printer_graph_html_test.rb +60 -0
  87. data/test/printer_graph_test.rb +41 -0
  88. data/test/printers_test.rb +141 -255
  89. data/test/printing_recursive_graph_test.rb +81 -127
  90. data/test/rack_test.rb +157 -93
  91. data/test/recursive_test.rb +210 -215
  92. data/test/singleton_test.rb +38 -38
  93. data/test/stack_printer_test.rb +64 -78
  94. data/test/start_stop_test.rb +109 -112
  95. data/test/test_helper.rb +24 -264
  96. data/test/thread_test.rb +144 -187
  97. data/test/unique_call_path_test.rb +190 -202
  98. data/test/yarv_test.rb +56 -55
  99. metadata +34 -114
  100. data/doc/LICENSE.html +0 -114
  101. data/doc/README_rdoc.html +0 -603
  102. data/doc/Rack.html +0 -95
  103. data/doc/Rack/RubyProf.html +0 -226
  104. data/doc/RubyProf.html +0 -962
  105. data/doc/RubyProf/AbstractPrinter.html +0 -546
  106. data/doc/RubyProf/AggregateCallInfo.html +0 -551
  107. data/doc/RubyProf/CallInfo.html +0 -639
  108. data/doc/RubyProf/CallInfoPrinter.html +0 -120
  109. data/doc/RubyProf/CallInfoVisitor.html +0 -198
  110. data/doc/RubyProf/CallStackPrinter.html +0 -1121
  111. data/doc/RubyProf/CallTreePrinter.html +0 -641
  112. data/doc/RubyProf/Cmd.html +0 -631
  113. data/doc/RubyProf/DotPrinter.html +0 -257
  114. data/doc/RubyProf/FlatPrinter.html +0 -163
  115. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -208
  116. data/doc/RubyProf/GraphHtmlPrinter.html +0 -552
  117. data/doc/RubyProf/GraphPrinter.html +0 -139
  118. data/doc/RubyProf/MethodInfo.html +0 -745
  119. data/doc/RubyProf/MultiPrinter.html +0 -360
  120. data/doc/RubyProf/Profile.html +0 -763
  121. data/doc/RubyProf/ProfileTask.html +0 -490
  122. data/doc/RubyProf/Thread.html +0 -310
  123. data/doc/created.rid +0 -31
  124. data/doc/css/fonts.css +0 -167
  125. data/doc/css/rdoc.css +0 -590
  126. data/doc/examples/flat_txt.html +0 -138
  127. data/doc/examples/graph_html.html +0 -909
  128. data/doc/examples/graph_txt.html +0 -247
  129. data/doc/fonts/Lato-Light.ttf +0 -0
  130. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  131. data/doc/fonts/Lato-Regular.ttf +0 -0
  132. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  133. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  134. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  135. data/doc/images/add.png +0 -0
  136. data/doc/images/arrow_up.png +0 -0
  137. data/doc/images/brick.png +0 -0
  138. data/doc/images/brick_link.png +0 -0
  139. data/doc/images/bug.png +0 -0
  140. data/doc/images/bullet_black.png +0 -0
  141. data/doc/images/bullet_toggle_minus.png +0 -0
  142. data/doc/images/bullet_toggle_plus.png +0 -0
  143. data/doc/images/date.png +0 -0
  144. data/doc/images/delete.png +0 -0
  145. data/doc/images/find.png +0 -0
  146. data/doc/images/loadingAnimation.gif +0 -0
  147. data/doc/images/macFFBgHack.png +0 -0
  148. data/doc/images/package.png +0 -0
  149. data/doc/images/page_green.png +0 -0
  150. data/doc/images/page_white_text.png +0 -0
  151. data/doc/images/page_white_width.png +0 -0
  152. data/doc/images/plugin.png +0 -0
  153. data/doc/images/ruby.png +0 -0
  154. data/doc/images/tag_blue.png +0 -0
  155. data/doc/images/tag_green.png +0 -0
  156. data/doc/images/transparent.png +0 -0
  157. data/doc/images/wrench.png +0 -0
  158. data/doc/images/wrench_orange.png +0 -0
  159. data/doc/images/zoom.png +0 -0
  160. data/doc/index.html +0 -626
  161. data/doc/js/darkfish.js +0 -161
  162. data/doc/js/jquery.js +0 -4
  163. data/doc/js/navigation.js +0 -142
  164. data/doc/js/navigation.js.gz +0 -0
  165. data/doc/js/search.js +0 -109
  166. data/doc/js/search_index.js +0 -1
  167. data/doc/js/search_index.js.gz +0 -0
  168. data/doc/js/searcher.js +0 -228
  169. data/doc/js/searcher.js.gz +0 -0
  170. data/doc/table_of_contents.html +0 -942
  171. data/examples/cachegrind.out.1 +0 -114
  172. data/examples/cachegrind.out.1.32313213 +0 -114
  173. data/examples/flat.txt +0 -50
  174. data/examples/graph.dot +0 -84
  175. data/examples/graph.html +0 -823
  176. data/examples/graph.txt +0 -139
  177. data/examples/multi.flat.txt +0 -23
  178. data/examples/multi.graph.html +0 -760
  179. data/examples/multi.grind.dat +0 -114
  180. data/examples/multi.stack.html +0 -547
  181. data/examples/stack.html +0 -547
  182. data/ext/ruby_prof/rp_measure.c +0 -40
  183. data/ext/ruby_prof/rp_measure.h +0 -45
  184. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  185. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  186. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  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/lib/ruby-prof/aggregate_call_info.rb +0 -76
  190. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  191. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  192. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -64
  193. data/test/aggregate_test.rb +0 -136
  194. data/test/block_test.rb +0 -74
  195. data/test/call_info_test.rb +0 -78
  196. data/test/issue137_test.rb +0 -63
  197. data/test/measure_cpu_time_test.rb +0 -213
  198. data/test/measure_gc_runs_test.rb +0 -32
  199. data/test/measure_gc_time_test.rb +0 -36
  200. data/test/measure_memory_test.rb +0 -33
  201. data/test/method_elimination_test.rb +0 -84
  202. data/test/module_test.rb +0 -45
  203. data/test/stack_test.rb +0 -138
@@ -1,63 +1,849 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- class MeasureProcessTimeTest < 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
- expected_number_of_methods =
35
- case RUBY_VERSION
36
- when /^1\.9\.3/ then 16
37
- when /^2\.0/ then 15
38
- when /^2\.(1|2)/ then 14
39
- else 13
40
- end
41
- # puts methods.map(&:full_name).inspect
42
- assert_equal expected_number_of_methods, methods.length
43
-
44
- # Check times
45
- assert_equal("MeasureProcessTimeTest#test_primes", methods[0].full_name)
46
- assert_in_delta(total_time, methods[0].total_time, 0.02)
47
- assert_in_delta(0.0, methods[0].wait_time, 0.01)
48
- assert_in_delta(0.0, methods[0].self_time, 0.01)
49
-
50
- assert_equal("Object#run_primes", methods[1].full_name)
51
- assert_in_delta(total_time, methods[1].total_time, 0.02)
52
- assert_in_delta(0.0, methods[1].wait_time, 0.01)
53
- assert_in_delta(0.0, methods[1].self_time, 0.01)
54
-
55
- assert_equal("Object#find_primes", methods[2].full_name)
56
- assert_equal("Array#select", methods[3].full_name)
57
- assert_equal("Object#is_prime", methods[4].full_name)
58
- assert_equal("Integer#upto", methods[5].full_name)
59
- assert_equal("Object#make_random_array", methods[6].full_name)
60
- assert_equal("Array#each_index", methods[7].full_name)
61
- assert_equal("Kernel#rand", methods[8].full_name)
62
- end
63
- 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
+ root_methods = thread.root_methods
27
+ assert_equal(1, root_methods.count)
28
+ assert_equal("MeasureProcessTimeTest#test_class_methods_sleep", root_methods.first.full_name)
29
+
30
+ methods = result.threads.first.methods.sort.reverse
31
+ assert_equal(3, methods.length)
32
+
33
+ # Check times
34
+ method = methods[0]
35
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
36
+ assert_in_delta(0.0, method.total_time, 0.05)
37
+ assert_in_delta(0.0, method.wait_time, 0.05)
38
+ assert_in_delta(0.0, method.self_time, 0.05)
39
+ assert_in_delta(0.0, method.children_time, 0.05)
40
+
41
+ method = methods[1]
42
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
43
+ assert_in_delta(0.0, method.total_time, 0.05)
44
+ assert_in_delta(0.0, method.wait_time, 0.05)
45
+ assert_in_delta(0.0, method.self_time, 0.05)
46
+ assert_in_delta(0.0, method.children_time, 0.05)
47
+
48
+ method = methods[2]
49
+ assert_equal('Kernel#sleep', method.full_name)
50
+ assert_in_delta(0.0, method.total_time, 0.05)
51
+ assert_in_delta(0.0, method.wait_time, 0.05)
52
+ assert_in_delta(0.0, method.self_time, 0.05)
53
+ assert_in_delta(0.0, method.children_time, 0.05)
54
+ end
55
+
56
+ def test_class_methods_sleep_threaded
57
+ result = RubyProf.profile do
58
+ background_thread = Thread.new do
59
+ RubyProf::C1.sleep_wait
60
+ end
61
+ background_thread.join
62
+ end
63
+
64
+ assert_equal(2, result.threads.count)
65
+
66
+ thread = result.threads.first
67
+ assert_in_delta(0.0, thread.total_time, 0.05)
68
+
69
+ root_methods = thread.root_methods
70
+ assert_equal(1, root_methods.count)
71
+ assert_equal("MeasureProcessTimeTest#test_class_methods_sleep_threaded", root_methods.first.full_name)
72
+
73
+ methods = result.threads.first.methods.sort.reverse
74
+ assert_equal(4, methods.length)
75
+
76
+ # Check times
77
+ method = methods[0]
78
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
79
+ assert_in_delta(0.0, method.total_time, 0.05)
80
+ assert_in_delta(0.0, method.wait_time, 0.05)
81
+ assert_in_delta(0.0, method.self_time, 0.05)
82
+ assert_in_delta(0.0, method.children_time, 0.05)
83
+
84
+ method = methods[1]
85
+ assert_equal('Thread#join', method.full_name)
86
+ assert_in_delta(0.0, method.total_time, 0.05)
87
+ assert_in_delta(0.0, method.wait_time, 0.05)
88
+ assert_in_delta(0.0, method.self_time, 0.05)
89
+ assert_in_delta(0.0, method.children_time, 0.05)
90
+
91
+ method = methods[2]
92
+ assert_equal('<Class::Thread>#new', method.full_name)
93
+ assert_in_delta(0.0, method.total_time, 0.05)
94
+ assert_in_delta(0.0, method.wait_time, 0.05)
95
+ assert_in_delta(0.0, method.self_time, 0.05)
96
+ assert_in_delta(0.0, method.children_time, 0.05)
97
+
98
+ method = methods[3]
99
+ assert_equal('Thread#initialize', method.full_name)
100
+ assert_in_delta(0.0, method.total_time, 0.05)
101
+ assert_in_delta(0.0, method.wait_time, 0.05)
102
+ assert_in_delta(0.0, method.self_time, 0.05)
103
+ assert_in_delta(0.0, method.children_time, 0.05)
104
+
105
+ thread = result.threads.last
106
+ assert_in_delta(0.0, thread.total_time, 0.05)
107
+
108
+ root_methods = thread.root_methods
109
+ assert_equal(1, root_methods.count)
110
+ assert_equal("MeasureProcessTimeTest#test_class_methods_sleep_threaded", root_methods.first.full_name)
111
+
112
+ methods = result.threads.first.methods.sort.reverse
113
+ assert_equal(4, methods.length)
114
+
115
+ methods = result.threads.last.methods.sort.reverse
116
+ assert_equal(3, methods.length)
117
+
118
+ # Check times
119
+ method = methods[0]
120
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
121
+ assert_in_delta(0.0, method.total_time, 0.05)
122
+ assert_in_delta(0.0, method.wait_time, 0.05)
123
+ assert_in_delta(0.0, method.self_time, 0.05)
124
+ assert_in_delta(0.0, method.children_time, 0.05)
125
+
126
+ method = methods[1]
127
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
128
+ assert_in_delta(0.0, method.total_time, 0.05)
129
+ assert_in_delta(0.0, method.wait_time, 0.05)
130
+ assert_in_delta(0.0, method.self_time, 0.05)
131
+ assert_in_delta(0.0, method.children_time, 0.05)
132
+
133
+ method = methods[2]
134
+ assert_equal('Kernel#sleep', method.full_name)
135
+ assert_in_delta(0.0, method.total_time, 0.05)
136
+ assert_in_delta(0.0, method.wait_time, 0.05)
137
+ assert_in_delta(0.0, method.self_time, 0.05)
138
+ assert_in_delta(0.0, method.children_time, 0.05)
139
+ end
140
+
141
+ def test_class_methods_busy
142
+ result = RubyProf.profile do
143
+ RubyProf::C1.busy_wait
144
+ end
145
+
146
+ thread = result.threads.first
147
+ assert_in_delta(0.08, thread.total_time, 0.05)
148
+
149
+ root_methods = thread.root_methods
150
+ assert_equal(1, root_methods.count)
151
+ assert_equal("MeasureProcessTimeTest#test_class_methods_busy", root_methods.first.full_name)
152
+
153
+ methods = result.threads.first.methods.sort.reverse
154
+ assert_equal(3, methods.length)
155
+
156
+ # Check times
157
+ method = methods[0]
158
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
159
+ assert_in_delta(0.1, method.total_time, 0.05)
160
+ assert_in_delta(0.0, method.wait_time, 0.05)
161
+ assert_in_delta(0.0, method.self_time, 0.05)
162
+ assert_in_delta(0.1, method.children_time, 0.05)
163
+
164
+ method = methods[1]
165
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
166
+ assert_in_delta(0.1, method.total_time, 0.05)
167
+ assert_in_delta(0.0, method.wait_time, 0.05)
168
+ assert_in_delta(0.06, method.self_time, 0.05)
169
+ assert_in_delta(0.07, method.children_time, 0.05)
170
+
171
+ method = methods[2]
172
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
173
+ assert_in_delta(0.05, method.total_time, 0.05)
174
+ assert_in_delta(0.0, method.wait_time, 0.05)
175
+ assert_in_delta(0.05, method.self_time, 0.05)
176
+ assert_in_delta(0.0, method.children_time, 0.05)
177
+ end
178
+
179
+ def test_class_methods_busy_threaded
180
+ result = RubyProf.profile do
181
+ background_thread = Thread.new do
182
+ RubyProf::C1.busy_wait
183
+ end
184
+ background_thread.join
185
+ end
186
+
187
+ assert_equal(2, result.threads.count)
188
+
189
+ thread = result.threads.first
190
+ assert_in_delta(0.1, thread.total_time, 0.05)
191
+
192
+ root_methods = thread.root_methods
193
+ assert_equal(1, root_methods.count)
194
+ assert_equal("MeasureProcessTimeTest#test_class_methods_busy_threaded", root_methods.first.full_name)
195
+
196
+ methods = result.threads.first.methods.sort.reverse
197
+ assert_equal(4, methods.length)
198
+
199
+ # Check times
200
+ method = methods[0]
201
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
202
+ assert_in_delta(0.1, method.total_time, 0.05)
203
+ assert_in_delta(0.0, method.wait_time, 0.05)
204
+ assert_in_delta(0.0, method.self_time, 0.05)
205
+ assert_in_delta(0.1, method.children_time, 0.05)
206
+
207
+ method = methods[1]
208
+ assert_equal('Thread#join', method.full_name)
209
+ assert_in_delta(0.1, method.total_time, 0.05)
210
+ assert_in_delta(0.1, method.wait_time, 0.05)
211
+ assert_in_delta(0.0, method.self_time, 0.05)
212
+ assert_in_delta(0.0, method.children_time, 0.05)
213
+
214
+ method = methods[2]
215
+ assert_equal('<Class::Thread>#new', method.full_name)
216
+ assert_in_delta(0.0, method.total_time, 0.05)
217
+ assert_in_delta(0.0, method.wait_time, 0.05)
218
+ assert_in_delta(0.0, method.self_time, 0.05)
219
+ assert_in_delta(0.0, method.children_time, 0.05)
220
+
221
+ method = methods[3]
222
+ assert_equal('Thread#initialize', method.full_name)
223
+ assert_in_delta(0.0, method.total_time, 0.05)
224
+ assert_in_delta(0.0, method.wait_time, 0.05)
225
+ assert_in_delta(0.0, method.self_time, 0.05)
226
+ assert_in_delta(0.0, method.children_time, 0.05)
227
+
228
+ thread = result.threads.last
229
+ assert_in_delta(0.1, thread.total_time, 0.05)
230
+
231
+ root_methods = thread.root_methods
232
+ assert_equal(1, root_methods.count)
233
+ assert_equal("MeasureProcessTimeTest#test_class_methods_busy_threaded", root_methods.first.full_name)
234
+
235
+ methods = result.threads.first.methods.sort.reverse
236
+ assert_equal(4, methods.length)
237
+
238
+ methods = result.threads.last.methods.sort.reverse
239
+ assert_equal(3, methods.length)
240
+
241
+ # Check times
242
+ method = methods[0]
243
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
244
+ assert_in_delta(0.1, method.total_time, 0.05)
245
+ assert_in_delta(0.0, method.wait_time, 0.05)
246
+ assert_in_delta(0.0, method.self_time, 0.05)
247
+ assert_in_delta(0.1, method.children_time, 0.05)
248
+
249
+ method = methods[1]
250
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
251
+ assert_in_delta(0.1, method.total_time, 0.05)
252
+ assert_in_delta(0.0, method.wait_time, 0.05)
253
+ assert_in_delta(0.05, method.self_time, 0.05)
254
+ assert_in_delta(0.05, method.children_time, 0.05)
255
+
256
+ method = methods[2]
257
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
258
+ assert_in_delta(0.05, method.total_time, 0.05)
259
+ assert_in_delta(0.0, method.wait_time, 0.05)
260
+ assert_in_delta(0.05, method.self_time, 0.05)
261
+ assert_in_delta(0.0, method.children_time, 0.05)
262
+ end
263
+
264
+ def test_instance_methods_sleep
265
+ result = RubyProf.profile do
266
+ RubyProf::C1.new.sleep_wait
267
+ end
268
+
269
+ thread = result.threads.first
270
+ assert_in_delta(0.0, thread.total_time, 0.05)
271
+
272
+ root_methods = thread.root_methods
273
+ assert_equal(1, root_methods.count)
274
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep", root_methods.first.full_name)
275
+
276
+ methods = result.threads.first.methods.sort.reverse
277
+ assert_equal(5, methods.length)
278
+
279
+ # Check times
280
+ method = methods[0]
281
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', 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
+
287
+ method = methods[1]
288
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
289
+ assert_in_delta(0.0, method.total_time, 0.05)
290
+ assert_in_delta(0.0, method.wait_time, 0.05)
291
+ assert_in_delta(0.0, method.self_time, 0.05)
292
+ assert_in_delta(0.0, method.children_time, 0.05)
293
+
294
+ method = methods[2]
295
+ assert_equal('Kernel#sleep', method.full_name)
296
+ assert_in_delta(0.0, method.total_time, 0.05)
297
+ assert_in_delta(0.0, method.wait_time, 0.05)
298
+ assert_in_delta(0.0, method.self_time, 0.05)
299
+ assert_in_delta(0.0, method.children_time, 0.05)
300
+
301
+ method = methods[3]
302
+ assert_equal('Class#new', method.full_name)
303
+ assert_in_delta(0.0, method.total_time, 0.05)
304
+ assert_in_delta(0.0, method.wait_time, 0.05)
305
+ assert_in_delta(0.0, method.self_time, 0.05)
306
+ assert_in_delta(0.0, method.children_time, 0.05)
307
+
308
+ method = methods[4]
309
+ assert_equal('BasicObject#initialize', method.full_name)
310
+ assert_in_delta(0.0, method.total_time, 0.05)
311
+ assert_in_delta(0.0, method.wait_time, 0.05)
312
+ assert_in_delta(0.0, method.self_time, 0.05)
313
+ assert_in_delta(0.0, method.children_time, 0.05)
314
+ end
315
+
316
+ def test_instance_methods_sleep_block
317
+ result = RubyProf.profile do
318
+ 1.times { RubyProf::C1.new.sleep_wait }
319
+ end
320
+
321
+ methods = result.threads.first.methods.sort.reverse
322
+ assert_equal(6, methods.length)
323
+
324
+ # Check times
325
+ method = methods[0]
326
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", 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[1]
333
+ assert_equal('Integer#times', 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
+
339
+ method = methods[2]
340
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
341
+ assert_in_delta(0.0, method.total_time, 0.05)
342
+ assert_in_delta(0.0, method.wait_time, 0.05)
343
+ assert_in_delta(0.0, method.self_time, 0.05)
344
+ assert_in_delta(0.0, method.children_time, 0.05)
345
+
346
+ method = methods[3]
347
+ assert_equal('Kernel#sleep', method.full_name)
348
+ assert_in_delta(0.0, method.total_time, 0.05)
349
+ assert_in_delta(0.0, method.wait_time, 0.05)
350
+ assert_in_delta(0.0, method.self_time, 0.05)
351
+ assert_in_delta(0.0, method.children_time, 0.05)
352
+
353
+ method = methods[4]
354
+ assert_equal('Class#new', method.full_name)
355
+ assert_in_delta(0.0, method.total_time, 0.05)
356
+ assert_in_delta(0.0, method.wait_time, 0.05)
357
+ assert_in_delta(0.0, method.self_time, 0.05)
358
+ assert_in_delta(0.0, method.children_time, 0.05)
359
+
360
+ method = methods[5]
361
+ assert_equal('BasicObject#initialize', method.full_name)
362
+ assert_in_delta(0.0, method.total_time, 0.05)
363
+ assert_in_delta(0.0, method.wait_time, 0.05)
364
+ assert_in_delta(0.0, method.self_time, 0.05)
365
+ assert_in_delta(0.0, method.children_time, 0.05)
366
+ end
367
+
368
+ def test_instance_methods_sleep_threaded
369
+ result = RubyProf.profile do
370
+ background_thread = Thread.new do
371
+ RubyProf::C1.new.sleep_wait
372
+ end
373
+ background_thread.join
374
+ end
375
+
376
+ assert_equal(2, result.threads.count)
377
+
378
+ thread = result.threads.first
379
+ assert_in_delta(0.0, thread.total_time, 0.05)
380
+
381
+ root_methods = thread.root_methods
382
+ assert_equal(1, root_methods.count)
383
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_threaded", root_methods.first.full_name)
384
+
385
+ methods = result.threads.first.methods.sort.reverse
386
+ assert_equal(4, methods.length)
387
+
388
+ # Check times
389
+ method = methods[0]
390
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
391
+ assert_in_delta(0.0, method.total_time, 0.05)
392
+ assert_in_delta(0.0, method.wait_time, 0.05)
393
+ assert_in_delta(0.0, method.self_time, 0.05)
394
+ assert_in_delta(0.0, method.children_time, 0.05)
395
+
396
+ method = methods[1]
397
+ assert_equal('Thread#join', method.full_name)
398
+ assert_in_delta(0.0, method.total_time, 0.05)
399
+ assert_in_delta(0.0, method.wait_time, 0.05)
400
+ assert_in_delta(0.0, method.self_time, 0.05)
401
+ assert_in_delta(0.0, method.children_time, 0.05)
402
+
403
+ method = methods[2]
404
+ assert_equal('<Class::Thread>#new', method.full_name)
405
+ assert_in_delta(0.0, method.total_time, 0.05)
406
+ assert_in_delta(0.0, method.wait_time, 0.05)
407
+ assert_in_delta(0.0, method.self_time, 0.05)
408
+ assert_in_delta(0.0, method.children_time, 0.05)
409
+
410
+ method = methods[3]
411
+ assert_equal('Thread#initialize', method.full_name)
412
+ assert_in_delta(0.0, method.total_time, 0.05)
413
+ assert_in_delta(0.0, method.wait_time, 0.05)
414
+ assert_in_delta(0.0, method.self_time, 0.05)
415
+ assert_in_delta(0.0, method.children_time, 0.05)
416
+
417
+ thread = result.threads.last
418
+ assert_in_delta(0.0, thread.total_time, 0.05)
419
+
420
+ root_methods = thread.root_methods
421
+ assert_equal(1, root_methods.count)
422
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_threaded", root_methods.first.full_name)
423
+
424
+ methods = result.threads.first.methods.sort.reverse
425
+ assert_equal(4, methods.length)
426
+
427
+ methods = result.threads.last.methods.sort.reverse
428
+ assert_equal(5, methods.length)
429
+
430
+ # Check times
431
+ method = methods[0]
432
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
433
+ assert_in_delta(0.0, method.total_time, 0.05)
434
+ assert_in_delta(0.0, method.wait_time, 0.05)
435
+ assert_in_delta(0.0, method.self_time, 0.05)
436
+ assert_in_delta(0.0, method.children_time, 0.05)
437
+
438
+ method = methods[1]
439
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
440
+ assert_in_delta(0.0, method.total_time, 0.05)
441
+ assert_in_delta(0.0, method.wait_time, 0.05)
442
+ assert_in_delta(0.0, method.self_time, 0.05)
443
+ assert_in_delta(0.0, method.children_time, 0.05)
444
+
445
+ method = methods[2]
446
+ assert_equal('Kernel#sleep', method.full_name)
447
+ assert_in_delta(0.0, method.total_time, 0.05)
448
+ assert_in_delta(0.0, method.wait_time, 0.05)
449
+ assert_in_delta(0.0, method.self_time, 0.05)
450
+ assert_in_delta(0.0, method.children_time, 0.05)
451
+
452
+ method = methods[3]
453
+ assert_equal('Class#new', method.full_name)
454
+ assert_in_delta(0.0, method.total_time, 0.05)
455
+ assert_in_delta(0.0, method.wait_time, 0.05)
456
+ assert_in_delta(0.0, method.self_time, 0.05)
457
+ assert_in_delta(0.0, method.children_time, 0.05)
458
+
459
+ method = methods[4]
460
+ assert_equal('BasicObject#initialize', method.full_name)
461
+ assert_in_delta(0.0, method.total_time, 0.05)
462
+ assert_in_delta(0.0, method.wait_time, 0.05)
463
+ assert_in_delta(0.0, method.self_time, 0.05)
464
+ assert_in_delta(0.0, method.children_time, 0.05)
465
+ end
466
+
467
+ def test_instance_methods_busy
468
+ result = RubyProf.profile do
469
+ RubyProf::C1.new.busy_wait
470
+ end
471
+
472
+ thread = result.threads.first
473
+ assert_in_delta(0.2, thread.total_time, 0.05)
474
+
475
+ root_methods = thread.root_methods
476
+ assert_equal(1, root_methods.count)
477
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy", root_methods.first.full_name)
478
+
479
+ methods = result.threads.first.methods.sort.reverse
480
+ assert_equal(5, methods.length)
481
+
482
+ # Check times
483
+ method = methods[0]
484
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
485
+ assert_in_delta(0.2, method.total_time, 0.05)
486
+ assert_in_delta(0.0, method.wait_time, 0.05)
487
+ assert_in_delta(0.0, method.self_time, 0.05)
488
+ assert_in_delta(0.2, method.children_time, 0.05)
489
+
490
+ method = methods[1]
491
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
492
+ assert_in_delta(0.2, method.total_time, 0.05)
493
+ assert_in_delta(0.0, method.wait_time, 0.05)
494
+ assert_in_delta(0.09, method.self_time, 0.05)
495
+ assert_in_delta(0.11, method.children_time, 0.05)
496
+
497
+ method = methods[2]
498
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
499
+ assert_in_delta(0.11, method.total_time, 0.05)
500
+ assert_in_delta(0.0, method.wait_time, 0.05)
501
+ assert_in_delta(0.11, method.self_time, 0.05)
502
+ assert_in_delta(0.0, method.children_time, 0.05)
503
+
504
+ method = methods[3]
505
+ assert_equal('Class#new', method.full_name)
506
+ assert_in_delta(0.0, method.total_time, 0.05)
507
+ assert_in_delta(0.0, method.wait_time, 0.05)
508
+ assert_in_delta(0.0, method.self_time, 0.05)
509
+ assert_in_delta(0.0, method.children_time, 0.05)
510
+
511
+ method = methods[4]
512
+ assert_equal('BasicObject#initialize', method.full_name)
513
+ assert_in_delta(0.0, method.total_time, 0.05)
514
+ assert_in_delta(0.0, method.wait_time, 0.05)
515
+ assert_in_delta(0.0, method.self_time, 0.05)
516
+ assert_in_delta(0.0, method.children_time, 0.05)
517
+ end
518
+
519
+ def test_instance_methods_busy_block
520
+ result = RubyProf.profile do
521
+ 1.times { RubyProf::C1.new.busy_wait }
522
+ end
523
+
524
+ methods = result.threads.first.methods.sort.reverse
525
+ assert_equal(6, methods.length)
526
+
527
+ # Check times
528
+ method = methods[0]
529
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
530
+ assert_in_delta(0.2, method.total_time, 0.05)
531
+ assert_in_delta(0.0, method.wait_time, 0.05)
532
+ assert_in_delta(0.0, method.self_time, 0.05)
533
+ assert_in_delta(0.2, method.children_time, 0.05)
534
+
535
+ method = methods[1]
536
+ assert_equal('Integer#times', method.full_name)
537
+ assert_in_delta(0.2, method.total_time, 0.05)
538
+ assert_in_delta(0.0, method.wait_time, 0.05)
539
+ assert_in_delta(0.0, method.self_time, 0.05)
540
+ assert_in_delta(0.2, method.children_time, 0.05)
541
+
542
+ method = methods[2]
543
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
544
+ assert_in_delta(0.2, method.total_time, 0.05)
545
+ assert_in_delta(0.0, method.wait_time, 0.05)
546
+ assert_in_delta(0.09, method.self_time, 0.05)
547
+ assert_in_delta(0.11, method.children_time, 0.05)
548
+
549
+ method = methods[3]
550
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
551
+ assert_in_delta(0.11, method.total_time, 0.05)
552
+ assert_in_delta(0.0, method.wait_time, 0.05)
553
+ assert_in_delta(0.11, method.self_time, 0.05)
554
+ assert_in_delta(0.0, method.children_time, 0.05)
555
+
556
+ method = methods[4]
557
+ assert_equal('Class#new', method.full_name)
558
+ assert_in_delta(0.0, method.total_time, 0.05)
559
+ assert_in_delta(0.0, method.wait_time, 0.05)
560
+ assert_in_delta(0.0, method.self_time, 0.05)
561
+ assert_in_delta(0.0, method.children_time, 0.05)
562
+
563
+ method = methods[5]
564
+ assert_equal('BasicObject#initialize', method.full_name)
565
+ assert_in_delta(0.0, method.total_time, 0.05)
566
+ assert_in_delta(0.0, method.wait_time, 0.05)
567
+ assert_in_delta(0.0, method.self_time, 0.05)
568
+ assert_in_delta(0.0, method.children_time, 0.05)
569
+ end
570
+
571
+ def test_instance_methods_busy_threaded
572
+ result = RubyProf.profile do
573
+ background_thread = Thread.new do
574
+ RubyProf::C1.new.busy_wait
575
+ end
576
+ background_thread.join
577
+ end
578
+
579
+ assert_equal(2, result.threads.count)
580
+
581
+ thread = result.threads.first
582
+ assert_in_delta(0.2, thread.total_time, 0.05)
583
+
584
+ root_methods = thread.root_methods
585
+ assert_equal(1, root_methods.count)
586
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_threaded", root_methods.first.full_name)
587
+
588
+ methods = result.threads.first.methods.sort.reverse
589
+ assert_equal(4, methods.length)
590
+
591
+ # Check times
592
+ method = methods[0]
593
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
594
+ assert_in_delta(0.2, method.total_time, 0.05)
595
+ assert_in_delta(0.0, method.wait_time, 0.05)
596
+ assert_in_delta(0.0, method.self_time, 0.05)
597
+ assert_in_delta(0.2, method.children_time, 0.05)
598
+
599
+ method = methods[1]
600
+ assert_equal('Thread#join', method.full_name)
601
+ assert_in_delta(0.2, method.total_time, 0.05)
602
+ assert_in_delta(0.2, method.wait_time, 0.05)
603
+ assert_in_delta(0.0, method.self_time, 0.05)
604
+ assert_in_delta(0.0, method.children_time, 0.05)
605
+
606
+ method = methods[2]
607
+ assert_equal('<Class::Thread>#new', method.full_name)
608
+ assert_in_delta(0.0, method.total_time, 0.05)
609
+ assert_in_delta(0.0, method.wait_time, 0.05)
610
+ assert_in_delta(0.0, method.self_time, 0.05)
611
+ assert_in_delta(0.0, method.children_time, 0.05)
612
+
613
+ method = methods[3]
614
+ assert_equal('Thread#initialize', method.full_name)
615
+ assert_in_delta(0.0, method.total_time, 0.05)
616
+ assert_in_delta(0.0, method.wait_time, 0.05)
617
+ assert_in_delta(0.0, method.self_time, 0.05)
618
+ assert_in_delta(0.0, method.children_time, 0.05)
619
+
620
+ thread = result.threads.last
621
+ assert_in_delta(0.2, thread.total_time, 0.05)
622
+
623
+ root_methods = thread.root_methods
624
+ assert_equal(1, root_methods.count)
625
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_threaded", root_methods.first.full_name)
626
+
627
+ methods = result.threads.first.methods.sort.reverse
628
+ assert_equal(4, methods.length)
629
+
630
+ methods = result.threads.last.methods.sort.reverse
631
+ assert_equal(5, methods.length)
632
+
633
+ # Check times
634
+ method = methods[0]
635
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
636
+ assert_in_delta(0.2, 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.2, method.children_time, 0.05)
640
+
641
+ method = methods[1]
642
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
643
+ assert_in_delta(0.2, method.total_time, 0.05)
644
+ assert_in_delta(0.0, method.wait_time, 0.05)
645
+ assert_in_delta(0.1, method.self_time, 0.05)
646
+ assert_in_delta(0.1, method.children_time, 0.05)
647
+
648
+ method = methods[2]
649
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
650
+ assert_in_delta(0.1, method.total_time, 0.05)
651
+ assert_in_delta(0.0, method.wait_time, 0.05)
652
+ assert_in_delta(0.1, method.self_time, 0.05)
653
+ assert_in_delta(0.0, method.children_time, 0.05)
654
+
655
+ method = methods[3]
656
+ assert_equal('Class#new', method.full_name)
657
+ assert_in_delta(0.0, method.total_time, 0.05)
658
+ assert_in_delta(0.0, method.wait_time, 0.05)
659
+ assert_in_delta(0.0, method.self_time, 0.05)
660
+ assert_in_delta(0.0, method.children_time, 0.05)
661
+
662
+ method = methods[4]
663
+ assert_equal('BasicObject#initialize', method.full_name)
664
+ assert_in_delta(0.0, method.total_time, 0.05)
665
+ assert_in_delta(0.0, method.wait_time, 0.05)
666
+ assert_in_delta(0.0, method.self_time, 0.05)
667
+ assert_in_delta(0.0, method.children_time, 0.05)
668
+ end
669
+
670
+ def test_module_methods_sleep
671
+ result = RubyProf.profile do
672
+ RubyProf::C2.sleep_wait
673
+ end
674
+
675
+ thread = result.threads.first
676
+ assert_in_delta(0.0, thread.total_time, 0.05)
677
+
678
+ root_methods = thread.root_methods
679
+ assert_equal(1, root_methods.count)
680
+ assert_equal("MeasureProcessTimeTest#test_module_methods_sleep", root_methods.first.full_name)
681
+
682
+ methods = result.threads.first.methods.sort.reverse
683
+ assert_equal(3, methods.length)
684
+
685
+ # Check times
686
+ method = methods[0]
687
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
688
+ assert_in_delta(0.0, method.total_time, 0.05)
689
+ assert_in_delta(0.0, method.wait_time, 0.05)
690
+ assert_in_delta(0.0, method.self_time, 0.05)
691
+ assert_in_delta(0.0, method.children_time, 0.05)
692
+
693
+ method = methods[1]
694
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
695
+ assert_in_delta(0.0, method.total_time, 0.05)
696
+ assert_in_delta(0.0, method.wait_time, 0.05)
697
+ assert_in_delta(0.0, method.self_time, 0.05)
698
+ assert_in_delta(0.0, method.children_time, 0.05)
699
+
700
+ method = methods[2]
701
+ assert_equal('Kernel#sleep', method.full_name)
702
+ assert_in_delta(0.0, method.total_time, 0.05)
703
+ assert_in_delta(0.0, method.wait_time, 0.05)
704
+ assert_in_delta(0.0, method.self_time, 0.05)
705
+ assert_in_delta(0.0, method.children_time, 0.05)
706
+ end
707
+
708
+ def test_module_methods_busy
709
+ result = RubyProf.profile do
710
+ RubyProf::C2.busy_wait
711
+ end
712
+
713
+ thread = result.threads.first
714
+ assert_in_delta(0.3, thread.total_time, 0.05)
715
+
716
+ root_methods = thread.root_methods
717
+ assert_equal(1, root_methods.count)
718
+ assert_equal("MeasureProcessTimeTest#test_module_methods_busy", root_methods.first.full_name)
719
+
720
+ methods = result.threads.first.methods.sort.reverse
721
+ assert_equal(3, methods.length)
722
+
723
+ # Check times
724
+ method = methods[0]
725
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
726
+ assert_in_delta(0.3, method.total_time, 0.05)
727
+ assert_in_delta(0.0, method.wait_time, 0.05)
728
+ assert_in_delta(0.0, method.self_time, 0.05)
729
+ assert_in_delta(0.3, method.children_time, 0.05)
730
+
731
+ method = methods[1]
732
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
733
+ assert_in_delta(0.3, method.total_time, 0.05)
734
+ assert_in_delta(0.0, method.wait_time, 0.05)
735
+ assert_in_delta(0.15, method.self_time, 0.05)
736
+ assert_in_delta(0.15, method.children_time, 0.05)
737
+
738
+ method = methods[2]
739
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
740
+ assert_in_delta(0.15, method.total_time, 0.05)
741
+ assert_in_delta(0.0, method.wait_time, 0.05)
742
+ assert_in_delta(0.15, method.self_time, 0.05)
743
+ assert_in_delta(0.0, method.children_time, 0.05)
744
+ end
745
+
746
+ def test_module_instance_methods_sleep
747
+ result = RubyProf.profile do
748
+ RubyProf::C2.new.sleep_wait
749
+ end
750
+
751
+ thread = result.threads.first
752
+ assert_in_delta(0.0, thread.total_time, 0.05)
753
+
754
+ root_methods = thread.root_methods
755
+ assert_equal(1, root_methods.count)
756
+ assert_equal("MeasureProcessTimeTest#test_module_instance_methods_sleep", root_methods.first.full_name)
757
+
758
+ methods = result.threads.first.methods.sort.reverse
759
+ assert_equal(5, methods.length)
760
+
761
+ # Check times
762
+ method = methods[0]
763
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
764
+ assert_in_delta(0.0, method.total_time, 0.05)
765
+ assert_in_delta(0.0, method.wait_time, 0.05)
766
+ assert_in_delta(0.0, method.self_time, 0.05)
767
+ assert_in_delta(0.0, method.children_time, 0.05)
768
+
769
+ method = methods[1]
770
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
771
+ assert_in_delta(0.0, method.total_time, 0.05)
772
+ assert_in_delta(0.0, method.wait_time, 0.05)
773
+ assert_in_delta(0.0, method.self_time, 0.05)
774
+ assert_in_delta(0.0, method.children_time, 0.05)
775
+
776
+ method = methods[2]
777
+ assert_equal('Kernel#sleep', method.full_name)
778
+ assert_in_delta(0.0, method.total_time, 0.05)
779
+ assert_in_delta(0.0, method.wait_time, 0.05)
780
+ assert_in_delta(0.0, method.self_time, 0.05)
781
+ assert_in_delta(0.0, method.children_time, 0.05)
782
+
783
+ method = methods[3]
784
+ assert_equal('Class#new', method.full_name)
785
+ assert_in_delta(0.0, method.total_time, 0.05)
786
+ assert_in_delta(0.0, method.wait_time, 0.05)
787
+ assert_in_delta(0.0, method.self_time, 0.05)
788
+ assert_in_delta(0.0, method.children_time, 0.05)
789
+
790
+ method = methods[4]
791
+ assert_equal('BasicObject#initialize', method.full_name)
792
+ assert_in_delta(0.0, method.total_time, 0.05)
793
+ assert_in_delta(0.0, method.wait_time, 0.05)
794
+ assert_in_delta(0.0, method.self_time, 0.05)
795
+ assert_in_delta(0.0, method.children_time, 0.05)
796
+ end
797
+
798
+ def test_module_instance_methods_busy
799
+ result = RubyProf.profile do
800
+ RubyProf::C2.new.busy_wait
801
+ end
802
+
803
+ thread = result.threads.first
804
+ assert_in_delta(0.3, thread.total_time, 0.05)
805
+
806
+ root_methods = thread.root_methods
807
+ assert_equal(1, root_methods.count)
808
+ assert_equal("MeasureProcessTimeTest#test_module_instance_methods_busy", root_methods.first.full_name)
809
+
810
+ methods = result.threads.first.methods.sort.reverse
811
+ assert_equal(5, methods.length)
812
+
813
+ # Check times
814
+ method = methods[0]
815
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
816
+ assert_in_delta(0.3, method.total_time, 0.05)
817
+ assert_in_delta(0.0, method.wait_time, 0.05)
818
+ assert_in_delta(0.0, method.self_time, 0.05)
819
+ assert_in_delta(0.3, method.children_time, 0.05)
820
+
821
+ method = methods[1]
822
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
823
+ assert_in_delta(0.3, method.total_time, 0.05)
824
+ assert_in_delta(0.0, method.wait_time, 0.05)
825
+ assert_in_delta(0.15, method.self_time, 0.05)
826
+ assert_in_delta(0.15, method.children_time, 0.05)
827
+
828
+ method = methods[2]
829
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
830
+ assert_in_delta(0.15, method.total_time, 0.05)
831
+ assert_in_delta(0.0, method.wait_time, 0.05)
832
+ assert_in_delta(0.15, method.self_time, 0.05)
833
+ assert_in_delta(0.0, method.children_time, 0.05)
834
+
835
+ method = methods[3]
836
+ assert_equal('Class#new', method.full_name)
837
+ assert_in_delta(0.0, method.total_time, 0.05)
838
+ assert_in_delta(0.0, method.wait_time, 0.05)
839
+ assert_in_delta(0.0, method.self_time, 0.05)
840
+ assert_in_delta(0.0, method.children_time, 0.05)
841
+
842
+ method = methods[4]
843
+ assert_equal('BasicObject#initialize', method.full_name)
844
+ assert_in_delta(0.0, method.total_time, 0.05)
845
+ assert_in_delta(0.0, method.wait_time, 0.05)
846
+ assert_in_delta(0.0, method.self_time, 0.05)
847
+ assert_in_delta(0.0, method.children_time, 0.05)
848
+ end
849
+ end