ruby-prof 1.4.4-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +608 -0
  3. data/LICENSE +25 -0
  4. data/README.md +5 -0
  5. data/Rakefile +98 -0
  6. data/bin/ruby-prof +328 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +22 -0
  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 +367 -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 +47 -0
  18. data/ext/ruby_prof/rp_measure_memory.c +46 -0
  19. data/ext/ruby_prof/rp_measure_process_time.c +66 -0
  20. data/ext/ruby_prof/rp_measure_wall_time.c +64 -0
  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 -0
  24. data/ext/ruby_prof/rp_method.h +62 -0
  25. data/ext/ruby_prof/rp_profile.c +915 -0
  26. data/ext/ruby_prof/rp_profile.h +35 -0
  27. data/ext/ruby_prof/rp_stack.c +212 -0
  28. data/ext/ruby_prof/rp_stack.h +53 -0
  29. data/ext/ruby_prof/rp_thread.c +362 -0
  30. data/ext/ruby_prof/rp_thread.h +39 -0
  31. data/ext/ruby_prof/ruby_prof.c +52 -0
  32. data/ext/ruby_prof/ruby_prof.h +26 -0
  33. data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
  34. data/ext/ruby_prof/vc/ruby_prof.vcxproj +160 -0
  35. data/lib/3.1/ruby_prof.so +0 -0
  36. data/lib/ruby-prof/assets/call_stack_printer.html.erb +711 -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 -0
  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 -0
  45. data/lib/ruby-prof/printers/abstract_printer.rb +137 -0
  46. data/lib/ruby-prof/printers/call_info_printer.rb +53 -0
  47. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -0
  48. data/lib/ruby-prof/printers/call_tree_printer.rb +147 -0
  49. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  50. data/lib/ruby-prof/printers/flat_printer.rb +53 -0
  51. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
  52. data/lib/ruby-prof/printers/graph_printer.rb +113 -0
  53. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  54. data/lib/ruby-prof/profile.rb +37 -0
  55. data/lib/ruby-prof/rack.rb +95 -0
  56. data/lib/ruby-prof/task.rb +147 -0
  57. data/lib/ruby-prof/thread.rb +20 -0
  58. data/lib/ruby-prof/version.rb +3 -0
  59. data/lib/ruby-prof.rb +52 -0
  60. data/lib/unprof.rb +10 -0
  61. data/ruby-prof.gemspec +64 -0
  62. data/test/abstract_printer_test.rb +26 -0
  63. data/test/alias_test.rb +122 -0
  64. data/test/basic_test.rb +43 -0
  65. data/test/call_tree_visitor_test.rb +32 -0
  66. data/test/call_trees_test.rb +66 -0
  67. data/test/duplicate_names_test.rb +32 -0
  68. data/test/dynamic_method_test.rb +67 -0
  69. data/test/enumerable_test.rb +21 -0
  70. data/test/exceptions_test.rb +24 -0
  71. data/test/exclude_methods_test.rb +151 -0
  72. data/test/exclude_threads_test.rb +53 -0
  73. data/test/fiber_test.rb +129 -0
  74. data/test/gc_test.rb +100 -0
  75. data/test/inverse_call_tree_test.rb +175 -0
  76. data/test/line_number_test.rb +158 -0
  77. data/test/marshal_test.rb +145 -0
  78. data/test/measure_allocations.rb +26 -0
  79. data/test/measure_allocations_test.rb +333 -0
  80. data/test/measure_memory_test.rb +688 -0
  81. data/test/measure_process_time_test.rb +1614 -0
  82. data/test/measure_times.rb +56 -0
  83. data/test/measure_wall_time_test.rb +426 -0
  84. data/test/multi_printer_test.rb +71 -0
  85. data/test/no_method_class_test.rb +15 -0
  86. data/test/pause_resume_test.rb +175 -0
  87. data/test/prime.rb +54 -0
  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 -0
  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 +430 -0
  99. data/test/singleton_test.rb +38 -0
  100. data/test/stack_printer_test.rb +64 -0
  101. data/test/start_stop_test.rb +109 -0
  102. data/test/test_helper.rb +13 -0
  103. data/test/thread_test.rb +144 -0
  104. data/test/unique_call_path_test.rb +136 -0
  105. data/test/yarv_test.rb +60 -0
  106. metadata +187 -0
@@ -0,0 +1,1614 @@
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
+ # These tests run to fast for Windows to detect any used process time
19
+ if !windows?
20
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
21
+ def test_class_methods_sleep
22
+ result = RubyProf.profile do
23
+ RubyProf::C1.sleep_wait
24
+ end
25
+
26
+ thread = result.threads.first
27
+ assert_in_delta(0.0, thread.total_time, 0.05)
28
+
29
+ methods = result.threads.first.methods.sort.reverse
30
+ assert_equal(3, methods.length)
31
+
32
+ # Check times
33
+ method = methods[0]
34
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
35
+ assert_in_delta(0.0, method.total_time, 0.05)
36
+ assert_in_delta(0.0, method.wait_time, 0.05)
37
+ assert_in_delta(0.0, method.self_time, 0.05)
38
+ assert_in_delta(0.0, method.children_time, 0.05)
39
+
40
+ method = methods[1]
41
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
42
+ assert_in_delta(0.0, method.total_time, 0.05)
43
+ assert_in_delta(0.0, method.wait_time, 0.05)
44
+ assert_in_delta(0.0, method.self_time, 0.05)
45
+ assert_in_delta(0.0, method.children_time, 0.05)
46
+
47
+ method = methods[2]
48
+ assert_equal('Kernel#sleep', method.full_name)
49
+ assert_in_delta(0.0, method.total_time, 0.05)
50
+ assert_in_delta(0.0, method.wait_time, 0.05)
51
+ assert_in_delta(0.0, method.self_time, 0.05)
52
+ assert_in_delta(0.0, method.children_time, 0.05)
53
+ end
54
+
55
+ def test_class_methods_sleep_threaded
56
+ result = RubyProf.profile do
57
+ background_thread = Thread.new do
58
+ RubyProf::C1.sleep_wait
59
+ end
60
+ background_thread.join
61
+ end
62
+
63
+ assert_equal(2, result.threads.count)
64
+
65
+ thread = result.threads.first
66
+ assert_in_delta(0.0, thread.total_time, 0.05)
67
+
68
+ methods = result.threads.first.methods.sort.reverse
69
+ assert_equal(4, methods.length)
70
+
71
+ # Check times
72
+ method = methods[0]
73
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
74
+ assert_in_delta(0.0, method.total_time, 0.05)
75
+ assert_in_delta(0.0, method.wait_time, 0.05)
76
+ assert_in_delta(0.0, method.self_time, 0.05)
77
+ assert_in_delta(0.0, method.children_time, 0.05)
78
+
79
+ method = methods[1]
80
+ assert_equal('Thread#join', method.full_name)
81
+ assert_in_delta(0.0, method.total_time, 0.05)
82
+ assert_in_delta(0.0, method.wait_time, 0.05)
83
+ assert_in_delta(0.0, method.self_time, 0.05)
84
+ assert_in_delta(0.0, method.children_time, 0.05)
85
+
86
+ method = methods[2]
87
+ assert_equal('<Class::Thread>#new', method.full_name)
88
+ assert_in_delta(0.0, method.total_time, 0.05)
89
+ assert_in_delta(0.0, method.wait_time, 0.05)
90
+ assert_in_delta(0.0, method.self_time, 0.05)
91
+ assert_in_delta(0.0, method.children_time, 0.05)
92
+
93
+ method = methods[3]
94
+ assert_equal('Thread#initialize', method.full_name)
95
+ assert_in_delta(0.0, method.total_time, 0.05)
96
+ assert_in_delta(0.0, method.wait_time, 0.05)
97
+ assert_in_delta(0.0, method.self_time, 0.05)
98
+ assert_in_delta(0.0, method.children_time, 0.05)
99
+
100
+ thread = result.threads.last
101
+ assert_in_delta(0.0, thread.total_time, 0.05)
102
+
103
+ methods = result.threads.first.methods.sort.reverse
104
+ assert_equal(4, methods.length)
105
+
106
+ methods = result.threads.last.methods.sort.reverse
107
+ assert_equal(3, methods.length)
108
+
109
+ # Check times
110
+ method = methods[0]
111
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
112
+ assert_in_delta(0.0, method.total_time, 0.05)
113
+ assert_in_delta(0.0, method.wait_time, 0.05)
114
+ assert_in_delta(0.0, method.self_time, 0.05)
115
+ assert_in_delta(0.0, method.children_time, 0.05)
116
+
117
+ method = methods[1]
118
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
119
+ assert_in_delta(0.0, method.total_time, 0.05)
120
+ assert_in_delta(0.0, method.wait_time, 0.05)
121
+ assert_in_delta(0.0, method.self_time, 0.05)
122
+ assert_in_delta(0.0, method.children_time, 0.05)
123
+
124
+ method = methods[2]
125
+ assert_equal('Kernel#sleep', method.full_name)
126
+ assert_in_delta(0.0, method.total_time, 0.05)
127
+ assert_in_delta(0.0, method.wait_time, 0.05)
128
+ assert_in_delta(0.0, method.self_time, 0.05)
129
+ assert_in_delta(0.0, method.children_time, 0.05)
130
+ end
131
+
132
+ def test_class_methods_busy
133
+ result = RubyProf.profile do
134
+ RubyProf::C1.busy_wait
135
+ end
136
+
137
+ thread = result.threads.first
138
+ assert_in_delta(0.08, thread.total_time, 0.05)
139
+
140
+ methods = result.threads.first.methods.sort.reverse
141
+ assert_equal(3, methods.length)
142
+
143
+ # Check times
144
+ method = methods[0]
145
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
146
+ assert_in_delta(0.1, method.total_time, 0.05)
147
+ assert_in_delta(0.0, method.wait_time, 0.05)
148
+ assert_in_delta(0.0, method.self_time, 0.05)
149
+ assert_in_delta(0.1, method.children_time, 0.05)
150
+
151
+ method = methods[1]
152
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
153
+ assert_in_delta(0.1, method.total_time, 0.05)
154
+ assert_in_delta(0.0, method.wait_time, 0.05)
155
+ assert_in_delta(0.06, method.self_time, 0.05)
156
+ assert_in_delta(0.07, method.children_time, 0.05)
157
+
158
+ method = methods[2]
159
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
160
+ assert_in_delta(0.05, method.total_time, 0.05)
161
+ assert_in_delta(0.0, method.wait_time, 0.05)
162
+ assert_in_delta(0.05, method.self_time, 0.05)
163
+ assert_in_delta(0.0, method.children_time, 0.05)
164
+ end
165
+
166
+ def test_class_methods_busy_threaded
167
+ result = RubyProf.profile do
168
+ background_thread = Thread.new do
169
+ RubyProf::C1.busy_wait
170
+ end
171
+ background_thread.join
172
+ end
173
+
174
+ assert_equal(2, result.threads.count)
175
+
176
+ thread = result.threads.first
177
+ assert_in_delta(0.1, thread.total_time, 0.05)
178
+
179
+ methods = result.threads.first.methods.sort.reverse
180
+ assert_equal(4, methods.length)
181
+
182
+ # Check times
183
+ method = methods[0]
184
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
185
+ assert_in_delta(0.1, method.total_time, 0.05)
186
+ assert_in_delta(0.0, method.wait_time, 0.05)
187
+ assert_in_delta(0.0, method.self_time, 0.05)
188
+ assert_in_delta(0.1, method.children_time, 0.05)
189
+
190
+ method = methods[1]
191
+ assert_equal('Thread#join', method.full_name)
192
+ assert_in_delta(0.1, method.total_time, 0.05)
193
+ assert_in_delta(0.1, method.wait_time, 0.05)
194
+ assert_in_delta(0.0, method.self_time, 0.05)
195
+ assert_in_delta(0.0, method.children_time, 0.05)
196
+
197
+ method = methods[2]
198
+ assert_equal('<Class::Thread>#new', method.full_name)
199
+ assert_in_delta(0.0, method.total_time, 0.05)
200
+ assert_in_delta(0.0, method.wait_time, 0.05)
201
+ assert_in_delta(0.0, method.self_time, 0.05)
202
+ assert_in_delta(0.0, method.children_time, 0.05)
203
+
204
+ method = methods[3]
205
+ assert_equal('Thread#initialize', method.full_name)
206
+ assert_in_delta(0.0, method.total_time, 0.05)
207
+ assert_in_delta(0.0, method.wait_time, 0.05)
208
+ assert_in_delta(0.0, method.self_time, 0.05)
209
+ assert_in_delta(0.0, method.children_time, 0.05)
210
+
211
+ thread = result.threads.last
212
+ assert_in_delta(0.1, thread.total_time, 0.05)
213
+
214
+ methods = result.threads.first.methods.sort.reverse
215
+ assert_equal(4, methods.length)
216
+
217
+ methods = result.threads.last.methods.sort.reverse
218
+ assert_equal(3, methods.length)
219
+
220
+ # Check times
221
+ method = methods[0]
222
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
223
+ assert_in_delta(0.1, 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.1, method.children_time, 0.05)
227
+
228
+ method = methods[1]
229
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
230
+ assert_in_delta(0.1, method.total_time, 0.05)
231
+ assert_in_delta(0.0, method.wait_time, 0.05)
232
+ assert_in_delta(0.05, method.self_time, 0.05)
233
+ assert_in_delta(0.05, method.children_time, 0.05)
234
+
235
+ method = methods[2]
236
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
237
+ assert_in_delta(0.05, method.total_time, 0.05)
238
+ assert_in_delta(0.0, method.wait_time, 0.05)
239
+ assert_in_delta(0.05, method.self_time, 0.05)
240
+ assert_in_delta(0.0, method.children_time, 0.05)
241
+ end
242
+
243
+ def test_instance_methods_sleep
244
+ result = RubyProf.profile do
245
+ RubyProf::C1.new.sleep_wait
246
+ end
247
+
248
+ thread = result.threads.first
249
+ assert_in_delta(0.0, thread.total_time, 0.05)
250
+
251
+ methods = result.threads.first.methods.sort.reverse
252
+ assert_equal(5, methods.length)
253
+
254
+ # Check times
255
+ method = methods[0]
256
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
257
+ assert_in_delta(0.0, method.total_time, 0.05)
258
+ assert_in_delta(0.0, method.wait_time, 0.05)
259
+ assert_in_delta(0.0, method.self_time, 0.05)
260
+ assert_in_delta(0.0, method.children_time, 0.05)
261
+
262
+ method = methods[1]
263
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
264
+ assert_in_delta(0.0, method.total_time, 0.05)
265
+ assert_in_delta(0.0, method.wait_time, 0.05)
266
+ assert_in_delta(0.0, method.self_time, 0.05)
267
+ assert_in_delta(0.0, method.children_time, 0.05)
268
+
269
+ method = methods[2]
270
+ assert_equal('Kernel#sleep', method.full_name)
271
+ assert_in_delta(0.0, method.total_time, 0.05)
272
+ assert_in_delta(0.0, method.wait_time, 0.05)
273
+ assert_in_delta(0.0, method.self_time, 0.05)
274
+ assert_in_delta(0.0, method.children_time, 0.05)
275
+
276
+ method = methods[3]
277
+ assert_equal('Class#new', method.full_name)
278
+ assert_in_delta(0.0, method.total_time, 0.05)
279
+ assert_in_delta(0.0, method.wait_time, 0.05)
280
+ assert_in_delta(0.0, method.self_time, 0.05)
281
+ assert_in_delta(0.0, method.children_time, 0.05)
282
+
283
+ method = methods[4]
284
+ assert_equal('BasicObject#initialize', method.full_name)
285
+ assert_in_delta(0.0, method.total_time, 0.05)
286
+ assert_in_delta(0.0, method.wait_time, 0.05)
287
+ assert_in_delta(0.0, method.self_time, 0.05)
288
+ assert_in_delta(0.0, method.children_time, 0.05)
289
+ end
290
+
291
+ def test_instance_methods_sleep_block
292
+ result = RubyProf.profile do
293
+ 1.times { RubyProf::C1.new.sleep_wait }
294
+ end
295
+
296
+ methods = result.threads.first.methods.sort.reverse
297
+ assert_equal(6, methods.length)
298
+
299
+ # Check times
300
+ method = methods[0]
301
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
302
+ assert_in_delta(0.0, method.total_time, 0.05)
303
+ assert_in_delta(0.0, method.wait_time, 0.05)
304
+ assert_in_delta(0.0, method.self_time, 0.05)
305
+ assert_in_delta(0.0, method.children_time, 0.05)
306
+
307
+ method = methods[1]
308
+ assert_equal('Integer#times', method.full_name)
309
+ assert_in_delta(0.0, method.total_time, 0.05)
310
+ assert_in_delta(0.0, method.wait_time, 0.05)
311
+ assert_in_delta(0.0, method.self_time, 0.05)
312
+ assert_in_delta(0.0, method.children_time, 0.05)
313
+
314
+ method = methods[2]
315
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
316
+ assert_in_delta(0.0, method.total_time, 0.05)
317
+ assert_in_delta(0.0, method.wait_time, 0.05)
318
+ assert_in_delta(0.0, method.self_time, 0.05)
319
+ assert_in_delta(0.0, method.children_time, 0.05)
320
+
321
+ method = methods[3]
322
+ assert_equal('Kernel#sleep', method.full_name)
323
+ assert_in_delta(0.0, method.total_time, 0.05)
324
+ assert_in_delta(0.0, method.wait_time, 0.05)
325
+ assert_in_delta(0.0, method.self_time, 0.05)
326
+ assert_in_delta(0.0, method.children_time, 0.05)
327
+
328
+ method = methods[4]
329
+ assert_equal('Class#new', method.full_name)
330
+ assert_in_delta(0.0, method.total_time, 0.05)
331
+ assert_in_delta(0.0, method.wait_time, 0.05)
332
+ assert_in_delta(0.0, method.self_time, 0.05)
333
+ assert_in_delta(0.0, method.children_time, 0.05)
334
+
335
+ method = methods[5]
336
+ assert_equal('BasicObject#initialize', method.full_name)
337
+ assert_in_delta(0.0, method.total_time, 0.05)
338
+ assert_in_delta(0.0, method.wait_time, 0.05)
339
+ assert_in_delta(0.0, method.self_time, 0.05)
340
+ assert_in_delta(0.0, method.children_time, 0.05)
341
+ end
342
+
343
+ def test_instance_methods_sleep_threaded
344
+ result = RubyProf.profile do
345
+ background_thread = Thread.new do
346
+ RubyProf::C1.new.sleep_wait
347
+ end
348
+ background_thread.join
349
+ end
350
+
351
+ assert_equal(2, result.threads.count)
352
+
353
+ thread = result.threads.first
354
+ assert_in_delta(0.0, thread.total_time, 0.05)
355
+
356
+ methods = result.threads.first.methods.sort.reverse
357
+ assert_equal(4, methods.length)
358
+
359
+ # Check times
360
+ method = methods[0]
361
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', 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
+
367
+ method = methods[1]
368
+ assert_equal('Thread#join', method.full_name)
369
+ assert_in_delta(0.0, method.total_time, 0.05)
370
+ assert_in_delta(0.0, method.wait_time, 0.05)
371
+ assert_in_delta(0.0, method.self_time, 0.05)
372
+ assert_in_delta(0.0, method.children_time, 0.05)
373
+
374
+ method = methods[2]
375
+ assert_equal('<Class::Thread>#new', method.full_name)
376
+ assert_in_delta(0.0, method.total_time, 0.05)
377
+ assert_in_delta(0.0, method.wait_time, 0.05)
378
+ assert_in_delta(0.0, method.self_time, 0.05)
379
+ assert_in_delta(0.0, method.children_time, 0.05)
380
+
381
+ method = methods[3]
382
+ assert_equal('Thread#initialize', method.full_name)
383
+ assert_in_delta(0.0, method.total_time, 0.05)
384
+ assert_in_delta(0.0, method.wait_time, 0.05)
385
+ assert_in_delta(0.0, method.self_time, 0.05)
386
+ assert_in_delta(0.0, method.children_time, 0.05)
387
+
388
+ thread = result.threads.last
389
+ assert_in_delta(0.0, thread.total_time, 0.05)
390
+
391
+ methods = result.threads.first.methods.sort.reverse
392
+ assert_equal(4, methods.length)
393
+
394
+ methods = result.threads.last.methods.sort.reverse
395
+ assert_equal(5, methods.length)
396
+
397
+ # Check times
398
+ method = methods[0]
399
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
400
+ assert_in_delta(0.0, method.total_time, 0.05)
401
+ assert_in_delta(0.0, method.wait_time, 0.05)
402
+ assert_in_delta(0.0, method.self_time, 0.05)
403
+ assert_in_delta(0.0, method.children_time, 0.05)
404
+
405
+ method = methods[1]
406
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
407
+ assert_in_delta(0.0, method.total_time, 0.05)
408
+ assert_in_delta(0.0, method.wait_time, 0.05)
409
+ assert_in_delta(0.0, method.self_time, 0.05)
410
+ assert_in_delta(0.0, method.children_time, 0.05)
411
+
412
+ method = methods[2]
413
+ assert_equal('Kernel#sleep', method.full_name)
414
+ assert_in_delta(0.0, method.total_time, 0.05)
415
+ assert_in_delta(0.0, method.wait_time, 0.05)
416
+ assert_in_delta(0.0, method.self_time, 0.05)
417
+ assert_in_delta(0.0, method.children_time, 0.05)
418
+
419
+ method = methods[3]
420
+ assert_equal('Class#new', method.full_name)
421
+ assert_in_delta(0.0, method.total_time, 0.05)
422
+ assert_in_delta(0.0, method.wait_time, 0.05)
423
+ assert_in_delta(0.0, method.self_time, 0.05)
424
+ assert_in_delta(0.0, method.children_time, 0.05)
425
+
426
+ method = methods[4]
427
+ assert_equal('BasicObject#initialize', method.full_name)
428
+ assert_in_delta(0.0, method.total_time, 0.05)
429
+ assert_in_delta(0.0, method.wait_time, 0.05)
430
+ assert_in_delta(0.0, method.self_time, 0.05)
431
+ assert_in_delta(0.0, method.children_time, 0.05)
432
+ end
433
+
434
+ def test_instance_methods_busy
435
+ result = RubyProf.profile do
436
+ RubyProf::C1.new.busy_wait
437
+ end
438
+
439
+ thread = result.threads.first
440
+ assert_in_delta(0.2, thread.total_time, 0.05)
441
+
442
+ methods = result.threads.first.methods.sort.reverse
443
+ assert_equal(5, methods.length)
444
+
445
+ # Check times
446
+ method = methods[0]
447
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
448
+ assert_in_delta(0.2, method.total_time, 0.05)
449
+ assert_in_delta(0.0, method.wait_time, 0.05)
450
+ assert_in_delta(0.0, method.self_time, 0.05)
451
+ assert_in_delta(0.2, method.children_time, 0.05)
452
+
453
+ method = methods[1]
454
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
455
+ assert_in_delta(0.2, method.total_time, 0.05)
456
+ assert_in_delta(0.0, method.wait_time, 0.05)
457
+ assert_in_delta(0.09, method.self_time, 0.05)
458
+ assert_in_delta(0.11, method.children_time, 0.05)
459
+
460
+ method = methods[2]
461
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
462
+ assert_in_delta(0.11, method.total_time, 0.05)
463
+ assert_in_delta(0.0, method.wait_time, 0.05)
464
+ assert_in_delta(0.11, method.self_time, 0.05)
465
+ assert_in_delta(0.0, method.children_time, 0.05)
466
+
467
+ method = methods[3]
468
+ assert_equal('Class#new', method.full_name)
469
+ assert_in_delta(0.0, method.total_time, 0.05)
470
+ assert_in_delta(0.0, method.wait_time, 0.05)
471
+ assert_in_delta(0.0, method.self_time, 0.05)
472
+ assert_in_delta(0.0, method.children_time, 0.05)
473
+
474
+ method = methods[4]
475
+ assert_equal('BasicObject#initialize', method.full_name)
476
+ assert_in_delta(0.0, method.total_time, 0.05)
477
+ assert_in_delta(0.0, method.wait_time, 0.05)
478
+ assert_in_delta(0.0, method.self_time, 0.05)
479
+ assert_in_delta(0.0, method.children_time, 0.05)
480
+ end
481
+
482
+ def test_instance_methods_busy_block
483
+ result = RubyProf.profile do
484
+ 1.times { RubyProf::C1.new.busy_wait }
485
+ end
486
+
487
+ methods = result.threads.first.methods.sort.reverse
488
+ assert_equal(6, methods.length)
489
+
490
+ # Check times
491
+ method = methods[0]
492
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
493
+ assert_in_delta(0.2, method.total_time, 0.05)
494
+ assert_in_delta(0.0, method.wait_time, 0.05)
495
+ assert_in_delta(0.0, method.self_time, 0.05)
496
+ assert_in_delta(0.2, method.children_time, 0.05)
497
+
498
+ method = methods[1]
499
+ assert_equal('Integer#times', method.full_name)
500
+ assert_in_delta(0.2, method.total_time, 0.05)
501
+ assert_in_delta(0.0, method.wait_time, 0.05)
502
+ assert_in_delta(0.0, method.self_time, 0.05)
503
+ assert_in_delta(0.2, method.children_time, 0.05)
504
+
505
+ method = methods[2]
506
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
507
+ assert_in_delta(0.2, method.total_time, 0.05)
508
+ assert_in_delta(0.0, method.wait_time, 0.05)
509
+ assert_in_delta(0.09, method.self_time, 0.05)
510
+ assert_in_delta(0.11, method.children_time, 0.05)
511
+
512
+ method = methods[3]
513
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
514
+ assert_in_delta(0.11, method.total_time, 0.05)
515
+ assert_in_delta(0.0, method.wait_time, 0.05)
516
+ assert_in_delta(0.11, method.self_time, 0.05)
517
+ assert_in_delta(0.0, method.children_time, 0.05)
518
+
519
+ method = methods[4]
520
+ assert_equal('Class#new', method.full_name)
521
+ assert_in_delta(0.0, method.total_time, 0.05)
522
+ assert_in_delta(0.0, method.wait_time, 0.05)
523
+ assert_in_delta(0.0, method.self_time, 0.05)
524
+ assert_in_delta(0.0, method.children_time, 0.05)
525
+
526
+ method = methods[5]
527
+ assert_equal('BasicObject#initialize', method.full_name)
528
+ assert_in_delta(0.0, method.total_time, 0.05)
529
+ assert_in_delta(0.0, method.wait_time, 0.05)
530
+ assert_in_delta(0.0, method.self_time, 0.05)
531
+ assert_in_delta(0.0, method.children_time, 0.05)
532
+ end
533
+
534
+ def test_instance_methods_busy_threaded
535
+ result = RubyProf.profile do
536
+ background_thread = Thread.new do
537
+ RubyProf::C1.new.busy_wait
538
+ end
539
+ background_thread.join
540
+ end
541
+
542
+ assert_equal(2, result.threads.count)
543
+
544
+ thread = result.threads.first
545
+ assert_in_delta(0.2, thread.total_time, 0.05)
546
+
547
+ methods = result.threads.first.methods.sort.reverse
548
+ assert_equal(4, methods.length)
549
+
550
+ # Check times
551
+ method = methods[0]
552
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
553
+ assert_in_delta(0.2, method.total_time, 0.05)
554
+ assert_in_delta(0.0, method.wait_time, 0.05)
555
+ assert_in_delta(0.0, method.self_time, 0.05)
556
+ assert_in_delta(0.2, method.children_time, 0.05)
557
+
558
+ method = methods[1]
559
+ assert_equal('Thread#join', method.full_name)
560
+ assert_in_delta(0.2, method.total_time, 0.05)
561
+ assert_in_delta(0.2, method.wait_time, 0.05)
562
+ assert_in_delta(0.0, method.self_time, 0.05)
563
+ assert_in_delta(0.0, method.children_time, 0.05)
564
+
565
+ method = methods[2]
566
+ assert_equal('<Class::Thread>#new', method.full_name)
567
+ assert_in_delta(0.0, method.total_time, 0.05)
568
+ assert_in_delta(0.0, method.wait_time, 0.05)
569
+ assert_in_delta(0.0, method.self_time, 0.05)
570
+ assert_in_delta(0.0, method.children_time, 0.05)
571
+
572
+ method = methods[3]
573
+ assert_equal('Thread#initialize', method.full_name)
574
+ assert_in_delta(0.0, method.total_time, 0.05)
575
+ assert_in_delta(0.0, method.wait_time, 0.05)
576
+ assert_in_delta(0.0, method.self_time, 0.05)
577
+ assert_in_delta(0.0, method.children_time, 0.05)
578
+
579
+ thread = result.threads.last
580
+ assert_in_delta(0.2, thread.total_time, 0.05)
581
+
582
+ methods = result.threads.first.methods.sort.reverse
583
+ assert_equal(4, methods.length)
584
+
585
+ methods = result.threads.last.methods.sort.reverse
586
+ assert_equal(5, methods.length)
587
+
588
+ # Check times
589
+ method = methods[0]
590
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
591
+ assert_in_delta(0.2, method.total_time, 0.05)
592
+ assert_in_delta(0.0, method.wait_time, 0.05)
593
+ assert_in_delta(0.0, method.self_time, 0.05)
594
+ assert_in_delta(0.2, method.children_time, 0.05)
595
+
596
+ method = methods[1]
597
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
598
+ assert_in_delta(0.2, method.total_time, 0.05)
599
+ assert_in_delta(0.0, method.wait_time, 0.05)
600
+ assert_in_delta(0.1, method.self_time, 0.05)
601
+ assert_in_delta(0.1, method.children_time, 0.05)
602
+
603
+ method = methods[2]
604
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
605
+ assert_in_delta(0.1, method.total_time, 0.05)
606
+ assert_in_delta(0.0, method.wait_time, 0.05)
607
+ assert_in_delta(0.1, method.self_time, 0.05)
608
+ assert_in_delta(0.0, method.children_time, 0.05)
609
+
610
+ method = methods[3]
611
+ assert_equal('Class#new', method.full_name)
612
+ assert_in_delta(0.0, method.total_time, 0.05)
613
+ assert_in_delta(0.0, method.wait_time, 0.05)
614
+ assert_in_delta(0.0, method.self_time, 0.05)
615
+ assert_in_delta(0.0, method.children_time, 0.05)
616
+
617
+ method = methods[4]
618
+ assert_equal('BasicObject#initialize', method.full_name)
619
+ assert_in_delta(0.0, method.total_time, 0.05)
620
+ assert_in_delta(0.0, method.wait_time, 0.05)
621
+ assert_in_delta(0.0, method.self_time, 0.05)
622
+ assert_in_delta(0.0, method.children_time, 0.05)
623
+ end
624
+
625
+ def test_module_methods_sleep
626
+ result = RubyProf.profile do
627
+ RubyProf::C2.sleep_wait
628
+ end
629
+
630
+ thread = result.threads.first
631
+ assert_in_delta(0.0, thread.total_time, 0.05)
632
+
633
+ methods = result.threads.first.methods.sort.reverse
634
+ assert_equal(3, methods.length)
635
+
636
+ # Check times
637
+ method = methods[0]
638
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
639
+ assert_in_delta(0.0, method.total_time, 0.05)
640
+ assert_in_delta(0.0, method.wait_time, 0.05)
641
+ assert_in_delta(0.0, method.self_time, 0.05)
642
+ assert_in_delta(0.0, method.children_time, 0.05)
643
+
644
+ method = methods[1]
645
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
646
+ assert_in_delta(0.0, method.total_time, 0.05)
647
+ assert_in_delta(0.0, method.wait_time, 0.05)
648
+ assert_in_delta(0.0, method.self_time, 0.05)
649
+ assert_in_delta(0.0, method.children_time, 0.05)
650
+
651
+ method = methods[2]
652
+ assert_equal('Kernel#sleep', method.full_name)
653
+ assert_in_delta(0.0, method.total_time, 0.05)
654
+ assert_in_delta(0.0, method.wait_time, 0.05)
655
+ assert_in_delta(0.0, method.self_time, 0.05)
656
+ assert_in_delta(0.0, method.children_time, 0.05)
657
+ end
658
+
659
+ def test_module_methods_busy
660
+ result = RubyProf.profile do
661
+ RubyProf::C2.busy_wait
662
+ end
663
+
664
+ thread = result.threads.first
665
+ assert_in_delta(0.3, thread.total_time, 0.05)
666
+
667
+ methods = result.threads.first.methods.sort.reverse
668
+ assert_equal(3, methods.length)
669
+
670
+ # Check times
671
+ method = methods[0]
672
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
673
+ assert_in_delta(0.3, method.total_time, 0.05)
674
+ assert_in_delta(0.0, method.wait_time, 0.05)
675
+ assert_in_delta(0.0, method.self_time, 0.05)
676
+ assert_in_delta(0.3, method.children_time, 0.05)
677
+
678
+ method = methods[1]
679
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
680
+ assert_in_delta(0.3, method.total_time, 0.05)
681
+ assert_in_delta(0.0, method.wait_time, 0.05)
682
+ assert_in_delta(0.15, method.self_time, 0.05)
683
+ assert_in_delta(0.15, method.children_time, 0.05)
684
+
685
+ method = methods[2]
686
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
687
+ assert_in_delta(0.15, method.total_time, 0.05)
688
+ assert_in_delta(0.0, method.wait_time, 0.05)
689
+ assert_in_delta(0.15, method.self_time, 0.05)
690
+ assert_in_delta(0.0, method.children_time, 0.05)
691
+ end
692
+
693
+ def test_module_instance_methods_sleep
694
+ result = RubyProf.profile do
695
+ RubyProf::C2.new.sleep_wait
696
+ end
697
+
698
+ thread = result.threads.first
699
+ assert_in_delta(0.0, thread.total_time, 0.05)
700
+
701
+ methods = result.threads.first.methods.sort.reverse
702
+ assert_equal(5, methods.length)
703
+
704
+ # Check times
705
+ method = methods[0]
706
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
707
+ assert_in_delta(0.0, method.total_time, 0.05)
708
+ assert_in_delta(0.0, method.wait_time, 0.05)
709
+ assert_in_delta(0.0, method.self_time, 0.05)
710
+ assert_in_delta(0.0, method.children_time, 0.05)
711
+
712
+ method = methods[1]
713
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
714
+ assert_in_delta(0.0, method.total_time, 0.05)
715
+ assert_in_delta(0.0, method.wait_time, 0.05)
716
+ assert_in_delta(0.0, method.self_time, 0.05)
717
+ assert_in_delta(0.0, method.children_time, 0.05)
718
+
719
+ method = methods[2]
720
+ assert_equal('Kernel#sleep', method.full_name)
721
+ assert_in_delta(0.0, method.total_time, 0.05)
722
+ assert_in_delta(0.0, method.wait_time, 0.05)
723
+ assert_in_delta(0.0, method.self_time, 0.05)
724
+ assert_in_delta(0.0, method.children_time, 0.05)
725
+
726
+ method = methods[3]
727
+ assert_equal('Class#new', method.full_name)
728
+ assert_in_delta(0.0, method.total_time, 0.05)
729
+ assert_in_delta(0.0, method.wait_time, 0.05)
730
+ assert_in_delta(0.0, method.self_time, 0.05)
731
+ assert_in_delta(0.0, method.children_time, 0.05)
732
+
733
+ method = methods[4]
734
+ assert_equal('BasicObject#initialize', method.full_name)
735
+ assert_in_delta(0.0, method.total_time, 0.05)
736
+ assert_in_delta(0.0, method.wait_time, 0.05)
737
+ assert_in_delta(0.0, method.self_time, 0.05)
738
+ assert_in_delta(0.0, method.children_time, 0.05)
739
+ end
740
+
741
+ def test_module_instance_methods_busy
742
+ result = RubyProf.profile do
743
+ RubyProf::C2.new.busy_wait
744
+ end
745
+
746
+ thread = result.threads.first
747
+ assert_in_delta(0.3, thread.total_time, 0.05)
748
+
749
+ methods = result.threads.first.methods.sort.reverse
750
+ assert_equal(5, methods.length)
751
+
752
+ # Check times
753
+ method = methods[0]
754
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
755
+ assert_in_delta(0.3, method.total_time, 0.05)
756
+ assert_in_delta(0.0, method.wait_time, 0.05)
757
+ assert_in_delta(0.0, method.self_time, 0.05)
758
+ assert_in_delta(0.3, method.children_time, 0.05)
759
+
760
+ method = methods[1]
761
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
762
+ assert_in_delta(0.3, method.total_time, 0.05)
763
+ assert_in_delta(0.0, method.wait_time, 0.05)
764
+ assert_in_delta(0.15, method.self_time, 0.05)
765
+ assert_in_delta(0.15, method.children_time, 0.05)
766
+
767
+ method = methods[2]
768
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
769
+ assert_in_delta(0.15, method.total_time, 0.05)
770
+ assert_in_delta(0.0, method.wait_time, 0.05)
771
+ assert_in_delta(0.15, method.self_time, 0.05)
772
+ assert_in_delta(0.0, method.children_time, 0.05)
773
+
774
+ method = methods[3]
775
+ assert_equal('Class#new', method.full_name)
776
+ assert_in_delta(0.0, method.total_time, 0.05)
777
+ assert_in_delta(0.0, method.wait_time, 0.05)
778
+ assert_in_delta(0.0, method.self_time, 0.05)
779
+ assert_in_delta(0.0, method.children_time, 0.05)
780
+
781
+ method = methods[4]
782
+ assert_equal('BasicObject#initialize', method.full_name)
783
+ assert_in_delta(0.0, method.total_time, 0.05)
784
+ assert_in_delta(0.0, method.wait_time, 0.05)
785
+ assert_in_delta(0.0, method.self_time, 0.05)
786
+ assert_in_delta(0.0, method.children_time, 0.05)
787
+ end
788
+ else
789
+ def test_class_methods_sleep
790
+ result = RubyProf.profile do
791
+ RubyProf::C1.sleep_wait
792
+ end
793
+
794
+ thread = result.threads.first
795
+ assert_in_delta(0.0, thread.total_time, 0.05)
796
+
797
+ methods = result.threads.first.methods.sort.reverse
798
+ assert_equal(3, methods.length)
799
+
800
+ # Check times
801
+ method = methods[0]
802
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
803
+ assert_in_delta(0.0, method.total_time, 0.05)
804
+ assert_in_delta(0.0, method.wait_time, 0.05)
805
+ assert_in_delta(0.0, method.self_time, 0.05)
806
+ assert_in_delta(0.0, method.children_time, 0.05)
807
+
808
+ method = methods[1]
809
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
810
+ assert_in_delta(0.0, method.total_time, 0.05)
811
+ assert_in_delta(0.0, method.wait_time, 0.05)
812
+ assert_in_delta(0.0, method.self_time, 0.05)
813
+ assert_in_delta(0.0, method.children_time, 0.05)
814
+
815
+ method = methods[2]
816
+ assert_equal('Kernel#sleep', method.full_name)
817
+ assert_in_delta(0.0, method.total_time, 0.05)
818
+ assert_in_delta(0.0, method.wait_time, 0.05)
819
+ assert_in_delta(0.0, method.self_time, 0.05)
820
+ assert_in_delta(0.0, method.children_time, 0.05)
821
+ end
822
+
823
+ def test_class_methods_sleep_threaded
824
+ result = RubyProf.profile do
825
+ background_thread = Thread.new do
826
+ RubyProf::C1.sleep_wait
827
+ end
828
+ background_thread.join
829
+ end
830
+
831
+ assert_equal(2, result.threads.count)
832
+
833
+ thread = result.threads.first
834
+ assert_in_delta(0.0, thread.total_time, 0.05)
835
+
836
+ methods = result.threads.first.methods.sort.reverse
837
+ assert_equal(4, methods.length)
838
+
839
+ # Check times
840
+ method = methods[0]
841
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
842
+ assert_in_delta(0.0, method.total_time, 0.05)
843
+ assert_in_delta(0.0, method.wait_time, 0.05)
844
+ assert_in_delta(0.0, method.self_time, 0.05)
845
+ assert_in_delta(0.0, method.children_time, 0.05)
846
+
847
+ method = methods[1]
848
+ assert_equal('Thread#join', method.full_name)
849
+ assert_in_delta(0.0, method.total_time, 0.05)
850
+ assert_in_delta(0.0, method.wait_time, 0.05)
851
+ assert_in_delta(0.0, method.self_time, 0.05)
852
+ assert_in_delta(0.0, method.children_time, 0.05)
853
+
854
+ method = methods[2]
855
+ assert_equal('<Class::Thread>#new', method.full_name)
856
+ assert_in_delta(0.0, method.total_time, 0.05)
857
+ assert_in_delta(0.0, method.wait_time, 0.05)
858
+ assert_in_delta(0.0, method.self_time, 0.05)
859
+ assert_in_delta(0.0, method.children_time, 0.05)
860
+
861
+ method = methods[3]
862
+ assert_equal('Thread#initialize', method.full_name)
863
+ assert_in_delta(0.0, method.total_time, 0.05)
864
+ assert_in_delta(0.0, method.wait_time, 0.05)
865
+ assert_in_delta(0.0, method.self_time, 0.05)
866
+ assert_in_delta(0.0, method.children_time, 0.05)
867
+
868
+ thread = result.threads.last
869
+ assert_in_delta(0.0, thread.total_time, 0.05)
870
+
871
+ methods = result.threads.first.methods.sort.reverse
872
+ assert_equal(4, methods.length)
873
+
874
+ methods = result.threads.last.methods.sort.reverse
875
+ assert_equal(3, methods.length)
876
+
877
+ # Check times
878
+ method = methods[0]
879
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
880
+ assert_in_delta(0.0, method.total_time, 0.05)
881
+ assert_in_delta(0.0, method.wait_time, 0.05)
882
+ assert_in_delta(0.0, method.self_time, 0.05)
883
+ assert_in_delta(0.0, method.children_time, 0.05)
884
+
885
+ method = methods[1]
886
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
887
+ assert_in_delta(0.0, method.total_time, 0.05)
888
+ assert_in_delta(0.0, method.wait_time, 0.05)
889
+ assert_in_delta(0.0, method.self_time, 0.05)
890
+ assert_in_delta(0.0, method.children_time, 0.05)
891
+
892
+ method = methods[2]
893
+ assert_equal('Kernel#sleep', method.full_name)
894
+ assert_in_delta(0.0, method.total_time, 0.05)
895
+ assert_in_delta(0.0, method.wait_time, 0.05)
896
+ assert_in_delta(0.0, method.self_time, 0.05)
897
+ assert_in_delta(0.0, method.children_time, 0.05)
898
+ end
899
+
900
+ def test_class_methods_busy
901
+ result = RubyProf.profile do
902
+ RubyProf::C1.busy_wait
903
+ end
904
+
905
+ thread = result.threads.first
906
+ assert_in_delta(0.08, thread.total_time, 0.05)
907
+
908
+ methods = result.threads.first.methods.sort.reverse
909
+ assert_equal(5, methods.length)
910
+
911
+ # Check times
912
+ method = methods[0]
913
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
914
+ assert_in_delta(0.1, method.total_time, 0.05)
915
+ assert_in_delta(0.0, method.wait_time, 0.05)
916
+ assert_in_delta(0.0, method.self_time, 0.05)
917
+ assert_in_delta(0.1, method.children_time, 0.05)
918
+
919
+ method = methods[1]
920
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
921
+ assert_in_delta(0.1, method.total_time, 0.05)
922
+ assert_in_delta(0.0, method.wait_time, 0.05)
923
+ assert_in_delta(0.06, method.self_time, 0.05)
924
+ assert_in_delta(0.07, method.children_time, 0.05)
925
+
926
+ method = methods[2]
927
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
928
+ assert_in_delta(0.05, method.total_time, 0.05)
929
+ assert_in_delta(0.0, method.wait_time, 0.05)
930
+ assert_in_delta(0.05, method.self_time, 0.05)
931
+ assert_in_delta(0.0, method.children_time, 0.05)
932
+ end
933
+
934
+ def test_class_methods_busy_threaded
935
+ result = RubyProf.profile do
936
+ background_thread = Thread.new do
937
+ RubyProf::C1.busy_wait
938
+ end
939
+ background_thread.join
940
+ end
941
+
942
+ assert_equal(2, result.threads.count)
943
+
944
+ thread = result.threads.first
945
+ assert_in_delta(0.1, thread.total_time, 0.05)
946
+
947
+ methods = result.threads.first.methods.sort.reverse
948
+ assert_equal(4, methods.length)
949
+
950
+ # Check times
951
+ method = methods[0]
952
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
953
+ assert_in_delta(0.1, method.total_time, 0.05)
954
+ assert_in_delta(0.0, method.wait_time, 0.05)
955
+ assert_in_delta(0.0, method.self_time, 0.05)
956
+ assert_in_delta(0.1, method.children_time, 0.05)
957
+
958
+ method = methods[1]
959
+ assert_equal('Thread#join', method.full_name)
960
+ assert_in_delta(0.1, method.total_time, 0.05)
961
+ assert_in_delta(0.1, method.wait_time, 0.05)
962
+ assert_in_delta(0.0, method.self_time, 0.05)
963
+ assert_in_delta(0.0, method.children_time, 0.05)
964
+
965
+ method = methods[2]
966
+ assert_equal('<Class::Thread>#new', method.full_name)
967
+ assert_in_delta(0.0, method.total_time, 0.05)
968
+ assert_in_delta(0.0, method.wait_time, 0.05)
969
+ assert_in_delta(0.0, method.self_time, 0.05)
970
+ assert_in_delta(0.0, method.children_time, 0.05)
971
+
972
+ method = methods[3]
973
+ assert_equal('Thread#initialize', method.full_name)
974
+ assert_in_delta(0.0, method.total_time, 0.05)
975
+ assert_in_delta(0.0, method.wait_time, 0.05)
976
+ assert_in_delta(0.0, method.self_time, 0.05)
977
+ assert_in_delta(0.0, method.children_time, 0.05)
978
+
979
+ thread = result.threads.last
980
+ assert_in_delta(0.1, thread.total_time, 0.05)
981
+
982
+ methods = result.threads.first.methods.sort.reverse
983
+ assert_equal(4, methods.length)
984
+
985
+ methods = result.threads.last.methods.sort.reverse
986
+ assert_equal(5, methods.length)
987
+
988
+ # Check times
989
+ method = methods[0]
990
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
991
+ assert_in_delta(0.1, method.total_time, 0.05)
992
+ assert_in_delta(0.0, method.wait_time, 0.05)
993
+ assert_in_delta(0.0, method.self_time, 0.05)
994
+ assert_in_delta(0.1, method.children_time, 0.05)
995
+
996
+ method = methods[1]
997
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
998
+ assert_in_delta(0.1, method.total_time, 0.05)
999
+ assert_in_delta(0.0, method.wait_time, 0.05)
1000
+ assert_in_delta(0.05, method.self_time, 0.05)
1001
+ assert_in_delta(0.05, method.children_time, 0.05)
1002
+
1003
+ method = methods[2]
1004
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1005
+ assert_in_delta(0.05, method.total_time, 0.05)
1006
+ assert_in_delta(0.0, method.wait_time, 0.05)
1007
+ assert_in_delta(0.05, method.self_time, 0.05)
1008
+ assert_in_delta(0.0, method.children_time, 0.05)
1009
+ end
1010
+
1011
+ def test_instance_methods_sleep
1012
+ result = RubyProf.profile do
1013
+ RubyProf::C1.new.sleep_wait
1014
+ end
1015
+
1016
+ thread = result.threads.first
1017
+ assert_in_delta(0.0, thread.total_time, 0.05)
1018
+
1019
+ methods = result.threads.first.methods.sort.reverse
1020
+ assert_equal(5, methods.length)
1021
+
1022
+ # Check times
1023
+ method = methods[0]
1024
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
1025
+ assert_in_delta(0.0, method.total_time, 0.05)
1026
+ assert_in_delta(0.0, method.wait_time, 0.05)
1027
+ assert_in_delta(0.0, method.self_time, 0.05)
1028
+ assert_in_delta(0.0, method.children_time, 0.05)
1029
+
1030
+ method = methods[1]
1031
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1032
+ assert_in_delta(0.0, method.total_time, 0.05)
1033
+ assert_in_delta(0.0, method.wait_time, 0.05)
1034
+ assert_in_delta(0.0, method.self_time, 0.05)
1035
+ assert_in_delta(0.0, method.children_time, 0.05)
1036
+
1037
+ method = methods[2]
1038
+ assert_equal('Kernel#sleep', method.full_name)
1039
+ assert_in_delta(0.0, method.total_time, 0.05)
1040
+ assert_in_delta(0.0, method.wait_time, 0.05)
1041
+ assert_in_delta(0.0, method.self_time, 0.05)
1042
+ assert_in_delta(0.0, method.children_time, 0.05)
1043
+
1044
+ method = methods[3]
1045
+ assert_equal('Class#new', method.full_name)
1046
+ assert_in_delta(0.0, method.total_time, 0.05)
1047
+ assert_in_delta(0.0, method.wait_time, 0.05)
1048
+ assert_in_delta(0.0, method.self_time, 0.05)
1049
+ assert_in_delta(0.0, method.children_time, 0.05)
1050
+
1051
+ method = methods[4]
1052
+ assert_equal('BasicObject#initialize', method.full_name)
1053
+ assert_in_delta(0.0, method.total_time, 0.05)
1054
+ assert_in_delta(0.0, method.wait_time, 0.05)
1055
+ assert_in_delta(0.0, method.self_time, 0.05)
1056
+ assert_in_delta(0.0, method.children_time, 0.05)
1057
+ end
1058
+
1059
+ def test_instance_methods_sleep_block
1060
+ result = RubyProf.profile do
1061
+ 1.times { RubyProf::C1.new.sleep_wait }
1062
+ end
1063
+
1064
+ methods = result.threads.first.methods.sort.reverse
1065
+ assert_equal(6, methods.length)
1066
+
1067
+ # Check times
1068
+ method = methods[0]
1069
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
1070
+ assert_in_delta(0.0, method.total_time, 0.05)
1071
+ assert_in_delta(0.0, method.wait_time, 0.05)
1072
+ assert_in_delta(0.0, method.self_time, 0.05)
1073
+ assert_in_delta(0.0, method.children_time, 0.05)
1074
+
1075
+ method = methods[1]
1076
+ assert_equal('Integer#times', method.full_name)
1077
+ assert_in_delta(0.0, method.total_time, 0.05)
1078
+ assert_in_delta(0.0, method.wait_time, 0.05)
1079
+ assert_in_delta(0.0, method.self_time, 0.05)
1080
+ assert_in_delta(0.0, method.children_time, 0.05)
1081
+
1082
+ method = methods[2]
1083
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1084
+ assert_in_delta(0.0, method.total_time, 0.05)
1085
+ assert_in_delta(0.0, method.wait_time, 0.05)
1086
+ assert_in_delta(0.0, method.self_time, 0.05)
1087
+ assert_in_delta(0.0, method.children_time, 0.05)
1088
+
1089
+ method = methods[3]
1090
+ assert_equal('Kernel#sleep', method.full_name)
1091
+ assert_in_delta(0.0, method.total_time, 0.05)
1092
+ assert_in_delta(0.0, method.wait_time, 0.05)
1093
+ assert_in_delta(0.0, method.self_time, 0.05)
1094
+ assert_in_delta(0.0, method.children_time, 0.05)
1095
+
1096
+ method = methods[4]
1097
+ assert_equal('Class#new', method.full_name)
1098
+ assert_in_delta(0.0, method.total_time, 0.05)
1099
+ assert_in_delta(0.0, method.wait_time, 0.05)
1100
+ assert_in_delta(0.0, method.self_time, 0.05)
1101
+ assert_in_delta(0.0, method.children_time, 0.05)
1102
+
1103
+ method = methods[5]
1104
+ assert_equal('BasicObject#initialize', method.full_name)
1105
+ assert_in_delta(0.0, method.total_time, 0.05)
1106
+ assert_in_delta(0.0, method.wait_time, 0.05)
1107
+ assert_in_delta(0.0, method.self_time, 0.05)
1108
+ assert_in_delta(0.0, method.children_time, 0.05)
1109
+ end
1110
+
1111
+ def test_instance_methods_sleep_threaded
1112
+ result = RubyProf.profile do
1113
+ background_thread = Thread.new do
1114
+ RubyProf::C1.new.sleep_wait
1115
+ end
1116
+ background_thread.join
1117
+ end
1118
+
1119
+ assert_equal(2, result.threads.count)
1120
+
1121
+ thread = result.threads.first
1122
+ assert_in_delta(0.0, thread.total_time, 0.05)
1123
+
1124
+ methods = result.threads.first.methods.sort.reverse
1125
+ assert_equal(4, methods.length)
1126
+
1127
+ # Check times
1128
+ method = methods[0]
1129
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1130
+ assert_in_delta(0.0, method.total_time, 0.05)
1131
+ assert_in_delta(0.0, method.wait_time, 0.05)
1132
+ assert_in_delta(0.0, method.self_time, 0.05)
1133
+ assert_in_delta(0.0, method.children_time, 0.05)
1134
+
1135
+ method = methods[1]
1136
+ assert_equal('Thread#join', method.full_name)
1137
+ assert_in_delta(0.0, method.total_time, 0.05)
1138
+ assert_in_delta(0.0, method.wait_time, 0.05)
1139
+ assert_in_delta(0.0, method.self_time, 0.05)
1140
+ assert_in_delta(0.0, method.children_time, 0.05)
1141
+
1142
+ method = methods[2]
1143
+ assert_equal('<Class::Thread>#new', method.full_name)
1144
+ assert_in_delta(0.0, method.total_time, 0.05)
1145
+ assert_in_delta(0.0, method.wait_time, 0.05)
1146
+ assert_in_delta(0.0, method.self_time, 0.05)
1147
+ assert_in_delta(0.0, method.children_time, 0.05)
1148
+
1149
+ method = methods[3]
1150
+ assert_equal('Thread#initialize', method.full_name)
1151
+ assert_in_delta(0.0, method.total_time, 0.05)
1152
+ assert_in_delta(0.0, method.wait_time, 0.05)
1153
+ assert_in_delta(0.0, method.self_time, 0.05)
1154
+ assert_in_delta(0.0, method.children_time, 0.05)
1155
+
1156
+ thread = result.threads.last
1157
+ assert_in_delta(0.0, thread.total_time, 0.05)
1158
+
1159
+ methods = result.threads.first.methods.sort.reverse
1160
+ assert_equal(4, methods.length)
1161
+
1162
+ methods = result.threads.last.methods.sort.reverse
1163
+ assert_equal(5, methods.length)
1164
+
1165
+ # Check times
1166
+ method = methods[0]
1167
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1168
+ assert_in_delta(0.0, method.total_time, 0.05)
1169
+ assert_in_delta(0.0, method.wait_time, 0.05)
1170
+ assert_in_delta(0.0, method.self_time, 0.05)
1171
+ assert_in_delta(0.0, method.children_time, 0.05)
1172
+
1173
+ method = methods[1]
1174
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1175
+ assert_in_delta(0.0, method.total_time, 0.05)
1176
+ assert_in_delta(0.0, method.wait_time, 0.05)
1177
+ assert_in_delta(0.0, method.self_time, 0.05)
1178
+ assert_in_delta(0.0, method.children_time, 0.05)
1179
+
1180
+ method = methods[2]
1181
+ assert_equal('Kernel#sleep', method.full_name)
1182
+ assert_in_delta(0.0, method.total_time, 0.05)
1183
+ assert_in_delta(0.0, method.wait_time, 0.05)
1184
+ assert_in_delta(0.0, method.self_time, 0.05)
1185
+ assert_in_delta(0.0, method.children_time, 0.05)
1186
+
1187
+ method = methods[3]
1188
+ assert_equal('Class#new', method.full_name)
1189
+ assert_in_delta(0.0, method.total_time, 0.05)
1190
+ assert_in_delta(0.0, method.wait_time, 0.05)
1191
+ assert_in_delta(0.0, method.self_time, 0.05)
1192
+ assert_in_delta(0.0, method.children_time, 0.05)
1193
+
1194
+ method = methods[4]
1195
+ assert_equal('BasicObject#initialize', method.full_name)
1196
+ assert_in_delta(0.0, method.total_time, 0.05)
1197
+ assert_in_delta(0.0, method.wait_time, 0.05)
1198
+ assert_in_delta(0.0, method.self_time, 0.05)
1199
+ assert_in_delta(0.0, method.children_time, 0.05)
1200
+ end
1201
+
1202
+ def test_instance_methods_busy
1203
+ result = RubyProf.profile do
1204
+ RubyProf::C1.new.busy_wait
1205
+ end
1206
+
1207
+ thread = result.threads.first
1208
+ assert_in_delta(0.2, thread.total_time, 0.05)
1209
+
1210
+ methods = result.threads.first.methods.sort.reverse
1211
+ assert_equal(7, methods.length)
1212
+
1213
+ # Check times
1214
+ method = methods[0]
1215
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
1216
+ assert_in_delta(0.2, method.total_time, 0.05)
1217
+ assert_in_delta(0.0, method.wait_time, 0.05)
1218
+ assert_in_delta(0.0, method.self_time, 0.05)
1219
+ assert_in_delta(0.2, method.children_time, 0.05)
1220
+
1221
+ method = methods[1]
1222
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
1223
+ assert_in_delta(0.2, method.total_time, 0.05)
1224
+ assert_in_delta(0.0, method.wait_time, 0.05)
1225
+ assert_in_delta(0.09, method.self_time, 0.05)
1226
+ assert_in_delta(0.11, method.children_time, 0.05)
1227
+
1228
+ method = methods[2]
1229
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1230
+ assert_in_delta(0.033, method.total_time, 0.05)
1231
+ assert_in_delta(0.0, method.wait_time, 0.05)
1232
+ assert_in_delta(0.033, method.self_time, 0.05)
1233
+ assert_in_delta(0.0, method.children_time, 0.05)
1234
+
1235
+ method = methods[3]
1236
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1237
+ assert_in_delta(0.0, method.total_time, 0.05)
1238
+ assert_in_delta(0.0, method.wait_time, 0.05)
1239
+ assert_in_delta(0.0, method.self_time, 0.05)
1240
+ assert_in_delta(0.0, method.children_time, 0.05)
1241
+
1242
+ method = methods[4]
1243
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1244
+ assert_in_delta(0.0, method.total_time, 0.05)
1245
+ assert_in_delta(0.0, method.wait_time, 0.05)
1246
+ assert_in_delta(0.0, method.self_time, 0.05)
1247
+ assert_in_delta(0.0, method.children_time, 0.05)
1248
+
1249
+ method = methods[5]
1250
+ assert_equal('Class#new', method.full_name)
1251
+ assert_in_delta(0.0, method.total_time, 0.05)
1252
+ assert_in_delta(0.0, method.wait_time, 0.05)
1253
+ assert_in_delta(0.0, method.self_time, 0.05)
1254
+ assert_in_delta(0.0, method.children_time, 0.05)
1255
+
1256
+ method = methods[6]
1257
+ assert_equal('BasicObject#initialize', method.full_name)
1258
+ assert_in_delta(0.0, method.total_time, 0.05)
1259
+ assert_in_delta(0.0, method.wait_time, 0.05)
1260
+ assert_in_delta(0.0, method.self_time, 0.05)
1261
+ assert_in_delta(0.0, method.children_time, 0.05)
1262
+ end
1263
+
1264
+ def test_instance_methods_busy_block
1265
+ result = RubyProf.profile do
1266
+ 1.times { RubyProf::C1.new.busy_wait }
1267
+ end
1268
+
1269
+ methods = result.threads.first.methods.sort.reverse
1270
+ assert_equal(8, methods.length)
1271
+
1272
+ # Check times
1273
+ method = methods[0]
1274
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
1275
+ assert_in_delta(0.2, method.total_time, 0.05)
1276
+ assert_in_delta(0.0, method.wait_time, 0.05)
1277
+ assert_in_delta(0.0, method.self_time, 0.05)
1278
+ assert_in_delta(0.2, method.children_time, 0.05)
1279
+
1280
+ method = methods[1]
1281
+ assert_equal('Integer#times', method.full_name)
1282
+ assert_in_delta(0.2, method.total_time, 0.05)
1283
+ assert_in_delta(0.0, method.wait_time, 0.05)
1284
+ assert_in_delta(0.0, method.self_time, 0.05)
1285
+ assert_in_delta(0.2, method.children_time, 0.05)
1286
+
1287
+ method = methods[2]
1288
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
1289
+ assert_in_delta(0.2, method.total_time, 0.05)
1290
+ assert_in_delta(0.0, method.wait_time, 0.05)
1291
+ assert_in_delta(0.09, method.self_time, 0.05)
1292
+ assert_in_delta(0.11, method.children_time, 0.05)
1293
+
1294
+ method = methods[3]
1295
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1296
+ assert_in_delta(0.033, method.total_time, 0.05)
1297
+ assert_in_delta(0.0, method.wait_time, 0.05)
1298
+ assert_in_delta(0.033, method.self_time, 0.05)
1299
+ assert_in_delta(0.0, method.children_time, 0.05)
1300
+
1301
+ method = methods[4]
1302
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1303
+ assert_in_delta(0.03, method.total_time, 0.03)
1304
+ assert_in_delta(0.03, method.wait_time, 0.03)
1305
+ assert_in_delta(0.03, method.self_time, 0.03)
1306
+ assert_in_delta(0.03, method.children_time, 0.03)
1307
+
1308
+ method = methods[5]
1309
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1310
+ assert_in_delta(0.03, method.total_time, 0.03)
1311
+ assert_in_delta(0.03, method.wait_time, 0.03)
1312
+ assert_in_delta(0.03, method.self_time, 0.03)
1313
+ assert_in_delta(0.03, method.children_time, 0.03)
1314
+
1315
+ method = methods[6]
1316
+ assert_equal('Class#new', method.full_name)
1317
+ assert_in_delta(0.0, method.total_time, 0.01)
1318
+ assert_in_delta(0.0, method.wait_time, 0.01)
1319
+ assert_in_delta(0.0, method.self_time, 0.01)
1320
+ assert_in_delta(0.0, method.children_time, 0.01)
1321
+
1322
+ method = methods[7]
1323
+ assert_equal('BasicObject#initialize', method.full_name)
1324
+ assert_in_delta(0.0, method.total_time, 0.05)
1325
+ assert_in_delta(0.0, method.wait_time, 0.05)
1326
+ assert_in_delta(0.0, method.self_time, 0.05)
1327
+ assert_in_delta(0.0, method.children_time, 0.05)
1328
+ end
1329
+
1330
+ def test_instance_methods_busy_threaded
1331
+ result = RubyProf.profile do
1332
+ background_thread = Thread.new do
1333
+ RubyProf::C1.new.busy_wait
1334
+ end
1335
+ background_thread.join
1336
+ end
1337
+
1338
+ assert_equal(2, result.threads.count)
1339
+
1340
+ thread = result.threads.first
1341
+ assert_in_delta(0.2, thread.total_time, 0.05)
1342
+
1343
+ methods = result.threads.first.methods.sort.reverse
1344
+ assert_equal(4, methods.length)
1345
+
1346
+ # Check times
1347
+ method = methods[0]
1348
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
1349
+ assert_in_delta(0.2, method.total_time, 0.05)
1350
+ assert_in_delta(0.0, method.wait_time, 0.05)
1351
+ assert_in_delta(0.0, method.self_time, 0.05)
1352
+ assert_in_delta(0.2, method.children_time, 0.05)
1353
+
1354
+ method = methods[1]
1355
+ assert_equal('Thread#join', method.full_name)
1356
+ assert_in_delta(0.2, method.total_time, 0.05)
1357
+ assert_in_delta(0.2, method.wait_time, 0.05)
1358
+ assert_in_delta(0.0, method.self_time, 0.05)
1359
+ assert_in_delta(0.0, method.children_time, 0.05)
1360
+
1361
+ method = methods[2]
1362
+ assert_equal('<Class::Thread>#new', method.full_name)
1363
+ assert_in_delta(0.0, method.total_time, 0.05)
1364
+ assert_in_delta(0.0, method.wait_time, 0.05)
1365
+ assert_in_delta(0.0, method.self_time, 0.05)
1366
+ assert_in_delta(0.0, method.children_time, 0.05)
1367
+
1368
+ method = methods[3]
1369
+ assert_equal('Thread#initialize', method.full_name)
1370
+ assert_in_delta(0.0, method.total_time, 0.05)
1371
+ assert_in_delta(0.0, method.wait_time, 0.05)
1372
+ assert_in_delta(0.0, method.self_time, 0.05)
1373
+ assert_in_delta(0.0, method.children_time, 0.05)
1374
+
1375
+ thread = result.threads.last
1376
+ assert_in_delta(0.2, thread.total_time, 0.05)
1377
+
1378
+ methods = result.threads.first.methods.sort.reverse
1379
+ assert_equal(4, methods.length)
1380
+
1381
+ methods = result.threads.last.methods.sort.reverse
1382
+ assert_equal(7, methods.length)
1383
+
1384
+ # Check times
1385
+ method = methods[0]
1386
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
1387
+ assert_in_delta(0.2, method.total_time, 0.05)
1388
+ assert_in_delta(0.0, method.wait_time, 0.05)
1389
+ assert_in_delta(0.0, method.self_time, 0.05)
1390
+ assert_in_delta(0.2, method.children_time, 0.05)
1391
+
1392
+ method = methods[1]
1393
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
1394
+ assert_in_delta(0.2, method.total_time, 0.05)
1395
+ assert_in_delta(0.0, method.wait_time, 0.05)
1396
+ assert_in_delta(0.1, method.self_time, 0.05)
1397
+ assert_in_delta(0.1, method.children_time, 0.05)
1398
+
1399
+ method = methods[2]
1400
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1401
+ assert_in_delta(0.03, method.total_time, 0.05)
1402
+ assert_in_delta(0.0, method.wait_time, 0.05)
1403
+ assert_in_delta(0.03, method.self_time, 0.05)
1404
+ assert_in_delta(0.0, method.children_time, 0.05)
1405
+
1406
+ method = methods[3]
1407
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1408
+ assert_in_delta(0.0, method.total_time, 0.05)
1409
+ assert_in_delta(0.0, method.wait_time, 0.05)
1410
+ assert_in_delta(0.0, method.self_time, 0.05)
1411
+ assert_in_delta(0.0, method.children_time, 0.05)
1412
+
1413
+ method = methods[4]
1414
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1415
+ assert_in_delta(0.0, method.total_time, 0.05)
1416
+ assert_in_delta(0.0, method.wait_time, 0.05)
1417
+ assert_in_delta(0.0, method.self_time, 0.05)
1418
+ assert_in_delta(0.0, method.children_time, 0.05)
1419
+
1420
+ method = methods[5]
1421
+ assert_equal('Class#new', method.full_name)
1422
+ assert_in_delta(0.0, method.total_time, 0.05)
1423
+ assert_in_delta(0.0, method.wait_time, 0.05)
1424
+ assert_in_delta(0.0, method.self_time, 0.05)
1425
+ assert_in_delta(0.0, method.children_time, 0.05)
1426
+
1427
+ method = methods[6]
1428
+ assert_equal('BasicObject#initialize', method.full_name)
1429
+ assert_in_delta(0.0, method.total_time, 0.05)
1430
+ assert_in_delta(0.0, method.wait_time, 0.05)
1431
+ assert_in_delta(0.0, method.self_time, 0.05)
1432
+ assert_in_delta(0.0, method.children_time, 0.05)
1433
+ end
1434
+
1435
+ def test_module_methods_sleep
1436
+ result = RubyProf.profile do
1437
+ RubyProf::C2.sleep_wait
1438
+ end
1439
+
1440
+ thread = result.threads.first
1441
+ assert_in_delta(0.0, thread.total_time, 0.05)
1442
+
1443
+ methods = result.threads.first.methods.sort.reverse
1444
+ assert_equal(3, methods.length)
1445
+
1446
+ # Check times
1447
+ method = methods[0]
1448
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
1449
+ assert_in_delta(0.0, method.total_time, 0.05)
1450
+ assert_in_delta(0.0, method.wait_time, 0.05)
1451
+ assert_in_delta(0.0, method.self_time, 0.05)
1452
+ assert_in_delta(0.0, method.children_time, 0.05)
1453
+
1454
+ method = methods[1]
1455
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
1456
+ assert_in_delta(0.0, method.total_time, 0.05)
1457
+ assert_in_delta(0.0, method.wait_time, 0.05)
1458
+ assert_in_delta(0.0, method.self_time, 0.05)
1459
+ assert_in_delta(0.0, method.children_time, 0.05)
1460
+
1461
+ method = methods[2]
1462
+ assert_equal('Kernel#sleep', method.full_name)
1463
+ assert_in_delta(0.0, method.total_time, 0.05)
1464
+ assert_in_delta(0.0, method.wait_time, 0.05)
1465
+ assert_in_delta(0.0, method.self_time, 0.05)
1466
+ assert_in_delta(0.0, method.children_time, 0.05)
1467
+ end
1468
+
1469
+ def test_module_methods_busy
1470
+ result = RubyProf.profile do
1471
+ RubyProf::C2.busy_wait
1472
+ end
1473
+
1474
+ thread = result.threads.first
1475
+ assert_in_delta(0.3, thread.total_time, 0.05)
1476
+
1477
+ methods = result.threads.first.methods.sort.reverse
1478
+ assert_equal(5, methods.length)
1479
+
1480
+ # Check times
1481
+ method = methods[0]
1482
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
1483
+ assert_in_delta(0.3, method.total_time, 0.05)
1484
+ assert_in_delta(0.0, method.wait_time, 0.05)
1485
+ assert_in_delta(0.0, method.self_time, 0.05)
1486
+ assert_in_delta(0.3, method.children_time, 0.05)
1487
+
1488
+ method = methods[1]
1489
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
1490
+ assert_in_delta(0.3, method.total_time, 0.05)
1491
+ assert_in_delta(0.0, method.wait_time, 0.05)
1492
+ assert_in_delta(0.15, method.self_time, 0.05)
1493
+ assert_in_delta(0.15, method.children_time, 0.05)
1494
+
1495
+ method = methods[2]
1496
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1497
+ assert_in_delta(0.05, method.total_time, 0.05)
1498
+ assert_in_delta(0.0, method.wait_time, 0.05)
1499
+ assert_in_delta(0.05, method.self_time, 0.05)
1500
+ assert_in_delta(0.0, method.children_time, 0.05)
1501
+ end
1502
+
1503
+ def test_module_instance_methods_sleep
1504
+ result = RubyProf.profile do
1505
+ RubyProf::C2.new.sleep_wait
1506
+ end
1507
+
1508
+ thread = result.threads.first
1509
+ assert_in_delta(0.0, thread.total_time, 0.05)
1510
+
1511
+ methods = result.threads.first.methods.sort.reverse
1512
+ assert_equal(5, methods.length)
1513
+
1514
+ # Check times
1515
+ method = methods[0]
1516
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
1517
+ assert_in_delta(0.0, method.total_time, 0.05)
1518
+ assert_in_delta(0.0, method.wait_time, 0.05)
1519
+ assert_in_delta(0.0, method.self_time, 0.05)
1520
+ assert_in_delta(0.0, method.children_time, 0.05)
1521
+
1522
+ method = methods[1]
1523
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
1524
+ assert_in_delta(0.0, method.total_time, 0.05)
1525
+ assert_in_delta(0.0, method.wait_time, 0.05)
1526
+ assert_in_delta(0.0, method.self_time, 0.05)
1527
+ assert_in_delta(0.0, method.children_time, 0.05)
1528
+
1529
+ method = methods[2]
1530
+ assert_equal('Kernel#sleep', method.full_name)
1531
+ assert_in_delta(0.0, method.total_time, 0.05)
1532
+ assert_in_delta(0.0, method.wait_time, 0.05)
1533
+ assert_in_delta(0.0, method.self_time, 0.05)
1534
+ assert_in_delta(0.0, method.children_time, 0.05)
1535
+
1536
+ method = methods[3]
1537
+ assert_equal('Class#new', method.full_name)
1538
+ assert_in_delta(0.0, method.total_time, 0.05)
1539
+ assert_in_delta(0.0, method.wait_time, 0.05)
1540
+ assert_in_delta(0.0, method.self_time, 0.05)
1541
+ assert_in_delta(0.0, method.children_time, 0.05)
1542
+
1543
+ method = methods[4]
1544
+ assert_equal('BasicObject#initialize', method.full_name)
1545
+ assert_in_delta(0.0, method.total_time, 0.05)
1546
+ assert_in_delta(0.0, method.wait_time, 0.05)
1547
+ assert_in_delta(0.0, method.self_time, 0.05)
1548
+ assert_in_delta(0.0, method.children_time, 0.05)
1549
+ end
1550
+
1551
+ def test_module_instance_methods_busy
1552
+ result = RubyProf.profile do
1553
+ RubyProf::C2.new.busy_wait
1554
+ end
1555
+
1556
+ thread = result.threads.first
1557
+ assert_in_delta(0.3, thread.total_time, 0.05)
1558
+
1559
+ methods = result.threads.first.methods.sort.reverse
1560
+ assert_equal(7, methods.length)
1561
+
1562
+ # Check times
1563
+ method = methods[0]
1564
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
1565
+ assert_in_delta(0.3, method.total_time, 0.05)
1566
+ assert_in_delta(0.0, method.wait_time, 0.05)
1567
+ assert_in_delta(0.0, method.self_time, 0.05)
1568
+ assert_in_delta(0.3, method.children_time, 0.05)
1569
+
1570
+ method = methods[1]
1571
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
1572
+ assert_in_delta(0.3, method.total_time, 0.05)
1573
+ assert_in_delta(0.0, method.wait_time, 0.05)
1574
+ assert_in_delta(0.15, method.self_time, 0.05)
1575
+ assert_in_delta(0.15, method.children_time, 0.05)
1576
+
1577
+ method = methods[2]
1578
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1579
+ assert_in_delta(0.05, method.total_time, 0.05)
1580
+ assert_in_delta(0.0, method.wait_time, 0.05)
1581
+ assert_in_delta(0.05, method.self_time, 0.05)
1582
+ assert_in_delta(0.0, method.children_time, 0.05)
1583
+
1584
+ method = methods[3]
1585
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1586
+ assert_in_delta(0.0, method.total_time, 0.05)
1587
+ assert_in_delta(0.0, method.wait_time, 0.05)
1588
+ assert_in_delta(0.0, method.self_time, 0.05)
1589
+ assert_in_delta(0.0, method.children_time, 0.05)
1590
+
1591
+ method = methods[4]
1592
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1593
+ assert_in_delta(0.0, method.total_time, 0.05)
1594
+ assert_in_delta(0.0, method.wait_time, 0.05)
1595
+ assert_in_delta(0.0, method.self_time, 0.05)
1596
+ assert_in_delta(0.0, method.children_time, 0.05)
1597
+
1598
+ method = methods[5]
1599
+ assert_equal('Class#new', method.full_name)
1600
+ assert_in_delta(0.0, method.total_time, 0.05)
1601
+ assert_in_delta(0.0, method.wait_time, 0.05)
1602
+ assert_in_delta(0.0, method.self_time, 0.05)
1603
+ assert_in_delta(0.0, method.children_time, 0.05)
1604
+
1605
+ method = methods[6]
1606
+ assert_equal('BasicObject#initialize', method.full_name)
1607
+ assert_in_delta(0.0, method.total_time, 0.05)
1608
+ assert_in_delta(0.0, method.wait_time, 0.05)
1609
+ assert_in_delta(0.0, method.self_time, 0.05)
1610
+ assert_in_delta(0.0, method.children_time, 0.05)
1611
+ end
1612
+ end
1613
+ end
1614
+ end