ruby-prof 1.6.3 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +19 -0
  3. data/ext/ruby_prof/extconf.rb +23 -22
  4. data/ext/ruby_prof/rp_allocation.c +342 -342
  5. data/ext/ruby_prof/rp_call_tree.c +1 -1
  6. data/ext/ruby_prof/rp_call_tree.h +1 -1
  7. data/ext/ruby_prof/rp_call_trees.c +296 -296
  8. data/ext/ruby_prof/rp_call_trees.h +28 -28
  9. data/ext/ruby_prof/rp_measure_allocations.c +47 -47
  10. data/ext/ruby_prof/rp_measure_memory.c +46 -46
  11. data/ext/ruby_prof/rp_measure_process_time.c +64 -66
  12. data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
  13. data/ext/ruby_prof/rp_measurement.c +364 -364
  14. data/ext/ruby_prof/rp_method.c +551 -550
  15. data/ext/ruby_prof/rp_method.h +5 -2
  16. data/ext/ruby_prof/rp_profile.c +2 -2
  17. data/ext/ruby_prof/rp_profile.h +36 -36
  18. data/ext/ruby_prof/rp_stack.c +212 -212
  19. data/ext/ruby_prof/rp_thread.c +1 -1
  20. data/ext/ruby_prof/ruby_prof.c +50 -50
  21. data/ext/ruby_prof/ruby_prof.h +35 -34
  22. data/ext/ruby_prof/vc/ruby_prof.vcxproj +5 -7
  23. data/lib/ruby-prof/compatibility.rb +113 -113
  24. data/lib/ruby-prof/exclude_common_methods.rb +204 -198
  25. data/lib/ruby-prof/method_info.rb +87 -85
  26. data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
  27. data/lib/ruby-prof/version.rb +3 -3
  28. data/ruby-prof.gemspec +66 -64
  29. data/test/dynamic_method_test.rb +9 -21
  30. data/test/enumerable_test.rb +23 -21
  31. data/test/exclude_methods_test.rb +363 -146
  32. data/test/fiber_test.rb +195 -195
  33. data/test/gc_test.rb +104 -102
  34. data/test/line_number_test.rb +426 -134
  35. data/test/measure_allocations_test.rb +1172 -660
  36. data/test/measure_memory_test.rb +1193 -1024
  37. data/test/measure_process_time_test.rb +3330 -1610
  38. data/test/measure_wall_time_test.rb +634 -420
  39. data/test/merge_test.rb +146 -146
  40. data/test/method_info_test.rb +100 -95
  41. data/test/printers_test.rb +178 -135
  42. data/test/recursive_test.rb +796 -425
  43. data/test/start_stop_test.rb +4 -4
  44. data/test/test_helper.rb +20 -20
  45. data/test/thread_test.rb +229 -235
  46. data/test/unique_call_path_test.rb +9 -22
  47. data/test/yarv_test.rb +1 -5
  48. metadata +33 -8
@@ -1,1610 +1,3330 @@
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
- super
10
- GC.start
11
- end
12
-
13
- # These tests run to fast for Windows to detect any used process time
14
- if !windows?
15
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
16
- def test_class_methods_sleep
17
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
18
- RubyProf::C1.sleep_wait
19
- end
20
-
21
- thread = result.threads.first
22
- assert_in_delta(0.0, thread.total_time, 0.05)
23
-
24
- methods = result.threads.first.methods.sort.reverse
25
- assert_equal(3, methods.length)
26
-
27
- # Check times
28
- method = methods[0]
29
- assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
30
- assert_in_delta(0.0, method.total_time, 0.05)
31
- assert_in_delta(0.0, method.wait_time, 0.05)
32
- assert_in_delta(0.0, method.self_time, 0.05)
33
- assert_in_delta(0.0, method.children_time, 0.05)
34
-
35
- method = methods[1]
36
- assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
37
- assert_in_delta(0.0, method.total_time, 0.05)
38
- assert_in_delta(0.0, method.wait_time, 0.05)
39
- assert_in_delta(0.0, method.self_time, 0.05)
40
- assert_in_delta(0.0, method.children_time, 0.05)
41
-
42
- method = methods[2]
43
- assert_equal('Kernel#sleep', method.full_name)
44
- assert_in_delta(0.0, method.total_time, 0.05)
45
- assert_in_delta(0.0, method.wait_time, 0.05)
46
- assert_in_delta(0.0, method.self_time, 0.05)
47
- assert_in_delta(0.0, method.children_time, 0.05)
48
- end
49
-
50
- def test_class_methods_sleep_threaded
51
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
52
- background_thread = Thread.new do
53
- RubyProf::C1.sleep_wait
54
- end
55
- background_thread.join
56
- end
57
-
58
- assert_equal(2, result.threads.count)
59
-
60
- thread = result.threads.first
61
- assert_in_delta(0.0, thread.total_time, 0.05)
62
-
63
- methods = result.threads.first.methods.sort.reverse
64
- assert_equal(4, methods.length)
65
-
66
- # Check times
67
- method = methods[0]
68
- assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
69
- assert_in_delta(0.0, method.total_time, 0.05)
70
- assert_in_delta(0.0, method.wait_time, 0.05)
71
- assert_in_delta(0.0, method.self_time, 0.05)
72
- assert_in_delta(0.0, method.children_time, 0.05)
73
-
74
- method = methods[1]
75
- assert_equal('Thread#join', method.full_name)
76
- assert_in_delta(0.0, method.total_time, 0.05)
77
- assert_in_delta(0.0, method.wait_time, 0.05)
78
- assert_in_delta(0.0, method.self_time, 0.05)
79
- assert_in_delta(0.0, method.children_time, 0.05)
80
-
81
- method = methods[2]
82
- assert_equal('<Class::Thread>#new', method.full_name)
83
- assert_in_delta(0.0, method.total_time, 0.05)
84
- assert_in_delta(0.0, method.wait_time, 0.05)
85
- assert_in_delta(0.0, method.self_time, 0.05)
86
- assert_in_delta(0.0, method.children_time, 0.05)
87
-
88
- method = methods[3]
89
- assert_equal('Thread#initialize', method.full_name)
90
- assert_in_delta(0.0, method.total_time, 0.05)
91
- assert_in_delta(0.0, method.wait_time, 0.05)
92
- assert_in_delta(0.0, method.self_time, 0.05)
93
- assert_in_delta(0.0, method.children_time, 0.05)
94
-
95
- thread = result.threads.last
96
- assert_in_delta(0.0, thread.total_time, 0.05)
97
-
98
- methods = result.threads.first.methods.sort.reverse
99
- assert_equal(4, methods.length)
100
-
101
- methods = result.threads.last.methods.sort.reverse
102
- assert_equal(3, methods.length)
103
-
104
- # Check times
105
- method = methods[0]
106
- assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
107
- assert_in_delta(0.0, method.total_time, 0.05)
108
- assert_in_delta(0.0, method.wait_time, 0.05)
109
- assert_in_delta(0.0, method.self_time, 0.05)
110
- assert_in_delta(0.0, method.children_time, 0.05)
111
-
112
- method = methods[1]
113
- assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
114
- assert_in_delta(0.0, method.total_time, 0.05)
115
- assert_in_delta(0.0, method.wait_time, 0.05)
116
- assert_in_delta(0.0, method.self_time, 0.05)
117
- assert_in_delta(0.0, method.children_time, 0.05)
118
-
119
- method = methods[2]
120
- assert_equal('Kernel#sleep', 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
- end
126
-
127
- def test_class_methods_busy
128
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
129
- RubyProf::C1.busy_wait
130
- end
131
-
132
- thread = result.threads.first
133
- assert_in_delta(0.08, thread.total_time, 0.05)
134
-
135
- methods = result.threads.first.methods.sort.reverse
136
- assert_equal(3, methods.length)
137
-
138
- # Check times
139
- method = methods[0]
140
- assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
141
- assert_in_delta(0.1, method.total_time, 0.05)
142
- assert_in_delta(0.0, method.wait_time, 0.05)
143
- assert_in_delta(0.0, method.self_time, 0.05)
144
- assert_in_delta(0.1, method.children_time, 0.05)
145
-
146
- method = methods[1]
147
- assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
148
- assert_in_delta(0.1, method.total_time, 0.05)
149
- assert_in_delta(0.0, method.wait_time, 0.05)
150
- assert_in_delta(0.06, method.self_time, 0.05)
151
- assert_in_delta(0.07, method.children_time, 0.05)
152
-
153
- method = methods[2]
154
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
155
- assert_in_delta(0.05, method.total_time, 0.05)
156
- assert_in_delta(0.0, method.wait_time, 0.05)
157
- assert_in_delta(0.05, method.self_time, 0.05)
158
- assert_in_delta(0.0, method.children_time, 0.05)
159
- end
160
-
161
- def test_class_methods_busy_threaded
162
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
163
- background_thread = Thread.new do
164
- RubyProf::C1.busy_wait
165
- end
166
- background_thread.join
167
- end
168
-
169
- assert_equal(2, result.threads.count)
170
-
171
- thread = result.threads.first
172
- assert_in_delta(0.1, thread.total_time, 0.05)
173
-
174
- methods = result.threads.first.methods.sort.reverse
175
- assert_equal(4, methods.length)
176
-
177
- # Check times
178
- method = methods[0]
179
- assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
180
- assert_in_delta(0.1, method.total_time, 0.05)
181
- assert_in_delta(0.0, method.wait_time, 0.05)
182
- assert_in_delta(0.0, method.self_time, 0.05)
183
- assert_in_delta(0.1, method.children_time, 0.05)
184
-
185
- method = methods[1]
186
- assert_equal('Thread#join', method.full_name)
187
- assert_in_delta(0.1, method.total_time, 0.05)
188
- assert_in_delta(0.1, method.wait_time, 0.05)
189
- assert_in_delta(0.0, method.self_time, 0.05)
190
- assert_in_delta(0.0, method.children_time, 0.05)
191
-
192
- method = methods[2]
193
- assert_equal('<Class::Thread>#new', method.full_name)
194
- assert_in_delta(0.0, method.total_time, 0.05)
195
- assert_in_delta(0.0, method.wait_time, 0.05)
196
- assert_in_delta(0.0, method.self_time, 0.05)
197
- assert_in_delta(0.0, method.children_time, 0.05)
198
-
199
- method = methods[3]
200
- assert_equal('Thread#initialize', method.full_name)
201
- assert_in_delta(0.0, method.total_time, 0.05)
202
- assert_in_delta(0.0, method.wait_time, 0.05)
203
- assert_in_delta(0.0, method.self_time, 0.05)
204
- assert_in_delta(0.0, method.children_time, 0.05)
205
-
206
- thread = result.threads.last
207
- assert_in_delta(0.1, thread.total_time, 0.05)
208
-
209
- methods = result.threads.first.methods.sort.reverse
210
- assert_equal(4, methods.length)
211
-
212
- methods = result.threads.last.methods.sort.reverse
213
- assert_equal(3, methods.length)
214
-
215
- # Check times
216
- method = methods[0]
217
- assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
218
- assert_in_delta(0.1, method.total_time, 0.05)
219
- assert_in_delta(0.0, method.wait_time, 0.05)
220
- assert_in_delta(0.0, method.self_time, 0.05)
221
- assert_in_delta(0.1, method.children_time, 0.05)
222
-
223
- method = methods[1]
224
- assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
225
- assert_in_delta(0.1, method.total_time, 0.05)
226
- assert_in_delta(0.0, method.wait_time, 0.05)
227
- assert_in_delta(0.05, method.self_time, 0.05)
228
- assert_in_delta(0.05, method.children_time, 0.05)
229
-
230
- method = methods[2]
231
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
232
- assert_in_delta(0.05, method.total_time, 0.05)
233
- assert_in_delta(0.0, method.wait_time, 0.05)
234
- assert_in_delta(0.05, method.self_time, 0.05)
235
- assert_in_delta(0.0, method.children_time, 0.05)
236
- end
237
-
238
- def test_instance_methods_sleep
239
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
240
- RubyProf::C1.new.sleep_wait
241
- end
242
-
243
- thread = result.threads.first
244
- assert_in_delta(0.0, thread.total_time, 0.05)
245
-
246
- methods = result.threads.first.methods.sort.reverse
247
- assert_equal(5, methods.length)
248
-
249
- # Check times
250
- method = methods[0]
251
- assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
252
- assert_in_delta(0.0, method.total_time, 0.05)
253
- assert_in_delta(0.0, method.wait_time, 0.05)
254
- assert_in_delta(0.0, method.self_time, 0.05)
255
- assert_in_delta(0.0, method.children_time, 0.05)
256
-
257
- method = methods[1]
258
- assert_equal('RubyProf::C1#sleep_wait', method.full_name)
259
- assert_in_delta(0.0, method.total_time, 0.05)
260
- assert_in_delta(0.0, method.wait_time, 0.05)
261
- assert_in_delta(0.0, method.self_time, 0.05)
262
- assert_in_delta(0.0, method.children_time, 0.05)
263
-
264
- method = methods[2]
265
- assert_equal('Kernel#sleep', method.full_name)
266
- assert_in_delta(0.0, method.total_time, 0.05)
267
- assert_in_delta(0.0, method.wait_time, 0.05)
268
- assert_in_delta(0.0, method.self_time, 0.05)
269
- assert_in_delta(0.0, method.children_time, 0.05)
270
-
271
- method = methods[3]
272
- assert_equal('Class#new', method.full_name)
273
- assert_in_delta(0.0, method.total_time, 0.05)
274
- assert_in_delta(0.0, method.wait_time, 0.05)
275
- assert_in_delta(0.0, method.self_time, 0.05)
276
- assert_in_delta(0.0, method.children_time, 0.05)
277
-
278
- method = methods[4]
279
- assert_equal('BasicObject#initialize', method.full_name)
280
- assert_in_delta(0.0, method.total_time, 0.05)
281
- assert_in_delta(0.0, method.wait_time, 0.05)
282
- assert_in_delta(0.0, method.self_time, 0.05)
283
- assert_in_delta(0.0, method.children_time, 0.05)
284
- end
285
-
286
- def test_instance_methods_sleep_block
287
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
288
- 1.times { RubyProf::C1.new.sleep_wait }
289
- end
290
-
291
- methods = result.threads.first.methods.sort.reverse
292
- assert_equal(6, methods.length)
293
-
294
- # Check times
295
- method = methods[0]
296
- assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
297
- assert_in_delta(0.0, method.total_time, 0.05)
298
- assert_in_delta(0.0, method.wait_time, 0.05)
299
- assert_in_delta(0.0, method.self_time, 0.05)
300
- assert_in_delta(0.0, method.children_time, 0.05)
301
-
302
- method = methods[1]
303
- assert_equal('Integer#times', method.full_name)
304
- assert_in_delta(0.0, method.total_time, 0.05)
305
- assert_in_delta(0.0, method.wait_time, 0.05)
306
- assert_in_delta(0.0, method.self_time, 0.05)
307
- assert_in_delta(0.0, method.children_time, 0.05)
308
-
309
- method = methods[2]
310
- assert_equal('RubyProf::C1#sleep_wait', method.full_name)
311
- assert_in_delta(0.0, method.total_time, 0.05)
312
- assert_in_delta(0.0, method.wait_time, 0.05)
313
- assert_in_delta(0.0, method.self_time, 0.05)
314
- assert_in_delta(0.0, method.children_time, 0.05)
315
-
316
- method = methods[3]
317
- assert_equal('Kernel#sleep', method.full_name)
318
- assert_in_delta(0.0, method.total_time, 0.05)
319
- assert_in_delta(0.0, method.wait_time, 0.05)
320
- assert_in_delta(0.0, method.self_time, 0.05)
321
- assert_in_delta(0.0, method.children_time, 0.05)
322
-
323
- method = methods[4]
324
- assert_equal('Class#new', method.full_name)
325
- assert_in_delta(0.0, method.total_time, 0.05)
326
- assert_in_delta(0.0, method.wait_time, 0.05)
327
- assert_in_delta(0.0, method.self_time, 0.05)
328
- assert_in_delta(0.0, method.children_time, 0.05)
329
-
330
- method = methods[5]
331
- assert_equal('BasicObject#initialize', method.full_name)
332
- assert_in_delta(0.0, method.total_time, 0.05)
333
- assert_in_delta(0.0, method.wait_time, 0.05)
334
- assert_in_delta(0.0, method.self_time, 0.05)
335
- assert_in_delta(0.0, method.children_time, 0.05)
336
- end
337
-
338
- def test_instance_methods_sleep_threaded
339
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
340
- background_thread = Thread.new do
341
- RubyProf::C1.new.sleep_wait
342
- end
343
- background_thread.join
344
- end
345
-
346
- assert_equal(2, result.threads.count)
347
-
348
- thread = result.threads.first
349
- assert_in_delta(0.0, thread.total_time, 0.05)
350
-
351
- methods = result.threads.first.methods.sort.reverse
352
- assert_equal(4, methods.length)
353
-
354
- # Check times
355
- method = methods[0]
356
- assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
357
- assert_in_delta(0.0, method.total_time, 0.05)
358
- assert_in_delta(0.0, method.wait_time, 0.05)
359
- assert_in_delta(0.0, method.self_time, 0.05)
360
- assert_in_delta(0.0, method.children_time, 0.05)
361
-
362
- method = methods[1]
363
- assert_equal('Thread#join', method.full_name)
364
- assert_in_delta(0.0, method.total_time, 0.05)
365
- assert_in_delta(0.0, method.wait_time, 0.05)
366
- assert_in_delta(0.0, method.self_time, 0.05)
367
- assert_in_delta(0.0, method.children_time, 0.05)
368
-
369
- method = methods[2]
370
- assert_equal('<Class::Thread>#new', method.full_name)
371
- assert_in_delta(0.0, method.total_time, 0.05)
372
- assert_in_delta(0.0, method.wait_time, 0.05)
373
- assert_in_delta(0.0, method.self_time, 0.05)
374
- assert_in_delta(0.0, method.children_time, 0.05)
375
-
376
- method = methods[3]
377
- assert_equal('Thread#initialize', method.full_name)
378
- assert_in_delta(0.0, method.total_time, 0.05)
379
- assert_in_delta(0.0, method.wait_time, 0.05)
380
- assert_in_delta(0.0, method.self_time, 0.05)
381
- assert_in_delta(0.0, method.children_time, 0.05)
382
-
383
- thread = result.threads.last
384
- assert_in_delta(0.0, thread.total_time, 0.05)
385
-
386
- methods = result.threads.first.methods.sort.reverse
387
- assert_equal(4, methods.length)
388
-
389
- methods = result.threads.last.methods.sort.reverse
390
- assert_equal(5, methods.length)
391
-
392
- # Check times
393
- method = methods[0]
394
- assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
395
- assert_in_delta(0.0, method.total_time, 0.05)
396
- assert_in_delta(0.0, method.wait_time, 0.05)
397
- assert_in_delta(0.0, method.self_time, 0.05)
398
- assert_in_delta(0.0, method.children_time, 0.05)
399
-
400
- method = methods[1]
401
- assert_equal('RubyProf::C1#sleep_wait', method.full_name)
402
- assert_in_delta(0.0, method.total_time, 0.05)
403
- assert_in_delta(0.0, method.wait_time, 0.05)
404
- assert_in_delta(0.0, method.self_time, 0.05)
405
- assert_in_delta(0.0, method.children_time, 0.05)
406
-
407
- method = methods[2]
408
- assert_equal('Kernel#sleep', method.full_name)
409
- assert_in_delta(0.0, method.total_time, 0.05)
410
- assert_in_delta(0.0, method.wait_time, 0.05)
411
- assert_in_delta(0.0, method.self_time, 0.05)
412
- assert_in_delta(0.0, method.children_time, 0.05)
413
-
414
- method = methods[3]
415
- assert_equal('Class#new', method.full_name)
416
- assert_in_delta(0.0, method.total_time, 0.05)
417
- assert_in_delta(0.0, method.wait_time, 0.05)
418
- assert_in_delta(0.0, method.self_time, 0.05)
419
- assert_in_delta(0.0, method.children_time, 0.05)
420
-
421
- method = methods[4]
422
- assert_equal('BasicObject#initialize', method.full_name)
423
- assert_in_delta(0.0, method.total_time, 0.05)
424
- assert_in_delta(0.0, method.wait_time, 0.05)
425
- assert_in_delta(0.0, method.self_time, 0.05)
426
- assert_in_delta(0.0, method.children_time, 0.05)
427
- end
428
-
429
- def test_instance_methods_busy
430
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
431
- RubyProf::C1.new.busy_wait
432
- end
433
-
434
- thread = result.threads.first
435
- assert_in_delta(0.2, thread.total_time, 0.05)
436
-
437
- methods = result.threads.first.methods.sort.reverse
438
- assert_equal(5, methods.length)
439
-
440
- # Check times
441
- method = methods[0]
442
- assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
443
- assert_in_delta(0.2, method.total_time, 0.05)
444
- assert_in_delta(0.0, method.wait_time, 0.05)
445
- assert_in_delta(0.0, method.self_time, 0.05)
446
- assert_in_delta(0.2, method.children_time, 0.05)
447
-
448
- method = methods[1]
449
- assert_equal('RubyProf::C1#busy_wait', method.full_name)
450
- assert_in_delta(0.2, method.total_time, 0.05)
451
- assert_in_delta(0.0, method.wait_time, 0.05)
452
- assert_in_delta(0.09, method.self_time, 0.05)
453
- assert_in_delta(0.11, method.children_time, 0.05)
454
-
455
- method = methods[2]
456
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
457
- assert_in_delta(0.11, method.total_time, 0.05)
458
- assert_in_delta(0.0, method.wait_time, 0.05)
459
- assert_in_delta(0.11, method.self_time, 0.05)
460
- assert_in_delta(0.0, method.children_time, 0.05)
461
-
462
- method = methods[3]
463
- assert_equal('Class#new', method.full_name)
464
- assert_in_delta(0.0, method.total_time, 0.05)
465
- assert_in_delta(0.0, method.wait_time, 0.05)
466
- assert_in_delta(0.0, method.self_time, 0.05)
467
- assert_in_delta(0.0, method.children_time, 0.05)
468
-
469
- method = methods[4]
470
- assert_equal('BasicObject#initialize', method.full_name)
471
- assert_in_delta(0.0, method.total_time, 0.05)
472
- assert_in_delta(0.0, method.wait_time, 0.05)
473
- assert_in_delta(0.0, method.self_time, 0.05)
474
- assert_in_delta(0.0, method.children_time, 0.05)
475
- end
476
-
477
- def test_instance_methods_busy_block
478
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
479
- 1.times { RubyProf::C1.new.busy_wait }
480
- end
481
-
482
- methods = result.threads.first.methods.sort.reverse
483
- assert_equal(6, methods.length)
484
-
485
- # Check times
486
- method = methods[0]
487
- assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
488
- assert_in_delta(0.2, method.total_time, 0.05)
489
- assert_in_delta(0.0, method.wait_time, 0.05)
490
- assert_in_delta(0.0, method.self_time, 0.05)
491
- assert_in_delta(0.2, method.children_time, 0.05)
492
-
493
- method = methods[1]
494
- assert_equal('Integer#times', method.full_name)
495
- assert_in_delta(0.2, method.total_time, 0.05)
496
- assert_in_delta(0.0, method.wait_time, 0.05)
497
- assert_in_delta(0.0, method.self_time, 0.05)
498
- assert_in_delta(0.2, method.children_time, 0.05)
499
-
500
- method = methods[2]
501
- assert_equal('RubyProf::C1#busy_wait', method.full_name)
502
- assert_in_delta(0.2, method.total_time, 0.05)
503
- assert_in_delta(0.0, method.wait_time, 0.05)
504
- assert_in_delta(0.09, method.self_time, 0.05)
505
- assert_in_delta(0.11, method.children_time, 0.05)
506
-
507
- method = methods[3]
508
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
509
- assert_in_delta(0.11, method.total_time, 0.05)
510
- assert_in_delta(0.0, method.wait_time, 0.05)
511
- assert_in_delta(0.11, method.self_time, 0.05)
512
- assert_in_delta(0.0, method.children_time, 0.05)
513
-
514
- method = methods[4]
515
- assert_equal('Class#new', method.full_name)
516
- assert_in_delta(0.0, method.total_time, 0.05)
517
- assert_in_delta(0.0, method.wait_time, 0.05)
518
- assert_in_delta(0.0, method.self_time, 0.05)
519
- assert_in_delta(0.0, method.children_time, 0.05)
520
-
521
- method = methods[5]
522
- assert_equal('BasicObject#initialize', method.full_name)
523
- assert_in_delta(0.0, method.total_time, 0.05)
524
- assert_in_delta(0.0, method.wait_time, 0.05)
525
- assert_in_delta(0.0, method.self_time, 0.05)
526
- assert_in_delta(0.0, method.children_time, 0.05)
527
- end
528
-
529
- def test_instance_methods_busy_threaded
530
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
531
- background_thread = Thread.new do
532
- RubyProf::C1.new.busy_wait
533
- end
534
- background_thread.join
535
- end
536
-
537
- assert_equal(2, result.threads.count)
538
-
539
- thread = result.threads.first
540
- assert_in_delta(0.2, thread.total_time, 0.05)
541
-
542
- methods = result.threads.first.methods.sort.reverse
543
- assert_equal(4, methods.length)
544
-
545
- # Check times
546
- method = methods[0]
547
- assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
548
- assert_in_delta(0.2, method.total_time, 0.05)
549
- assert_in_delta(0.0, method.wait_time, 0.05)
550
- assert_in_delta(0.0, method.self_time, 0.05)
551
- assert_in_delta(0.2, method.children_time, 0.05)
552
-
553
- method = methods[1]
554
- assert_equal('Thread#join', method.full_name)
555
- assert_in_delta(0.2, method.total_time, 0.05)
556
- assert_in_delta(0.2, method.wait_time, 0.05)
557
- assert_in_delta(0.0, method.self_time, 0.05)
558
- assert_in_delta(0.0, method.children_time, 0.05)
559
-
560
- method = methods[2]
561
- assert_equal('<Class::Thread>#new', method.full_name)
562
- assert_in_delta(0.0, method.total_time, 0.05)
563
- assert_in_delta(0.0, method.wait_time, 0.05)
564
- assert_in_delta(0.0, method.self_time, 0.05)
565
- assert_in_delta(0.0, method.children_time, 0.05)
566
-
567
- method = methods[3]
568
- assert_equal('Thread#initialize', method.full_name)
569
- assert_in_delta(0.0, method.total_time, 0.05)
570
- assert_in_delta(0.0, method.wait_time, 0.05)
571
- assert_in_delta(0.0, method.self_time, 0.05)
572
- assert_in_delta(0.0, method.children_time, 0.05)
573
-
574
- thread = result.threads.last
575
- assert_in_delta(0.2, thread.total_time, 0.05)
576
-
577
- methods = result.threads.first.methods.sort.reverse
578
- assert_equal(4, methods.length)
579
-
580
- methods = result.threads.last.methods.sort.reverse
581
- assert_equal(5, methods.length)
582
-
583
- # Check times
584
- method = methods[0]
585
- assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
586
- assert_in_delta(0.2, method.total_time, 0.05)
587
- assert_in_delta(0.0, method.wait_time, 0.05)
588
- assert_in_delta(0.0, method.self_time, 0.05)
589
- assert_in_delta(0.2, method.children_time, 0.05)
590
-
591
- method = methods[1]
592
- assert_equal('RubyProf::C1#busy_wait', method.full_name)
593
- assert_in_delta(0.2, method.total_time, 0.05)
594
- assert_in_delta(0.0, method.wait_time, 0.05)
595
- assert_in_delta(0.1, method.self_time, 0.05)
596
- assert_in_delta(0.1, method.children_time, 0.05)
597
-
598
- method = methods[2]
599
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
600
- assert_in_delta(0.1, method.total_time, 0.05)
601
- assert_in_delta(0.0, method.wait_time, 0.05)
602
- assert_in_delta(0.1, method.self_time, 0.05)
603
- assert_in_delta(0.0, method.children_time, 0.05)
604
-
605
- method = methods[3]
606
- assert_equal('Class#new', method.full_name)
607
- assert_in_delta(0.0, method.total_time, 0.05)
608
- assert_in_delta(0.0, method.wait_time, 0.05)
609
- assert_in_delta(0.0, method.self_time, 0.05)
610
- assert_in_delta(0.0, method.children_time, 0.05)
611
-
612
- method = methods[4]
613
- assert_equal('BasicObject#initialize', method.full_name)
614
- assert_in_delta(0.0, method.total_time, 0.05)
615
- assert_in_delta(0.0, method.wait_time, 0.05)
616
- assert_in_delta(0.0, method.self_time, 0.05)
617
- assert_in_delta(0.0, method.children_time, 0.05)
618
- end
619
-
620
- def test_module_methods_sleep
621
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
622
- RubyProf::C2.sleep_wait
623
- end
624
-
625
- thread = result.threads.first
626
- assert_in_delta(0.0, thread.total_time, 0.05)
627
-
628
- methods = result.threads.first.methods.sort.reverse
629
- assert_equal(3, methods.length)
630
-
631
- # Check times
632
- method = methods[0]
633
- assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
634
- assert_in_delta(0.0, method.total_time, 0.05)
635
- assert_in_delta(0.0, method.wait_time, 0.05)
636
- assert_in_delta(0.0, method.self_time, 0.05)
637
- assert_in_delta(0.0, method.children_time, 0.05)
638
-
639
- method = methods[1]
640
- assert_equal('RubyProf::M1#sleep_wait', method.full_name)
641
- assert_in_delta(0.0, method.total_time, 0.05)
642
- assert_in_delta(0.0, method.wait_time, 0.05)
643
- assert_in_delta(0.0, method.self_time, 0.05)
644
- assert_in_delta(0.0, method.children_time, 0.05)
645
-
646
- method = methods[2]
647
- assert_equal('Kernel#sleep', method.full_name)
648
- assert_in_delta(0.0, method.total_time, 0.05)
649
- assert_in_delta(0.0, method.wait_time, 0.05)
650
- assert_in_delta(0.0, method.self_time, 0.05)
651
- assert_in_delta(0.0, method.children_time, 0.05)
652
- end
653
-
654
- def test_module_methods_busy
655
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
656
- RubyProf::C2.busy_wait
657
- end
658
-
659
- thread = result.threads.first
660
- assert_in_delta(0.3, thread.total_time, 0.05)
661
-
662
- methods = result.threads.first.methods.sort.reverse
663
- assert_equal(3, methods.length)
664
-
665
- # Check times
666
- method = methods[0]
667
- assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
668
- assert_in_delta(0.3, method.total_time, 0.05)
669
- assert_in_delta(0.0, method.wait_time, 0.05)
670
- assert_in_delta(0.0, method.self_time, 0.05)
671
- assert_in_delta(0.3, method.children_time, 0.05)
672
-
673
- method = methods[1]
674
- assert_equal('RubyProf::M1#busy_wait', method.full_name)
675
- assert_in_delta(0.3, method.total_time, 0.05)
676
- assert_in_delta(0.0, method.wait_time, 0.05)
677
- assert_in_delta(0.15, method.self_time, 0.05)
678
- assert_in_delta(0.15, method.children_time, 0.05)
679
-
680
- method = methods[2]
681
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
682
- assert_in_delta(0.15, method.total_time, 0.05)
683
- assert_in_delta(0.0, method.wait_time, 0.05)
684
- assert_in_delta(0.15, method.self_time, 0.05)
685
- assert_in_delta(0.0, method.children_time, 0.05)
686
- end
687
-
688
- def test_module_instance_methods_sleep
689
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
690
- RubyProf::C2.new.sleep_wait
691
- end
692
-
693
- thread = result.threads.first
694
- assert_in_delta(0.0, thread.total_time, 0.05)
695
-
696
- methods = result.threads.first.methods.sort.reverse
697
- assert_equal(5, methods.length)
698
-
699
- # Check times
700
- method = methods[0]
701
- assert_equal('MeasureProcessTimeTest#test_module_instance_methods_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
-
707
- method = methods[1]
708
- assert_equal('RubyProf::M1#sleep_wait', method.full_name)
709
- assert_in_delta(0.0, method.total_time, 0.05)
710
- assert_in_delta(0.0, method.wait_time, 0.05)
711
- assert_in_delta(0.0, method.self_time, 0.05)
712
- assert_in_delta(0.0, method.children_time, 0.05)
713
-
714
- method = methods[2]
715
- assert_equal('Kernel#sleep', method.full_name)
716
- assert_in_delta(0.0, method.total_time, 0.05)
717
- assert_in_delta(0.0, method.wait_time, 0.05)
718
- assert_in_delta(0.0, method.self_time, 0.05)
719
- assert_in_delta(0.0, method.children_time, 0.05)
720
-
721
- method = methods[3]
722
- assert_equal('Class#new', method.full_name)
723
- assert_in_delta(0.0, method.total_time, 0.05)
724
- assert_in_delta(0.0, method.wait_time, 0.05)
725
- assert_in_delta(0.0, method.self_time, 0.05)
726
- assert_in_delta(0.0, method.children_time, 0.05)
727
-
728
- method = methods[4]
729
- assert_equal('BasicObject#initialize', method.full_name)
730
- assert_in_delta(0.0, method.total_time, 0.05)
731
- assert_in_delta(0.0, method.wait_time, 0.05)
732
- assert_in_delta(0.0, method.self_time, 0.05)
733
- assert_in_delta(0.0, method.children_time, 0.05)
734
- end
735
-
736
- def test_module_instance_methods_busy
737
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
738
- RubyProf::C2.new.busy_wait
739
- end
740
-
741
- thread = result.threads.first
742
- assert_in_delta(0.3, thread.total_time, 0.05)
743
-
744
- methods = result.threads.first.methods.sort.reverse
745
- assert_equal(5, methods.length)
746
-
747
- # Check times
748
- method = methods[0]
749
- assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
750
- assert_in_delta(0.3, method.total_time, 0.05)
751
- assert_in_delta(0.0, method.wait_time, 0.05)
752
- assert_in_delta(0.0, method.self_time, 0.05)
753
- assert_in_delta(0.3, method.children_time, 0.05)
754
-
755
- method = methods[1]
756
- assert_equal('RubyProf::M1#busy_wait', method.full_name)
757
- assert_in_delta(0.3, method.total_time, 0.05)
758
- assert_in_delta(0.0, method.wait_time, 0.05)
759
- assert_in_delta(0.15, method.self_time, 0.05)
760
- assert_in_delta(0.15, method.children_time, 0.05)
761
-
762
- method = methods[2]
763
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
764
- assert_in_delta(0.15, method.total_time, 0.05)
765
- assert_in_delta(0.0, method.wait_time, 0.05)
766
- assert_in_delta(0.15, method.self_time, 0.05)
767
- assert_in_delta(0.0, method.children_time, 0.05)
768
-
769
- method = methods[3]
770
- assert_equal('Class#new', 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[4]
777
- assert_equal('BasicObject#initialize', 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
- end
783
- else # Ruby 3.1 and higher
784
- def test_class_methods_sleep
785
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
786
- RubyProf::C1.sleep_wait
787
- end
788
-
789
- thread = result.threads.first
790
- assert_in_delta(0.0, thread.total_time, 0.05)
791
-
792
- methods = result.threads.first.methods.sort.reverse
793
- assert_equal(3, methods.length)
794
-
795
- # Check times
796
- method = methods[0]
797
- assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
798
- assert_in_delta(0.0, method.total_time, 0.05)
799
- assert_in_delta(0.0, method.wait_time, 0.05)
800
- assert_in_delta(0.0, method.self_time, 0.05)
801
- assert_in_delta(0.0, method.children_time, 0.05)
802
-
803
- method = methods[1]
804
- assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
805
- assert_in_delta(0.0, method.total_time, 0.05)
806
- assert_in_delta(0.0, method.wait_time, 0.05)
807
- assert_in_delta(0.0, method.self_time, 0.05)
808
- assert_in_delta(0.0, method.children_time, 0.05)
809
-
810
- method = methods[2]
811
- assert_equal('Kernel#sleep', method.full_name)
812
- assert_in_delta(0.0, method.total_time, 0.05)
813
- assert_in_delta(0.0, method.wait_time, 0.05)
814
- assert_in_delta(0.0, method.self_time, 0.05)
815
- assert_in_delta(0.0, method.children_time, 0.05)
816
- end
817
-
818
- def test_class_methods_sleep_threaded
819
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
820
- background_thread = Thread.new do
821
- RubyProf::C1.sleep_wait
822
- end
823
- background_thread.join
824
- end
825
-
826
- assert_equal(2, result.threads.count)
827
-
828
- thread = result.threads.first
829
- assert_in_delta(0.0, thread.total_time, 0.05)
830
-
831
- methods = result.threads.first.methods.sort.reverse
832
- assert_equal(4, methods.length)
833
-
834
- # Check times
835
- method = methods[0]
836
- assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', 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[1]
843
- assert_equal('Thread#join', 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
-
849
- method = methods[2]
850
- assert_equal('<Class::Thread>#new', method.full_name)
851
- assert_in_delta(0.0, method.total_time, 0.05)
852
- assert_in_delta(0.0, method.wait_time, 0.05)
853
- assert_in_delta(0.0, method.self_time, 0.05)
854
- assert_in_delta(0.0, method.children_time, 0.05)
855
-
856
- method = methods[3]
857
- assert_equal('Thread#initialize', method.full_name)
858
- assert_in_delta(0.0, method.total_time, 0.05)
859
- assert_in_delta(0.0, method.wait_time, 0.05)
860
- assert_in_delta(0.0, method.self_time, 0.05)
861
- assert_in_delta(0.0, method.children_time, 0.05)
862
-
863
- thread = result.threads.last
864
- assert_in_delta(0.0, thread.total_time, 0.05)
865
-
866
- methods = result.threads.first.methods.sort.reverse
867
- assert_equal(4, methods.length)
868
-
869
- methods = result.threads.last.methods.sort.reverse
870
- assert_equal(3, methods.length)
871
-
872
- # Check times
873
- method = methods[0]
874
- assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
875
- assert_in_delta(0.0, method.total_time, 0.05)
876
- assert_in_delta(0.0, method.wait_time, 0.05)
877
- assert_in_delta(0.0, method.self_time, 0.05)
878
- assert_in_delta(0.0, method.children_time, 0.05)
879
-
880
- method = methods[1]
881
- assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
882
- assert_in_delta(0.0, method.total_time, 0.05)
883
- assert_in_delta(0.0, method.wait_time, 0.05)
884
- assert_in_delta(0.0, method.self_time, 0.05)
885
- assert_in_delta(0.0, method.children_time, 0.05)
886
-
887
- method = methods[2]
888
- assert_equal('Kernel#sleep', method.full_name)
889
- assert_in_delta(0.0, method.total_time, 0.05)
890
- assert_in_delta(0.0, method.wait_time, 0.05)
891
- assert_in_delta(0.0, method.self_time, 0.05)
892
- assert_in_delta(0.0, method.children_time, 0.05)
893
- end
894
-
895
- def test_class_methods_busy
896
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
897
- RubyProf::C1.busy_wait
898
- end
899
-
900
- thread = result.threads.first
901
- assert_in_delta(0.08, thread.total_time, 0.05)
902
-
903
- methods = result.threads.first.methods.sort.reverse
904
- assert_equal(5, methods.length)
905
-
906
- # Check times
907
- method = methods[0]
908
- assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
909
- assert_in_delta(0.1, method.total_time, 0.05)
910
- assert_in_delta(0.0, method.wait_time, 0.05)
911
- assert_in_delta(0.0, method.self_time, 0.05)
912
- assert_in_delta(0.1, method.children_time, 0.05)
913
-
914
- method = methods[1]
915
- assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
916
- assert_in_delta(0.1, method.total_time, 0.05)
917
- assert_in_delta(0.0, method.wait_time, 0.05)
918
- assert_in_delta(0.06, method.self_time, 0.05)
919
- assert_in_delta(0.07, method.children_time, 0.05)
920
-
921
- method = methods[2]
922
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
923
- assert_in_delta(0.05, method.total_time, 0.05)
924
- assert_in_delta(0.0, method.wait_time, 0.05)
925
- assert_in_delta(0.05, method.self_time, 0.05)
926
- assert_in_delta(0.0, method.children_time, 0.05)
927
- end
928
-
929
- def test_class_methods_busy_threaded
930
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
931
- background_thread = Thread.new do
932
- RubyProf::C1.busy_wait
933
- end
934
- background_thread.join
935
- end
936
-
937
- assert_equal(2, result.threads.count)
938
-
939
- thread = result.threads.first
940
- assert_in_delta(0.1, thread.total_time, 0.05)
941
-
942
- methods = result.threads.first.methods.sort.reverse
943
- assert_equal(4, methods.length)
944
-
945
- # Check times
946
- method = methods[0]
947
- assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
948
- assert_in_delta(0.1, method.total_time, 0.05)
949
- assert_in_delta(0.0, method.wait_time, 0.05)
950
- assert_in_delta(0.0, method.self_time, 0.05)
951
- assert_in_delta(0.1, method.children_time, 0.05)
952
-
953
- method = methods[1]
954
- assert_equal('Thread#join', method.full_name)
955
- assert_in_delta(0.1, method.total_time, 0.05)
956
- assert_in_delta(0.1, method.wait_time, 0.05)
957
- assert_in_delta(0.0, method.self_time, 0.05)
958
- assert_in_delta(0.0, method.children_time, 0.05)
959
-
960
- method = methods[2]
961
- assert_equal('<Class::Thread>#new', method.full_name)
962
- assert_in_delta(0.0, method.total_time, 0.05)
963
- assert_in_delta(0.0, method.wait_time, 0.05)
964
- assert_in_delta(0.0, method.self_time, 0.05)
965
- assert_in_delta(0.0, method.children_time, 0.05)
966
-
967
- method = methods[3]
968
- assert_equal('Thread#initialize', method.full_name)
969
- assert_in_delta(0.0, method.total_time, 0.05)
970
- assert_in_delta(0.0, method.wait_time, 0.05)
971
- assert_in_delta(0.0, method.self_time, 0.05)
972
- assert_in_delta(0.0, method.children_time, 0.05)
973
-
974
- thread = result.threads.last
975
- assert_in_delta(0.1, thread.total_time, 0.05)
976
-
977
- methods = result.threads.first.methods.sort.reverse
978
- assert_equal(4, methods.length)
979
-
980
- methods = result.threads.last.methods.sort.reverse
981
- assert_equal(5, methods.length)
982
-
983
- # Check times
984
- method = methods[0]
985
- assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
986
- assert_in_delta(0.1, method.total_time, 0.05)
987
- assert_in_delta(0.0, method.wait_time, 0.05)
988
- assert_in_delta(0.0, method.self_time, 0.05)
989
- assert_in_delta(0.1, method.children_time, 0.05)
990
-
991
- method = methods[1]
992
- assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
993
- assert_in_delta(0.1, method.total_time, 0.05)
994
- assert_in_delta(0.0, method.wait_time, 0.05)
995
- assert_in_delta(0.05, method.self_time, 0.05)
996
- assert_in_delta(0.05, method.children_time, 0.05)
997
-
998
- method = methods[2]
999
- assert('<Module::Process>#clock_gettime' == method.full_name ||
1000
- 'Float#<' == method.full_name)
1001
- assert_in_delta(0.05, method.total_time, 0.05)
1002
- assert_in_delta(0.0, method.wait_time, 0.05)
1003
- assert_in_delta(0.05, method.self_time, 0.05)
1004
- assert_in_delta(0.0, method.children_time, 0.05)
1005
- end
1006
-
1007
- def test_instance_methods_sleep
1008
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1009
- RubyProf::C1.new.sleep_wait
1010
- end
1011
-
1012
- thread = result.threads.first
1013
- assert_in_delta(0.0, thread.total_time, 0.05)
1014
-
1015
- methods = result.threads.first.methods.sort.reverse
1016
- assert_equal(5, methods.length)
1017
-
1018
- # Check times
1019
- method = methods[0]
1020
- assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
1021
- assert_in_delta(0.0, method.total_time, 0.05)
1022
- assert_in_delta(0.0, method.wait_time, 0.05)
1023
- assert_in_delta(0.0, method.self_time, 0.05)
1024
- assert_in_delta(0.0, method.children_time, 0.05)
1025
-
1026
- method = methods[1]
1027
- assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1028
- assert_in_delta(0.0, method.total_time, 0.05)
1029
- assert_in_delta(0.0, method.wait_time, 0.05)
1030
- assert_in_delta(0.0, method.self_time, 0.05)
1031
- assert_in_delta(0.0, method.children_time, 0.05)
1032
-
1033
- method = methods[2]
1034
- assert_equal('Kernel#sleep', method.full_name)
1035
- assert_in_delta(0.0, method.total_time, 0.05)
1036
- assert_in_delta(0.0, method.wait_time, 0.05)
1037
- assert_in_delta(0.0, method.self_time, 0.05)
1038
- assert_in_delta(0.0, method.children_time, 0.05)
1039
-
1040
- method = methods[3]
1041
- assert_equal('Class#new', method.full_name)
1042
- assert_in_delta(0.0, method.total_time, 0.05)
1043
- assert_in_delta(0.0, method.wait_time, 0.05)
1044
- assert_in_delta(0.0, method.self_time, 0.05)
1045
- assert_in_delta(0.0, method.children_time, 0.05)
1046
-
1047
- method = methods[4]
1048
- assert_equal('BasicObject#initialize', method.full_name)
1049
- assert_in_delta(0.0, method.total_time, 0.05)
1050
- assert_in_delta(0.0, method.wait_time, 0.05)
1051
- assert_in_delta(0.0, method.self_time, 0.05)
1052
- assert_in_delta(0.0, method.children_time, 0.05)
1053
- end
1054
-
1055
- def test_instance_methods_sleep_block
1056
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1057
- 1.times { RubyProf::C1.new.sleep_wait }
1058
- end
1059
-
1060
- methods = result.threads.first.methods.sort.reverse
1061
- assert_equal(6, methods.length)
1062
-
1063
- # Check times
1064
- method = methods[0]
1065
- assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
1066
- assert_in_delta(0.0, method.total_time, 0.05)
1067
- assert_in_delta(0.0, method.wait_time, 0.05)
1068
- assert_in_delta(0.0, method.self_time, 0.05)
1069
- assert_in_delta(0.0, method.children_time, 0.05)
1070
-
1071
- method = methods[1]
1072
- assert_equal('Integer#times', method.full_name)
1073
- assert_in_delta(0.0, method.total_time, 0.05)
1074
- assert_in_delta(0.0, method.wait_time, 0.05)
1075
- assert_in_delta(0.0, method.self_time, 0.05)
1076
- assert_in_delta(0.0, method.children_time, 0.05)
1077
-
1078
- method = methods[2]
1079
- assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1080
- assert_in_delta(0.0, method.total_time, 0.05)
1081
- assert_in_delta(0.0, method.wait_time, 0.05)
1082
- assert_in_delta(0.0, method.self_time, 0.05)
1083
- assert_in_delta(0.0, method.children_time, 0.05)
1084
-
1085
- method = methods[3]
1086
- assert_equal('Kernel#sleep', method.full_name)
1087
- assert_in_delta(0.0, method.total_time, 0.05)
1088
- assert_in_delta(0.0, method.wait_time, 0.05)
1089
- assert_in_delta(0.0, method.self_time, 0.05)
1090
- assert_in_delta(0.0, method.children_time, 0.05)
1091
-
1092
- method = methods[4]
1093
- assert_equal('Class#new', method.full_name)
1094
- assert_in_delta(0.0, method.total_time, 0.05)
1095
- assert_in_delta(0.0, method.wait_time, 0.05)
1096
- assert_in_delta(0.0, method.self_time, 0.05)
1097
- assert_in_delta(0.0, method.children_time, 0.05)
1098
-
1099
- method = methods[5]
1100
- assert_equal('BasicObject#initialize', method.full_name)
1101
- assert_in_delta(0.0, method.total_time, 0.05)
1102
- assert_in_delta(0.0, method.wait_time, 0.05)
1103
- assert_in_delta(0.0, method.self_time, 0.05)
1104
- assert_in_delta(0.0, method.children_time, 0.05)
1105
- end
1106
-
1107
- def test_instance_methods_sleep_threaded
1108
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1109
- background_thread = Thread.new do
1110
- RubyProf::C1.new.sleep_wait
1111
- end
1112
- background_thread.join
1113
- end
1114
-
1115
- assert_equal(2, result.threads.count)
1116
-
1117
- thread = result.threads.first
1118
- assert_in_delta(0.0, thread.total_time, 0.05)
1119
-
1120
- methods = result.threads.first.methods.sort.reverse
1121
- assert_equal(4, methods.length)
1122
-
1123
- # Check times
1124
- method = methods[0]
1125
- assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1126
- assert_in_delta(0.0, method.total_time, 0.05)
1127
- assert_in_delta(0.0, method.wait_time, 0.05)
1128
- assert_in_delta(0.0, method.self_time, 0.05)
1129
- assert_in_delta(0.0, method.children_time, 0.05)
1130
-
1131
- method = methods[1]
1132
- assert_equal('Thread#join', method.full_name)
1133
- assert_in_delta(0.0, method.total_time, 0.05)
1134
- assert_in_delta(0.0, method.wait_time, 0.05)
1135
- assert_in_delta(0.0, method.self_time, 0.05)
1136
- assert_in_delta(0.0, method.children_time, 0.05)
1137
-
1138
- method = methods[2]
1139
- assert_equal('<Class::Thread>#new', method.full_name)
1140
- assert_in_delta(0.0, method.total_time, 0.05)
1141
- assert_in_delta(0.0, method.wait_time, 0.05)
1142
- assert_in_delta(0.0, method.self_time, 0.05)
1143
- assert_in_delta(0.0, method.children_time, 0.05)
1144
-
1145
- method = methods[3]
1146
- assert_equal('Thread#initialize', method.full_name)
1147
- assert_in_delta(0.0, method.total_time, 0.05)
1148
- assert_in_delta(0.0, method.wait_time, 0.05)
1149
- assert_in_delta(0.0, method.self_time, 0.05)
1150
- assert_in_delta(0.0, method.children_time, 0.05)
1151
-
1152
- thread = result.threads.last
1153
- assert_in_delta(0.0, thread.total_time, 0.05)
1154
-
1155
- methods = result.threads.first.methods.sort.reverse
1156
- assert_equal(4, methods.length)
1157
-
1158
- methods = result.threads.last.methods.sort.reverse
1159
- assert_equal(5, methods.length)
1160
-
1161
- # Check times
1162
- method = methods[0]
1163
- assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1164
- assert_in_delta(0.0, method.total_time, 0.05)
1165
- assert_in_delta(0.0, method.wait_time, 0.05)
1166
- assert_in_delta(0.0, method.self_time, 0.05)
1167
- assert_in_delta(0.0, method.children_time, 0.05)
1168
-
1169
- method = methods[1]
1170
- assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1171
- assert_in_delta(0.0, method.total_time, 0.05)
1172
- assert_in_delta(0.0, method.wait_time, 0.05)
1173
- assert_in_delta(0.0, method.self_time, 0.05)
1174
- assert_in_delta(0.0, method.children_time, 0.05)
1175
-
1176
- method = methods[2]
1177
- assert_equal('Kernel#sleep', method.full_name)
1178
- assert_in_delta(0.0, method.total_time, 0.05)
1179
- assert_in_delta(0.0, method.wait_time, 0.05)
1180
- assert_in_delta(0.0, method.self_time, 0.05)
1181
- assert_in_delta(0.0, method.children_time, 0.05)
1182
-
1183
- method = methods[3]
1184
- assert_equal('Class#new', method.full_name)
1185
- assert_in_delta(0.0, method.total_time, 0.05)
1186
- assert_in_delta(0.0, method.wait_time, 0.05)
1187
- assert_in_delta(0.0, method.self_time, 0.05)
1188
- assert_in_delta(0.0, method.children_time, 0.05)
1189
-
1190
- method = methods[4]
1191
- assert_equal('BasicObject#initialize', method.full_name)
1192
- assert_in_delta(0.0, method.total_time, 0.05)
1193
- assert_in_delta(0.0, method.wait_time, 0.05)
1194
- assert_in_delta(0.0, method.self_time, 0.05)
1195
- assert_in_delta(0.0, method.children_time, 0.05)
1196
- end
1197
-
1198
- def test_instance_methods_busy
1199
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1200
- RubyProf::C1.new.busy_wait
1201
- end
1202
-
1203
- thread = result.threads.first
1204
- assert_in_delta(0.2, thread.total_time, 0.05)
1205
-
1206
- methods = result.threads.first.methods.sort.reverse
1207
- assert_equal(7, methods.length)
1208
-
1209
- # Check times
1210
- method = methods[0]
1211
- assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
1212
- assert_in_delta(0.2, method.total_time, 0.05)
1213
- assert_in_delta(0.0, method.wait_time, 0.05)
1214
- assert_in_delta(0.0, method.self_time, 0.05)
1215
- assert_in_delta(0.2, method.children_time, 0.05)
1216
-
1217
- method = methods[1]
1218
- assert_equal('RubyProf::C1#busy_wait', method.full_name)
1219
- assert_in_delta(0.2, method.total_time, 0.05)
1220
- assert_in_delta(0.0, method.wait_time, 0.05)
1221
- assert_in_delta(0.09, method.self_time, 0.05)
1222
- assert_in_delta(0.11, method.children_time, 0.05)
1223
-
1224
- method = methods[2]
1225
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
1226
- assert_in_delta(0.033, method.total_time, 0.05)
1227
- assert_in_delta(0.0, method.wait_time, 0.05)
1228
- assert_in_delta(0.033, method.self_time, 0.05)
1229
- assert_in_delta(0.0, method.children_time, 0.05)
1230
-
1231
- method = methods[3]
1232
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1233
- assert_in_delta(0.0, method.total_time, 0.05)
1234
- assert_in_delta(0.0, method.wait_time, 0.05)
1235
- assert_in_delta(0.0, method.self_time, 0.05)
1236
- assert_in_delta(0.0, method.children_time, 0.05)
1237
-
1238
- method = methods[4]
1239
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1240
- assert_in_delta(0.0, method.total_time, 0.05)
1241
- assert_in_delta(0.0, method.wait_time, 0.05)
1242
- assert_in_delta(0.0, method.self_time, 0.05)
1243
- assert_in_delta(0.0, method.children_time, 0.05)
1244
-
1245
- method = methods[5]
1246
- assert_equal('Class#new', method.full_name)
1247
- assert_in_delta(0.0, method.total_time, 0.05)
1248
- assert_in_delta(0.0, method.wait_time, 0.05)
1249
- assert_in_delta(0.0, method.self_time, 0.05)
1250
- assert_in_delta(0.0, method.children_time, 0.05)
1251
-
1252
- method = methods[6]
1253
- assert_equal('BasicObject#initialize', method.full_name)
1254
- assert_in_delta(0.0, method.total_time, 0.05)
1255
- assert_in_delta(0.0, method.wait_time, 0.05)
1256
- assert_in_delta(0.0, method.self_time, 0.05)
1257
- assert_in_delta(0.0, method.children_time, 0.05)
1258
- end
1259
-
1260
- def test_instance_methods_busy_block
1261
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1262
- 1.times { RubyProf::C1.new.busy_wait }
1263
- end
1264
-
1265
- methods = result.threads.first.methods.sort.reverse
1266
- assert_equal(8, methods.length)
1267
-
1268
- # Check times
1269
- method = methods[0]
1270
- assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
1271
- assert_in_delta(0.2, method.total_time, 0.05)
1272
- assert_in_delta(0.0, method.wait_time, 0.05)
1273
- assert_in_delta(0.0, method.self_time, 0.05)
1274
- assert_in_delta(0.2, method.children_time, 0.05)
1275
-
1276
- method = methods[1]
1277
- assert_equal('Integer#times', method.full_name)
1278
- assert_in_delta(0.2, method.total_time, 0.05)
1279
- assert_in_delta(0.0, method.wait_time, 0.05)
1280
- assert_in_delta(0.0, method.self_time, 0.05)
1281
- assert_in_delta(0.2, method.children_time, 0.05)
1282
-
1283
- method = methods[2]
1284
- assert_equal('RubyProf::C1#busy_wait', method.full_name)
1285
- assert_in_delta(0.2, method.total_time, 0.05)
1286
- assert_in_delta(0.0, method.wait_time, 0.05)
1287
- assert_in_delta(0.09, method.self_time, 0.05)
1288
- assert_in_delta(0.11, method.children_time, 0.05)
1289
-
1290
- method = methods[3]
1291
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
1292
- assert_in_delta(0.033, method.total_time, 0.05)
1293
- assert_in_delta(0.0, method.wait_time, 0.05)
1294
- assert_in_delta(0.033, method.self_time, 0.05)
1295
- assert_in_delta(0.0, method.children_time, 0.05)
1296
-
1297
- method = methods[4]
1298
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1299
- assert_in_delta(0.03, method.total_time, 0.03)
1300
- assert_in_delta(0.03, method.wait_time, 0.03)
1301
- assert_in_delta(0.03, method.self_time, 0.03)
1302
- assert_in_delta(0.03, method.children_time, 0.03)
1303
-
1304
- method = methods[5]
1305
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1306
- assert_in_delta(0.03, method.total_time, 0.03)
1307
- assert_in_delta(0.03, method.wait_time, 0.03)
1308
- assert_in_delta(0.03, method.self_time, 0.03)
1309
- assert_in_delta(0.03, method.children_time, 0.03)
1310
-
1311
- method = methods[6]
1312
- assert_equal('Class#new', method.full_name)
1313
- assert_in_delta(0.0, method.total_time, 0.01)
1314
- assert_in_delta(0.0, method.wait_time, 0.01)
1315
- assert_in_delta(0.0, method.self_time, 0.01)
1316
- assert_in_delta(0.0, method.children_time, 0.01)
1317
-
1318
- method = methods[7]
1319
- assert_equal('BasicObject#initialize', method.full_name)
1320
- assert_in_delta(0.0, method.total_time, 0.05)
1321
- assert_in_delta(0.0, method.wait_time, 0.05)
1322
- assert_in_delta(0.0, method.self_time, 0.05)
1323
- assert_in_delta(0.0, method.children_time, 0.05)
1324
- end
1325
-
1326
- def test_instance_methods_busy_threaded
1327
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1328
- background_thread = Thread.new do
1329
- RubyProf::C1.new.busy_wait
1330
- end
1331
- background_thread.join
1332
- end
1333
-
1334
- assert_equal(2, result.threads.count)
1335
-
1336
- thread = result.threads.first
1337
- assert_in_delta(0.2, thread.total_time, 0.05)
1338
-
1339
- methods = result.threads.first.methods.sort.reverse
1340
- assert_equal(4, methods.length)
1341
-
1342
- # Check times
1343
- method = methods[0]
1344
- assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
1345
- assert_in_delta(0.2, method.total_time, 0.05)
1346
- assert_in_delta(0.0, method.wait_time, 0.05)
1347
- assert_in_delta(0.0, method.self_time, 0.05)
1348
- assert_in_delta(0.2, method.children_time, 0.05)
1349
-
1350
- method = methods[1]
1351
- assert_equal('Thread#join', method.full_name)
1352
- assert_in_delta(0.2, method.total_time, 0.05)
1353
- assert_in_delta(0.2, method.wait_time, 0.05)
1354
- assert_in_delta(0.0, method.self_time, 0.05)
1355
- assert_in_delta(0.0, method.children_time, 0.05)
1356
-
1357
- method = methods[2]
1358
- assert_equal('<Class::Thread>#new', method.full_name)
1359
- assert_in_delta(0.0, method.total_time, 0.05)
1360
- assert_in_delta(0.0, method.wait_time, 0.05)
1361
- assert_in_delta(0.0, method.self_time, 0.05)
1362
- assert_in_delta(0.0, method.children_time, 0.05)
1363
-
1364
- method = methods[3]
1365
- assert_equal('Thread#initialize', method.full_name)
1366
- assert_in_delta(0.0, method.total_time, 0.05)
1367
- assert_in_delta(0.0, method.wait_time, 0.05)
1368
- assert_in_delta(0.0, method.self_time, 0.05)
1369
- assert_in_delta(0.0, method.children_time, 0.05)
1370
-
1371
- thread = result.threads.last
1372
- assert_in_delta(0.2, thread.total_time, 0.05)
1373
-
1374
- methods = result.threads.first.methods.sort.reverse
1375
- assert_equal(4, methods.length)
1376
-
1377
- methods = result.threads.last.methods.sort.reverse
1378
- assert_equal(7, methods.length)
1379
-
1380
- # Check times
1381
- method = methods[0]
1382
- assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
1383
- assert_in_delta(0.2, method.total_time, 0.05)
1384
- assert_in_delta(0.0, method.wait_time, 0.05)
1385
- assert_in_delta(0.0, method.self_time, 0.05)
1386
- assert_in_delta(0.2, method.children_time, 0.05)
1387
-
1388
- method = methods[1]
1389
- assert_equal('RubyProf::C1#busy_wait', method.full_name)
1390
- assert_in_delta(0.2, method.total_time, 0.05)
1391
- assert_in_delta(0.0, method.wait_time, 0.05)
1392
- assert_in_delta(0.1, method.self_time, 0.05)
1393
- assert_in_delta(0.1, method.children_time, 0.05)
1394
-
1395
- method = methods[2]
1396
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
1397
- assert_in_delta(0.03, method.total_time, 0.05)
1398
- assert_in_delta(0.0, method.wait_time, 0.05)
1399
- assert_in_delta(0.03, method.self_time, 0.05)
1400
- assert_in_delta(0.0, method.children_time, 0.05)
1401
-
1402
- method = methods[3]
1403
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1404
- assert_in_delta(0.0, method.total_time, 0.05)
1405
- assert_in_delta(0.0, method.wait_time, 0.05)
1406
- assert_in_delta(0.0, method.self_time, 0.05)
1407
- assert_in_delta(0.0, method.children_time, 0.05)
1408
-
1409
- method = methods[4]
1410
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1411
- assert_in_delta(0.0, method.total_time, 0.05)
1412
- assert_in_delta(0.0, method.wait_time, 0.05)
1413
- assert_in_delta(0.0, method.self_time, 0.05)
1414
- assert_in_delta(0.0, method.children_time, 0.05)
1415
-
1416
- method = methods[5]
1417
- assert_equal('Class#new', method.full_name)
1418
- assert_in_delta(0.0, method.total_time, 0.05)
1419
- assert_in_delta(0.0, method.wait_time, 0.05)
1420
- assert_in_delta(0.0, method.self_time, 0.05)
1421
- assert_in_delta(0.0, method.children_time, 0.05)
1422
-
1423
- method = methods[6]
1424
- assert_equal('BasicObject#initialize', method.full_name)
1425
- assert_in_delta(0.0, method.total_time, 0.05)
1426
- assert_in_delta(0.0, method.wait_time, 0.05)
1427
- assert_in_delta(0.0, method.self_time, 0.05)
1428
- assert_in_delta(0.0, method.children_time, 0.05)
1429
- end
1430
-
1431
- def test_module_methods_sleep
1432
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1433
- RubyProf::C2.sleep_wait
1434
- end
1435
-
1436
- thread = result.threads.first
1437
- assert_in_delta(0.0, thread.total_time, 0.05)
1438
-
1439
- methods = result.threads.first.methods.sort.reverse
1440
- assert_equal(3, methods.length)
1441
-
1442
- # Check times
1443
- method = methods[0]
1444
- assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
1445
- assert_in_delta(0.0, method.total_time, 0.05)
1446
- assert_in_delta(0.0, method.wait_time, 0.05)
1447
- assert_in_delta(0.0, method.self_time, 0.05)
1448
- assert_in_delta(0.0, method.children_time, 0.05)
1449
-
1450
- method = methods[1]
1451
- assert_equal('RubyProf::M1#sleep_wait', method.full_name)
1452
- assert_in_delta(0.0, method.total_time, 0.05)
1453
- assert_in_delta(0.0, method.wait_time, 0.05)
1454
- assert_in_delta(0.0, method.self_time, 0.05)
1455
- assert_in_delta(0.0, method.children_time, 0.05)
1456
-
1457
- method = methods[2]
1458
- assert_equal('Kernel#sleep', method.full_name)
1459
- assert_in_delta(0.0, method.total_time, 0.05)
1460
- assert_in_delta(0.0, method.wait_time, 0.05)
1461
- assert_in_delta(0.0, method.self_time, 0.05)
1462
- assert_in_delta(0.0, method.children_time, 0.05)
1463
- end
1464
-
1465
- def test_module_methods_busy
1466
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1467
- RubyProf::C2.busy_wait
1468
- end
1469
-
1470
- thread = result.threads.first
1471
- assert_in_delta(0.3, thread.total_time, 0.05)
1472
-
1473
- methods = result.threads.first.methods.sort.reverse
1474
- assert_equal(5, methods.length)
1475
-
1476
- # Check times
1477
- method = methods[0]
1478
- assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
1479
- assert_in_delta(0.3, method.total_time, 0.05)
1480
- assert_in_delta(0.0, method.wait_time, 0.05)
1481
- assert_in_delta(0.0, method.self_time, 0.05)
1482
- assert_in_delta(0.3, method.children_time, 0.05)
1483
-
1484
- method = methods[1]
1485
- assert_equal('RubyProf::M1#busy_wait', method.full_name)
1486
- assert_in_delta(0.3, method.total_time, 0.05)
1487
- assert_in_delta(0.0, method.wait_time, 0.05)
1488
- assert_in_delta(0.15, method.self_time, 0.05)
1489
- assert_in_delta(0.15, method.children_time, 0.05)
1490
-
1491
- method = methods[2]
1492
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
1493
- assert_in_delta(0.05, method.total_time, 0.05)
1494
- assert_in_delta(0.0, method.wait_time, 0.05)
1495
- assert_in_delta(0.05, method.self_time, 0.05)
1496
- assert_in_delta(0.0, method.children_time, 0.05)
1497
- end
1498
-
1499
- def test_module_instance_methods_sleep
1500
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1501
- RubyProf::C2.new.sleep_wait
1502
- end
1503
-
1504
- thread = result.threads.first
1505
- assert_in_delta(0.0, thread.total_time, 0.05)
1506
-
1507
- methods = result.threads.first.methods.sort.reverse
1508
- assert_equal(5, methods.length)
1509
-
1510
- # Check times
1511
- method = methods[0]
1512
- assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
1513
- assert_in_delta(0.0, method.total_time, 0.05)
1514
- assert_in_delta(0.0, method.wait_time, 0.05)
1515
- assert_in_delta(0.0, method.self_time, 0.05)
1516
- assert_in_delta(0.0, method.children_time, 0.05)
1517
-
1518
- method = methods[1]
1519
- assert_equal('RubyProf::M1#sleep_wait', method.full_name)
1520
- assert_in_delta(0.0, method.total_time, 0.05)
1521
- assert_in_delta(0.0, method.wait_time, 0.05)
1522
- assert_in_delta(0.0, method.self_time, 0.05)
1523
- assert_in_delta(0.0, method.children_time, 0.05)
1524
-
1525
- method = methods[2]
1526
- assert_equal('Kernel#sleep', method.full_name)
1527
- assert_in_delta(0.0, method.total_time, 0.05)
1528
- assert_in_delta(0.0, method.wait_time, 0.05)
1529
- assert_in_delta(0.0, method.self_time, 0.05)
1530
- assert_in_delta(0.0, method.children_time, 0.05)
1531
-
1532
- method = methods[3]
1533
- assert_equal('Class#new', method.full_name)
1534
- assert_in_delta(0.0, method.total_time, 0.05)
1535
- assert_in_delta(0.0, method.wait_time, 0.05)
1536
- assert_in_delta(0.0, method.self_time, 0.05)
1537
- assert_in_delta(0.0, method.children_time, 0.05)
1538
-
1539
- method = methods[4]
1540
- assert_equal('BasicObject#initialize', method.full_name)
1541
- assert_in_delta(0.0, method.total_time, 0.05)
1542
- assert_in_delta(0.0, method.wait_time, 0.05)
1543
- assert_in_delta(0.0, method.self_time, 0.05)
1544
- assert_in_delta(0.0, method.children_time, 0.05)
1545
- end
1546
-
1547
- def test_module_instance_methods_busy
1548
- result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1549
- RubyProf::C2.new.busy_wait
1550
- end
1551
-
1552
- thread = result.threads.first
1553
- assert_in_delta(0.3, thread.total_time, 0.05)
1554
-
1555
- methods = result.threads.first.methods.sort.reverse
1556
- assert_equal(7, methods.length)
1557
-
1558
- # Check times
1559
- method = methods[0]
1560
- assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
1561
- assert_in_delta(0.3, method.total_time, 0.05)
1562
- assert_in_delta(0.0, method.wait_time, 0.05)
1563
- assert_in_delta(0.0, method.self_time, 0.05)
1564
- assert_in_delta(0.3, method.children_time, 0.05)
1565
-
1566
- method = methods[1]
1567
- assert_equal('RubyProf::M1#busy_wait', method.full_name)
1568
- assert_in_delta(0.3, method.total_time, 0.05)
1569
- assert_in_delta(0.0, method.wait_time, 0.05)
1570
- assert_in_delta(0.15, method.self_time, 0.05)
1571
- assert_in_delta(0.15, method.children_time, 0.05)
1572
-
1573
- method = methods[2]
1574
- assert_equal('<Module::Process>#clock_gettime', method.full_name)
1575
- assert_in_delta(0.05, method.total_time, 0.05)
1576
- assert_in_delta(0.0, method.wait_time, 0.05)
1577
- assert_in_delta(0.05, method.self_time, 0.05)
1578
- assert_in_delta(0.0, method.children_time, 0.05)
1579
-
1580
- method = methods[3]
1581
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1582
- assert_in_delta(0.0, method.total_time, 0.05)
1583
- assert_in_delta(0.0, method.wait_time, 0.05)
1584
- assert_in_delta(0.0, method.self_time, 0.05)
1585
- assert_in_delta(0.0, method.children_time, 0.05)
1586
-
1587
- method = methods[4]
1588
- assert_includes(['Float#<', 'Float#-'], method.full_name)
1589
- assert_in_delta(0.0, method.total_time, 0.05)
1590
- assert_in_delta(0.0, method.wait_time, 0.05)
1591
- assert_in_delta(0.0, method.self_time, 0.05)
1592
- assert_in_delta(0.0, method.children_time, 0.05)
1593
-
1594
- method = methods[5]
1595
- assert_equal('Class#new', method.full_name)
1596
- assert_in_delta(0.0, method.total_time, 0.05)
1597
- assert_in_delta(0.0, method.wait_time, 0.05)
1598
- assert_in_delta(0.0, method.self_time, 0.05)
1599
- assert_in_delta(0.0, method.children_time, 0.05)
1600
-
1601
- method = methods[6]
1602
- assert_equal('BasicObject#initialize', method.full_name)
1603
- assert_in_delta(0.0, method.total_time, 0.05)
1604
- assert_in_delta(0.0, method.wait_time, 0.05)
1605
- assert_in_delta(0.0, method.self_time, 0.05)
1606
- assert_in_delta(0.0, method.children_time, 0.05)
1607
- end
1608
- end
1609
- end
1610
- 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
+ super
10
+ GC.start
11
+ end
12
+
13
+ # These tests run to fast for Windows to detect any used process time
14
+ if !windows?
15
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
16
+ def test_class_methods_sleep
17
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
18
+ RubyProf::C1.sleep_wait
19
+ end
20
+
21
+ thread = result.threads.first
22
+ assert_in_delta(0.0, thread.total_time, 0.05)
23
+
24
+ methods = result.threads.first.methods.sort.reverse
25
+ assert_equal(3, methods.length)
26
+
27
+ # Check times
28
+ method = methods[0]
29
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
30
+ assert_in_delta(0.0, method.total_time, 0.05)
31
+ assert_in_delta(0.0, method.wait_time, 0.05)
32
+ assert_in_delta(0.0, method.self_time, 0.05)
33
+ assert_in_delta(0.0, method.children_time, 0.05)
34
+
35
+ method = methods[1]
36
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
37
+ assert_in_delta(0.0, method.total_time, 0.05)
38
+ assert_in_delta(0.0, method.wait_time, 0.05)
39
+ assert_in_delta(0.0, method.self_time, 0.05)
40
+ assert_in_delta(0.0, method.children_time, 0.05)
41
+
42
+ method = methods[2]
43
+ assert_equal('Kernel#sleep', method.full_name)
44
+ assert_in_delta(0.0, method.total_time, 0.05)
45
+ assert_in_delta(0.0, method.wait_time, 0.05)
46
+ assert_in_delta(0.0, method.self_time, 0.05)
47
+ assert_in_delta(0.0, method.children_time, 0.05)
48
+ end
49
+
50
+ def test_class_methods_sleep_threaded
51
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
52
+ background_thread = Thread.new do
53
+ RubyProf::C1.sleep_wait
54
+ end
55
+ background_thread.join
56
+ end
57
+
58
+ assert_equal(2, result.threads.count)
59
+
60
+ thread = result.threads.first
61
+ assert_in_delta(0.0, thread.total_time, 0.05)
62
+
63
+ methods = result.threads.first.methods.sort.reverse
64
+ assert_equal(4, methods.length)
65
+
66
+ # Check times
67
+ method = methods[0]
68
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
69
+ assert_in_delta(0.0, method.total_time, 0.05)
70
+ assert_in_delta(0.0, method.wait_time, 0.05)
71
+ assert_in_delta(0.0, method.self_time, 0.05)
72
+ assert_in_delta(0.0, method.children_time, 0.05)
73
+
74
+ method = methods[1]
75
+ assert_equal('Thread#join', method.full_name)
76
+ assert_in_delta(0.0, method.total_time, 0.05)
77
+ assert_in_delta(0.0, method.wait_time, 0.05)
78
+ assert_in_delta(0.0, method.self_time, 0.05)
79
+ assert_in_delta(0.0, method.children_time, 0.05)
80
+
81
+ method = methods[2]
82
+ assert_equal('<Class::Thread>#new', method.full_name)
83
+ assert_in_delta(0.0, method.total_time, 0.05)
84
+ assert_in_delta(0.0, method.wait_time, 0.05)
85
+ assert_in_delta(0.0, method.self_time, 0.05)
86
+ assert_in_delta(0.0, method.children_time, 0.05)
87
+
88
+ method = methods[3]
89
+ assert_equal('Thread#initialize', method.full_name)
90
+ assert_in_delta(0.0, method.total_time, 0.05)
91
+ assert_in_delta(0.0, method.wait_time, 0.05)
92
+ assert_in_delta(0.0, method.self_time, 0.05)
93
+ assert_in_delta(0.0, method.children_time, 0.05)
94
+
95
+ thread = result.threads.last
96
+ assert_in_delta(0.0, thread.total_time, 0.05)
97
+
98
+ methods = result.threads.first.methods.sort.reverse
99
+ assert_equal(4, methods.length)
100
+
101
+ methods = result.threads.last.methods.sort.reverse
102
+ assert_equal(3, methods.length)
103
+
104
+ # Check times
105
+ method = methods[0]
106
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
107
+ assert_in_delta(0.0, method.total_time, 0.05)
108
+ assert_in_delta(0.0, method.wait_time, 0.05)
109
+ assert_in_delta(0.0, method.self_time, 0.05)
110
+ assert_in_delta(0.0, method.children_time, 0.05)
111
+
112
+ method = methods[1]
113
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
114
+ assert_in_delta(0.0, method.total_time, 0.05)
115
+ assert_in_delta(0.0, method.wait_time, 0.05)
116
+ assert_in_delta(0.0, method.self_time, 0.05)
117
+ assert_in_delta(0.0, method.children_time, 0.05)
118
+
119
+ method = methods[2]
120
+ assert_equal('Kernel#sleep', 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
+ end
126
+
127
+ def test_class_methods_busy
128
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
129
+ RubyProf::C1.busy_wait
130
+ end
131
+
132
+ thread = result.threads.first
133
+ assert_in_delta(0.08, thread.total_time, 0.05)
134
+
135
+ methods = result.threads.first.methods.sort.reverse
136
+ assert_equal(3, methods.length)
137
+
138
+ # Check times
139
+ method = methods[0]
140
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
141
+ assert_in_delta(0.1, method.total_time, 0.05)
142
+ assert_in_delta(0.0, method.wait_time, 0.05)
143
+ assert_in_delta(0.0, method.self_time, 0.05)
144
+ assert_in_delta(0.1, method.children_time, 0.05)
145
+
146
+ method = methods[1]
147
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
148
+ assert_in_delta(0.1, method.total_time, 0.05)
149
+ assert_in_delta(0.0, method.wait_time, 0.05)
150
+ assert_in_delta(0.06, method.self_time, 0.05)
151
+ assert_in_delta(0.07, method.children_time, 0.05)
152
+
153
+ method = methods[2]
154
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
155
+ assert_in_delta(0.05, method.total_time, 0.05)
156
+ assert_in_delta(0.0, method.wait_time, 0.05)
157
+ assert_in_delta(0.05, method.self_time, 0.05)
158
+ assert_in_delta(0.0, method.children_time, 0.05)
159
+ end
160
+
161
+ def test_class_methods_busy_threaded
162
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
163
+ background_thread = Thread.new do
164
+ RubyProf::C1.busy_wait
165
+ end
166
+ background_thread.join
167
+ end
168
+
169
+ assert_equal(2, result.threads.count)
170
+
171
+ thread = result.threads.first
172
+ assert_in_delta(0.1, thread.total_time, 0.05)
173
+
174
+ methods = result.threads.first.methods.sort.reverse
175
+ assert_equal(4, methods.length)
176
+
177
+ # Check times
178
+ method = methods[0]
179
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
180
+ assert_in_delta(0.1, method.total_time, 0.05)
181
+ assert_in_delta(0.0, method.wait_time, 0.05)
182
+ assert_in_delta(0.0, method.self_time, 0.05)
183
+ assert_in_delta(0.1, method.children_time, 0.05)
184
+
185
+ method = methods[1]
186
+ assert_equal('Thread#join', method.full_name)
187
+ assert_in_delta(0.1, method.total_time, 0.05)
188
+ assert_in_delta(0.1, method.wait_time, 0.05)
189
+ assert_in_delta(0.0, method.self_time, 0.05)
190
+ assert_in_delta(0.0, method.children_time, 0.05)
191
+
192
+ method = methods[2]
193
+ assert_equal('<Class::Thread>#new', method.full_name)
194
+ assert_in_delta(0.0, method.total_time, 0.05)
195
+ assert_in_delta(0.0, method.wait_time, 0.05)
196
+ assert_in_delta(0.0, method.self_time, 0.05)
197
+ assert_in_delta(0.0, method.children_time, 0.05)
198
+
199
+ method = methods[3]
200
+ assert_equal('Thread#initialize', method.full_name)
201
+ assert_in_delta(0.0, method.total_time, 0.05)
202
+ assert_in_delta(0.0, method.wait_time, 0.05)
203
+ assert_in_delta(0.0, method.self_time, 0.05)
204
+ assert_in_delta(0.0, method.children_time, 0.05)
205
+
206
+ thread = result.threads.last
207
+ assert_in_delta(0.1, thread.total_time, 0.05)
208
+
209
+ methods = result.threads.first.methods.sort.reverse
210
+ assert_equal(4, methods.length)
211
+
212
+ methods = result.threads.last.methods.sort.reverse
213
+ assert_equal(3, methods.length)
214
+
215
+ # Check times
216
+ method = methods[0]
217
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
218
+ assert_in_delta(0.1, method.total_time, 0.05)
219
+ assert_in_delta(0.0, method.wait_time, 0.05)
220
+ assert_in_delta(0.0, method.self_time, 0.05)
221
+ assert_in_delta(0.1, method.children_time, 0.05)
222
+
223
+ method = methods[1]
224
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
225
+ assert_in_delta(0.1, method.total_time, 0.05)
226
+ assert_in_delta(0.0, method.wait_time, 0.05)
227
+ assert_in_delta(0.05, method.self_time, 0.05)
228
+ assert_in_delta(0.05, method.children_time, 0.05)
229
+
230
+ method = methods[2]
231
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
232
+ assert_in_delta(0.05, method.total_time, 0.05)
233
+ assert_in_delta(0.0, method.wait_time, 0.05)
234
+ assert_in_delta(0.05, method.self_time, 0.05)
235
+ assert_in_delta(0.0, method.children_time, 0.05)
236
+ end
237
+
238
+ def test_instance_methods_sleep
239
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
240
+ RubyProf::C1.new.sleep_wait
241
+ end
242
+
243
+ thread = result.threads.first
244
+ assert_in_delta(0.0, thread.total_time, 0.05)
245
+
246
+ methods = result.threads.first.methods.sort.reverse
247
+ assert_equal(5, methods.length)
248
+
249
+ # Check times
250
+ method = methods[0]
251
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
252
+ assert_in_delta(0.0, method.total_time, 0.05)
253
+ assert_in_delta(0.0, method.wait_time, 0.05)
254
+ assert_in_delta(0.0, method.self_time, 0.05)
255
+ assert_in_delta(0.0, method.children_time, 0.05)
256
+
257
+ method = methods[1]
258
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
259
+ assert_in_delta(0.0, method.total_time, 0.05)
260
+ assert_in_delta(0.0, method.wait_time, 0.05)
261
+ assert_in_delta(0.0, method.self_time, 0.05)
262
+ assert_in_delta(0.0, method.children_time, 0.05)
263
+
264
+ method = methods[2]
265
+ assert_equal('Class#new', method.full_name)
266
+ assert_in_delta(0.0, method.total_time, 0.05)
267
+ assert_in_delta(0.0, method.wait_time, 0.05)
268
+ assert_in_delta(0.0, method.self_time, 0.05)
269
+ assert_in_delta(0.0, method.children_time, 0.05)
270
+
271
+ method = methods[3]
272
+ assert_equal('Kernel#sleep', method.full_name)
273
+ assert_in_delta(0.0, method.total_time, 0.05)
274
+ assert_in_delta(0.0, method.wait_time, 0.05)
275
+ assert_in_delta(0.0, method.self_time, 0.05)
276
+ assert_in_delta(0.0, method.children_time, 0.05)
277
+
278
+ method = methods[4]
279
+ assert_equal('BasicObject#initialize', method.full_name)
280
+ assert_in_delta(0.0, method.total_time, 0.05)
281
+ assert_in_delta(0.0, method.wait_time, 0.05)
282
+ assert_in_delta(0.0, method.self_time, 0.05)
283
+ assert_in_delta(0.0, method.children_time, 0.05)
284
+ end
285
+
286
+ def test_instance_methods_sleep_block
287
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
288
+ 1.times { RubyProf::C1.new.sleep_wait }
289
+ end
290
+
291
+ methods = result.threads.first.methods.sort.reverse
292
+ assert_equal(6, methods.length)
293
+
294
+ # Check times
295
+ method = methods[0]
296
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
297
+ assert_in_delta(0.0, method.total_time, 0.05)
298
+ assert_in_delta(0.0, method.wait_time, 0.05)
299
+ assert_in_delta(0.0, method.self_time, 0.05)
300
+ assert_in_delta(0.0, method.children_time, 0.05)
301
+
302
+ method = methods[1]
303
+ assert_equal('Integer#times', method.full_name)
304
+ assert_in_delta(0.0, method.total_time, 0.05)
305
+ assert_in_delta(0.0, method.wait_time, 0.05)
306
+ assert_in_delta(0.0, method.self_time, 0.05)
307
+ assert_in_delta(0.0, method.children_time, 0.05)
308
+
309
+ method = methods[2]
310
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
311
+ assert_in_delta(0.0, method.total_time, 0.05)
312
+ assert_in_delta(0.0, method.wait_time, 0.05)
313
+ assert_in_delta(0.0, method.self_time, 0.05)
314
+ assert_in_delta(0.0, method.children_time, 0.05)
315
+
316
+ method = methods[3]
317
+ assert_equal('Class#new', method.full_name)
318
+ assert_in_delta(0.0, method.total_time, 0.05)
319
+ assert_in_delta(0.0, method.wait_time, 0.05)
320
+ assert_in_delta(0.0, method.self_time, 0.05)
321
+ assert_in_delta(0.0, method.children_time, 0.05)
322
+
323
+ method = methods[4]
324
+ assert_equal('Kernel#sleep', method.full_name)
325
+ assert_in_delta(0.0, method.total_time, 0.05)
326
+ assert_in_delta(0.0, method.wait_time, 0.05)
327
+ assert_in_delta(0.0, method.self_time, 0.05)
328
+ assert_in_delta(0.0, method.children_time, 0.05)
329
+
330
+ method = methods[5]
331
+ assert_equal('BasicObject#initialize', method.full_name)
332
+ assert_in_delta(0.0, method.total_time, 0.05)
333
+ assert_in_delta(0.0, method.wait_time, 0.05)
334
+ assert_in_delta(0.0, method.self_time, 0.05)
335
+ assert_in_delta(0.0, method.children_time, 0.05)
336
+ end
337
+
338
+ def test_instance_methods_sleep_threaded
339
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
340
+ background_thread = Thread.new do
341
+ RubyProf::C1.new.sleep_wait
342
+ end
343
+ background_thread.join
344
+ end
345
+
346
+ assert_equal(2, result.threads.count)
347
+
348
+ thread = result.threads.first
349
+ assert_in_delta(0.0, thread.total_time, 0.05)
350
+
351
+ methods = result.threads.first.methods.sort.reverse
352
+ assert_equal(4, methods.length)
353
+
354
+ # Check times
355
+ method = methods[0]
356
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
357
+ assert_in_delta(0.0, method.total_time, 0.05)
358
+ assert_in_delta(0.0, method.wait_time, 0.05)
359
+ assert_in_delta(0.0, method.self_time, 0.05)
360
+ assert_in_delta(0.0, method.children_time, 0.05)
361
+
362
+ method = methods[1]
363
+ assert_equal('Thread#join', method.full_name)
364
+ assert_in_delta(0.0, method.total_time, 0.05)
365
+ assert_in_delta(0.0, method.wait_time, 0.05)
366
+ assert_in_delta(0.0, method.self_time, 0.05)
367
+ assert_in_delta(0.0, method.children_time, 0.05)
368
+
369
+ method = methods[2]
370
+ assert_equal('<Class::Thread>#new', method.full_name)
371
+ assert_in_delta(0.0, method.total_time, 0.05)
372
+ assert_in_delta(0.0, method.wait_time, 0.05)
373
+ assert_in_delta(0.0, method.self_time, 0.05)
374
+ assert_in_delta(0.0, method.children_time, 0.05)
375
+
376
+ method = methods[3]
377
+ assert_equal('Thread#initialize', method.full_name)
378
+ assert_in_delta(0.0, method.total_time, 0.05)
379
+ assert_in_delta(0.0, method.wait_time, 0.05)
380
+ assert_in_delta(0.0, method.self_time, 0.05)
381
+ assert_in_delta(0.0, method.children_time, 0.05)
382
+
383
+ thread = result.threads.last
384
+ assert_in_delta(0.0, thread.total_time, 0.05)
385
+
386
+ methods = result.threads.first.methods.sort.reverse
387
+ assert_equal(4, methods.length)
388
+
389
+ methods = result.threads.last.methods.sort.reverse
390
+ assert_equal(5, methods.length)
391
+
392
+ # Check times
393
+ method = methods[0]
394
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
395
+ assert_in_delta(0.0, method.total_time, 0.05)
396
+ assert_in_delta(0.0, method.wait_time, 0.05)
397
+ assert_in_delta(0.0, method.self_time, 0.05)
398
+ assert_in_delta(0.0, method.children_time, 0.05)
399
+
400
+ method = methods[1]
401
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
402
+ assert_in_delta(0.0, method.total_time, 0.05)
403
+ assert_in_delta(0.0, method.wait_time, 0.05)
404
+ assert_in_delta(0.0, method.self_time, 0.05)
405
+ assert_in_delta(0.0, method.children_time, 0.05)
406
+
407
+ method = methods[2]
408
+ assert_equal('Class#new', method.full_name)
409
+ assert_in_delta(0.0, method.total_time, 0.05)
410
+ assert_in_delta(0.0, method.wait_time, 0.05)
411
+ assert_in_delta(0.0, method.self_time, 0.05)
412
+ assert_in_delta(0.0, method.children_time, 0.05)
413
+
414
+ method = methods[3]
415
+ assert_equal('Kernel#sleep', method.full_name)
416
+ assert_in_delta(0.0, method.total_time, 0.05)
417
+ assert_in_delta(0.0, method.wait_time, 0.05)
418
+ assert_in_delta(0.0, method.self_time, 0.05)
419
+ assert_in_delta(0.0, method.children_time, 0.05)
420
+
421
+ method = methods[4]
422
+ assert_equal('BasicObject#initialize', method.full_name)
423
+ assert_in_delta(0.0, method.total_time, 0.05)
424
+ assert_in_delta(0.0, method.wait_time, 0.05)
425
+ assert_in_delta(0.0, method.self_time, 0.05)
426
+ assert_in_delta(0.0, method.children_time, 0.05)
427
+ end
428
+
429
+ def test_instance_methods_busy
430
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
431
+ RubyProf::C1.new.busy_wait
432
+ end
433
+
434
+ thread = result.threads.first
435
+ assert_in_delta(0.2, thread.total_time, 0.05)
436
+
437
+ methods = result.threads.first.methods.sort.reverse
438
+ assert_equal(5, methods.length)
439
+
440
+ # Check times
441
+ method = methods[0]
442
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
443
+ assert_in_delta(0.2, method.total_time, 0.05)
444
+ assert_in_delta(0.0, method.wait_time, 0.05)
445
+ assert_in_delta(0.0, method.self_time, 0.05)
446
+ assert_in_delta(0.2, method.children_time, 0.05)
447
+
448
+ method = methods[1]
449
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
450
+ assert_in_delta(0.2, method.total_time, 0.05)
451
+ assert_in_delta(0.0, method.wait_time, 0.05)
452
+ assert_in_delta(0.09, method.self_time, 0.05)
453
+ assert_in_delta(0.11, method.children_time, 0.05)
454
+
455
+ method = methods[2]
456
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
457
+ assert_in_delta(0.11, method.total_time, 0.05)
458
+ assert_in_delta(0.0, method.wait_time, 0.05)
459
+ assert_in_delta(0.11, method.self_time, 0.05)
460
+ assert_in_delta(0.0, method.children_time, 0.05)
461
+
462
+ method = methods[3]
463
+ assert_equal('Class#new', method.full_name)
464
+ assert_in_delta(0.0, method.total_time, 0.05)
465
+ assert_in_delta(0.0, method.wait_time, 0.05)
466
+ assert_in_delta(0.0, method.self_time, 0.05)
467
+ assert_in_delta(0.0, method.children_time, 0.05)
468
+
469
+ method = methods[4]
470
+ assert_equal('BasicObject#initialize', method.full_name)
471
+ assert_in_delta(0.0, method.total_time, 0.05)
472
+ assert_in_delta(0.0, method.wait_time, 0.05)
473
+ assert_in_delta(0.0, method.self_time, 0.05)
474
+ assert_in_delta(0.0, method.children_time, 0.05)
475
+ end
476
+
477
+ def test_instance_methods_busy_block
478
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
479
+ 1.times { RubyProf::C1.new.busy_wait }
480
+ end
481
+
482
+ methods = result.threads.first.methods.sort.reverse
483
+ assert_equal(6, methods.length)
484
+
485
+ # Check times
486
+ method = methods[0]
487
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
488
+ assert_in_delta(0.2, method.total_time, 0.05)
489
+ assert_in_delta(0.0, method.wait_time, 0.05)
490
+ assert_in_delta(0.0, method.self_time, 0.05)
491
+ assert_in_delta(0.2, method.children_time, 0.05)
492
+
493
+ method = methods[1]
494
+ assert_equal('Integer#times', method.full_name)
495
+ assert_in_delta(0.2, method.total_time, 0.05)
496
+ assert_in_delta(0.0, method.wait_time, 0.05)
497
+ assert_in_delta(0.0, method.self_time, 0.05)
498
+ assert_in_delta(0.2, method.children_time, 0.05)
499
+
500
+ method = methods[2]
501
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
502
+ assert_in_delta(0.2, method.total_time, 0.05)
503
+ assert_in_delta(0.0, method.wait_time, 0.05)
504
+ assert_in_delta(0.09, method.self_time, 0.05)
505
+ assert_in_delta(0.11, method.children_time, 0.05)
506
+
507
+ method = methods[3]
508
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
509
+ assert_in_delta(0.11, method.total_time, 0.05)
510
+ assert_in_delta(0.0, method.wait_time, 0.05)
511
+ assert_in_delta(0.11, method.self_time, 0.05)
512
+ assert_in_delta(0.0, method.children_time, 0.05)
513
+
514
+ method = methods[4]
515
+ assert_equal('Class#new', method.full_name)
516
+ assert_in_delta(0.0, method.total_time, 0.05)
517
+ assert_in_delta(0.0, method.wait_time, 0.05)
518
+ assert_in_delta(0.0, method.self_time, 0.05)
519
+ assert_in_delta(0.0, method.children_time, 0.05)
520
+
521
+ method = methods[5]
522
+ assert_equal('BasicObject#initialize', method.full_name)
523
+ assert_in_delta(0.0, method.total_time, 0.05)
524
+ assert_in_delta(0.0, method.wait_time, 0.05)
525
+ assert_in_delta(0.0, method.self_time, 0.05)
526
+ assert_in_delta(0.0, method.children_time, 0.05)
527
+ end
528
+
529
+ def test_instance_methods_busy_threaded
530
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
531
+ background_thread = Thread.new do
532
+ RubyProf::C1.new.busy_wait
533
+ end
534
+ background_thread.join
535
+ end
536
+
537
+ assert_equal(2, result.threads.count)
538
+
539
+ thread = result.threads.first
540
+ assert_in_delta(0.2, thread.total_time, 0.05)
541
+
542
+ methods = result.threads.first.methods.sort.reverse
543
+ assert_equal(4, methods.length)
544
+
545
+ # Check times
546
+ method = methods[0]
547
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
548
+ assert_in_delta(0.2, method.total_time, 0.05)
549
+ assert_in_delta(0.0, method.wait_time, 0.05)
550
+ assert_in_delta(0.0, method.self_time, 0.05)
551
+ assert_in_delta(0.2, method.children_time, 0.05)
552
+
553
+ method = methods[1]
554
+ assert_equal('Thread#join', method.full_name)
555
+ assert_in_delta(0.2, method.total_time, 0.05)
556
+ assert_in_delta(0.2, method.wait_time, 0.05)
557
+ assert_in_delta(0.0, method.self_time, 0.05)
558
+ assert_in_delta(0.0, method.children_time, 0.05)
559
+
560
+ method = methods[2]
561
+ assert_equal('<Class::Thread>#new', method.full_name)
562
+ assert_in_delta(0.0, method.total_time, 0.05)
563
+ assert_in_delta(0.0, method.wait_time, 0.05)
564
+ assert_in_delta(0.0, method.self_time, 0.05)
565
+ assert_in_delta(0.0, method.children_time, 0.05)
566
+
567
+ method = methods[3]
568
+ assert_equal('Thread#initialize', method.full_name)
569
+ assert_in_delta(0.0, method.total_time, 0.05)
570
+ assert_in_delta(0.0, method.wait_time, 0.05)
571
+ assert_in_delta(0.0, method.self_time, 0.05)
572
+ assert_in_delta(0.0, method.children_time, 0.05)
573
+
574
+ thread = result.threads.last
575
+ assert_in_delta(0.2, thread.total_time, 0.05)
576
+
577
+ methods = result.threads.first.methods.sort.reverse
578
+ assert_equal(4, methods.length)
579
+
580
+ methods = result.threads.last.methods.sort.reverse
581
+ assert_equal(5, methods.length)
582
+
583
+ # Check times
584
+ method = methods[0]
585
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
586
+ assert_in_delta(0.2, method.total_time, 0.05)
587
+ assert_in_delta(0.0, method.wait_time, 0.05)
588
+ assert_in_delta(0.0, method.self_time, 0.05)
589
+ assert_in_delta(0.2, method.children_time, 0.05)
590
+
591
+ method = methods[1]
592
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
593
+ assert_in_delta(0.2, method.total_time, 0.05)
594
+ assert_in_delta(0.0, method.wait_time, 0.05)
595
+ assert_in_delta(0.1, method.self_time, 0.05)
596
+ assert_in_delta(0.1, method.children_time, 0.05)
597
+
598
+ method = methods[2]
599
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
600
+ assert_in_delta(0.1, method.total_time, 0.05)
601
+ assert_in_delta(0.0, method.wait_time, 0.05)
602
+ assert_in_delta(0.1, method.self_time, 0.05)
603
+ assert_in_delta(0.0, method.children_time, 0.05)
604
+
605
+ method = methods[3]
606
+ assert_equal('Class#new', method.full_name)
607
+ assert_in_delta(0.0, method.total_time, 0.05)
608
+ assert_in_delta(0.0, method.wait_time, 0.05)
609
+ assert_in_delta(0.0, method.self_time, 0.05)
610
+ assert_in_delta(0.0, method.children_time, 0.05)
611
+
612
+ method = methods[4]
613
+ assert_equal('BasicObject#initialize', method.full_name)
614
+ assert_in_delta(0.0, method.total_time, 0.05)
615
+ assert_in_delta(0.0, method.wait_time, 0.05)
616
+ assert_in_delta(0.0, method.self_time, 0.05)
617
+ assert_in_delta(0.0, method.children_time, 0.05)
618
+ end
619
+
620
+ def test_module_methods_sleep
621
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
622
+ RubyProf::C2.sleep_wait
623
+ end
624
+
625
+ thread = result.threads.first
626
+ assert_in_delta(0.0, thread.total_time, 0.05)
627
+
628
+ methods = result.threads.first.methods.sort.reverse
629
+ assert_equal(3, methods.length)
630
+
631
+ # Check times
632
+ method = methods[0]
633
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
634
+ assert_in_delta(0.0, method.total_time, 0.05)
635
+ assert_in_delta(0.0, method.wait_time, 0.05)
636
+ assert_in_delta(0.0, method.self_time, 0.05)
637
+ assert_in_delta(0.0, method.children_time, 0.05)
638
+
639
+ method = methods[1]
640
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
641
+ assert_in_delta(0.0, method.total_time, 0.05)
642
+ assert_in_delta(0.0, method.wait_time, 0.05)
643
+ assert_in_delta(0.0, method.self_time, 0.05)
644
+ assert_in_delta(0.0, method.children_time, 0.05)
645
+
646
+ method = methods[2]
647
+ assert_equal('Kernel#sleep', method.full_name)
648
+ assert_in_delta(0.0, method.total_time, 0.05)
649
+ assert_in_delta(0.0, method.wait_time, 0.05)
650
+ assert_in_delta(0.0, method.self_time, 0.05)
651
+ assert_in_delta(0.0, method.children_time, 0.05)
652
+ end
653
+
654
+ def test_module_methods_busy
655
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
656
+ RubyProf::C2.busy_wait
657
+ end
658
+
659
+ thread = result.threads.first
660
+ assert_in_delta(0.3, thread.total_time, 0.05)
661
+
662
+ methods = result.threads.first.methods.sort.reverse
663
+ assert_equal(3, methods.length)
664
+
665
+ # Check times
666
+ method = methods[0]
667
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
668
+ assert_in_delta(0.3, method.total_time, 0.05)
669
+ assert_in_delta(0.0, method.wait_time, 0.05)
670
+ assert_in_delta(0.0, method.self_time, 0.05)
671
+ assert_in_delta(0.3, method.children_time, 0.05)
672
+
673
+ method = methods[1]
674
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
675
+ assert_in_delta(0.3, method.total_time, 0.05)
676
+ assert_in_delta(0.0, method.wait_time, 0.05)
677
+ assert_in_delta(0.15, method.self_time, 0.05)
678
+ assert_in_delta(0.15, method.children_time, 0.05)
679
+
680
+ method = methods[2]
681
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
682
+ assert_in_delta(0.15, method.total_time, 0.05)
683
+ assert_in_delta(0.0, method.wait_time, 0.05)
684
+ assert_in_delta(0.15, method.self_time, 0.05)
685
+ assert_in_delta(0.0, method.children_time, 0.05)
686
+ end
687
+
688
+ def test_module_instance_methods_sleep
689
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
690
+ RubyProf::C2.new.sleep_wait
691
+ end
692
+
693
+ thread = result.threads.first
694
+ assert_in_delta(0.0, thread.total_time, 0.05)
695
+
696
+ methods = result.threads.first.methods.sort.reverse
697
+ assert_equal(5, methods.length)
698
+
699
+ # Check times
700
+ method = methods[0]
701
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_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
+
707
+ method = methods[1]
708
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
709
+ assert_in_delta(0.0, method.total_time, 0.05)
710
+ assert_in_delta(0.0, method.wait_time, 0.05)
711
+ assert_in_delta(0.0, method.self_time, 0.05)
712
+ assert_in_delta(0.0, method.children_time, 0.05)
713
+
714
+ method = methods[2]
715
+ assert_equal('Class#new', method.full_name)
716
+ assert_in_delta(0.0, method.total_time, 0.05)
717
+ assert_in_delta(0.0, method.wait_time, 0.05)
718
+ assert_in_delta(0.0, method.self_time, 0.05)
719
+ assert_in_delta(0.0, method.children_time, 0.05)
720
+
721
+ method = methods[3]
722
+ assert_equal('Kernel#sleep', method.full_name)
723
+ assert_in_delta(0.0, method.total_time, 0.05)
724
+ assert_in_delta(0.0, method.wait_time, 0.05)
725
+ assert_in_delta(0.0, method.self_time, 0.05)
726
+ assert_in_delta(0.0, method.children_time, 0.05)
727
+
728
+ method = methods[4]
729
+ assert_equal('BasicObject#initialize', method.full_name)
730
+ assert_in_delta(0.0, method.total_time, 0.05)
731
+ assert_in_delta(0.0, method.wait_time, 0.05)
732
+ assert_in_delta(0.0, method.self_time, 0.05)
733
+ assert_in_delta(0.0, method.children_time, 0.05)
734
+ end
735
+
736
+ def test_module_instance_methods_busy
737
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
738
+ RubyProf::C2.new.busy_wait
739
+ end
740
+
741
+ thread = result.threads.first
742
+ assert_in_delta(0.3, thread.total_time, 0.05)
743
+
744
+ methods = result.threads.first.methods.sort.reverse
745
+ assert_equal(5, methods.length)
746
+
747
+ # Check times
748
+ method = methods[0]
749
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
750
+ assert_in_delta(0.3, method.total_time, 0.05)
751
+ assert_in_delta(0.0, method.wait_time, 0.05)
752
+ assert_in_delta(0.0, method.self_time, 0.05)
753
+ assert_in_delta(0.3, method.children_time, 0.05)
754
+
755
+ method = methods[1]
756
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
757
+ assert_in_delta(0.3, method.total_time, 0.05)
758
+ assert_in_delta(0.0, method.wait_time, 0.05)
759
+ assert_in_delta(0.15, method.self_time, 0.05)
760
+ assert_in_delta(0.15, method.children_time, 0.05)
761
+
762
+ method = methods[2]
763
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
764
+ assert_in_delta(0.15, method.total_time, 0.05)
765
+ assert_in_delta(0.0, method.wait_time, 0.05)
766
+ assert_in_delta(0.15, method.self_time, 0.05)
767
+ assert_in_delta(0.0, method.children_time, 0.05)
768
+
769
+ method = methods[3]
770
+ assert_equal('Class#new', 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[4]
777
+ assert_equal('BasicObject#initialize', 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
+ end
783
+ elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.3')
784
+ def test_class_methods_sleep
785
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
786
+ RubyProf::C1.sleep_wait
787
+ end
788
+
789
+ thread = result.threads.first
790
+ assert_in_delta(0.0, thread.total_time, 0.05)
791
+
792
+ methods = result.threads.first.methods.sort.reverse
793
+ assert_equal(3, methods.length)
794
+
795
+ # Check times
796
+ method = methods[0]
797
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
798
+ assert_in_delta(0.0, method.total_time, 0.05)
799
+ assert_in_delta(0.0, method.wait_time, 0.05)
800
+ assert_in_delta(0.0, method.self_time, 0.05)
801
+ assert_in_delta(0.0, method.children_time, 0.05)
802
+
803
+ method = methods[1]
804
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
805
+ assert_in_delta(0.0, method.total_time, 0.05)
806
+ assert_in_delta(0.0, method.wait_time, 0.05)
807
+ assert_in_delta(0.0, method.self_time, 0.05)
808
+ assert_in_delta(0.0, method.children_time, 0.05)
809
+
810
+ method = methods[2]
811
+ assert_equal('Kernel#sleep', method.full_name)
812
+ assert_in_delta(0.0, method.total_time, 0.05)
813
+ assert_in_delta(0.0, method.wait_time, 0.05)
814
+ assert_in_delta(0.0, method.self_time, 0.05)
815
+ assert_in_delta(0.0, method.children_time, 0.05)
816
+ end
817
+
818
+ def test_class_methods_sleep_threaded
819
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
820
+ background_thread = Thread.new do
821
+ RubyProf::C1.sleep_wait
822
+ end
823
+ background_thread.join
824
+ end
825
+
826
+ assert_equal(2, result.threads.count)
827
+
828
+ thread = result.threads.first
829
+ assert_in_delta(0.0, thread.total_time, 0.05)
830
+
831
+ methods = result.threads.first.methods.sort.reverse
832
+ assert_equal(4, methods.length)
833
+
834
+ # Check times
835
+ method = methods[0]
836
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', 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[1]
843
+ assert_equal('Thread#join', 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
+
849
+ method = methods[2]
850
+ assert_equal('<Class::Thread>#new', method.full_name)
851
+ assert_in_delta(0.0, method.total_time, 0.05)
852
+ assert_in_delta(0.0, method.wait_time, 0.05)
853
+ assert_in_delta(0.0, method.self_time, 0.05)
854
+ assert_in_delta(0.0, method.children_time, 0.05)
855
+
856
+ method = methods[3]
857
+ assert_equal('Thread#initialize', method.full_name)
858
+ assert_in_delta(0.0, method.total_time, 0.05)
859
+ assert_in_delta(0.0, method.wait_time, 0.05)
860
+ assert_in_delta(0.0, method.self_time, 0.05)
861
+ assert_in_delta(0.0, method.children_time, 0.05)
862
+
863
+ thread = result.threads.last
864
+ assert_in_delta(0.0, thread.total_time, 0.05)
865
+
866
+ methods = result.threads.first.methods.sort.reverse
867
+ assert_equal(4, methods.length)
868
+
869
+ methods = result.threads.last.methods.sort.reverse
870
+ assert_equal(3, methods.length)
871
+
872
+ # Check times
873
+ method = methods[0]
874
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
875
+ assert_in_delta(0.0, method.total_time, 0.05)
876
+ assert_in_delta(0.0, method.wait_time, 0.05)
877
+ assert_in_delta(0.0, method.self_time, 0.05)
878
+ assert_in_delta(0.0, method.children_time, 0.05)
879
+
880
+ method = methods[1]
881
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
882
+ assert_in_delta(0.0, method.total_time, 0.05)
883
+ assert_in_delta(0.0, method.wait_time, 0.05)
884
+ assert_in_delta(0.0, method.self_time, 0.05)
885
+ assert_in_delta(0.0, method.children_time, 0.05)
886
+
887
+ method = methods[2]
888
+ assert_equal('Kernel#sleep', method.full_name)
889
+ assert_in_delta(0.0, method.total_time, 0.05)
890
+ assert_in_delta(0.0, method.wait_time, 0.05)
891
+ assert_in_delta(0.0, method.self_time, 0.05)
892
+ assert_in_delta(0.0, method.children_time, 0.05)
893
+ end
894
+
895
+ def test_class_methods_busy
896
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
897
+ RubyProf::C1.busy_wait
898
+ end
899
+
900
+ thread = result.threads.first
901
+ assert_in_delta(0.08, thread.total_time, 0.05)
902
+
903
+ methods = result.threads.first.methods.sort.reverse
904
+ assert_equal(5, methods.length)
905
+
906
+ # Check times
907
+ method = methods[0]
908
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
909
+ assert_in_delta(0.1, method.total_time, 0.05)
910
+ assert_in_delta(0.0, method.wait_time, 0.05)
911
+ assert_in_delta(0.0, method.self_time, 0.05)
912
+ assert_in_delta(0.1, method.children_time, 0.05)
913
+
914
+ method = methods[1]
915
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
916
+ assert_in_delta(0.1, method.total_time, 0.05)
917
+ assert_in_delta(0.0, method.wait_time, 0.05)
918
+ assert_in_delta(0.06, method.self_time, 0.05)
919
+ assert_in_delta(0.07, method.children_time, 0.05)
920
+
921
+ method = methods[2]
922
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
923
+ assert_in_delta(0.05, method.total_time, 0.05)
924
+ assert_in_delta(0.0, method.wait_time, 0.05)
925
+ assert_in_delta(0.05, method.self_time, 0.05)
926
+ assert_in_delta(0.0, method.children_time, 0.05)
927
+ end
928
+
929
+ def test_class_methods_busy_threaded
930
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
931
+ background_thread = Thread.new do
932
+ RubyProf::C1.busy_wait
933
+ end
934
+ background_thread.join
935
+ end
936
+
937
+ assert_equal(2, result.threads.count)
938
+
939
+ thread = result.threads.first
940
+ assert_in_delta(0.1, thread.total_time, 0.05)
941
+
942
+ methods = result.threads.first.methods.sort.reverse
943
+ assert_equal(4, methods.length)
944
+
945
+ # Check times
946
+ method = methods[0]
947
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
948
+ assert_in_delta(0.1, method.total_time, 0.05)
949
+ assert_in_delta(0.0, method.wait_time, 0.05)
950
+ assert_in_delta(0.0, method.self_time, 0.05)
951
+ assert_in_delta(0.1, method.children_time, 0.05)
952
+
953
+ method = methods[1]
954
+ assert_equal('Thread#join', method.full_name)
955
+ assert_in_delta(0.1, method.total_time, 0.05)
956
+ assert_in_delta(0.1, method.wait_time, 0.05)
957
+ assert_in_delta(0.0, method.self_time, 0.05)
958
+ assert_in_delta(0.0, method.children_time, 0.05)
959
+
960
+ method = methods[2]
961
+ assert_equal('<Class::Thread>#new', method.full_name)
962
+ assert_in_delta(0.0, method.total_time, 0.05)
963
+ assert_in_delta(0.0, method.wait_time, 0.05)
964
+ assert_in_delta(0.0, method.self_time, 0.05)
965
+ assert_in_delta(0.0, method.children_time, 0.05)
966
+
967
+ method = methods[3]
968
+ assert_equal('Thread#initialize', method.full_name)
969
+ assert_in_delta(0.0, method.total_time, 0.05)
970
+ assert_in_delta(0.0, method.wait_time, 0.05)
971
+ assert_in_delta(0.0, method.self_time, 0.05)
972
+ assert_in_delta(0.0, method.children_time, 0.05)
973
+
974
+ thread = result.threads.last
975
+ assert_in_delta(0.1, thread.total_time, 0.05)
976
+
977
+ methods = result.threads.first.methods.sort.reverse
978
+ assert_equal(4, methods.length)
979
+
980
+ methods = result.threads.last.methods.sort.reverse
981
+ assert_equal(5, methods.length)
982
+
983
+ # Check times
984
+ method = methods[0]
985
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
986
+ assert_in_delta(0.1, method.total_time, 0.05)
987
+ assert_in_delta(0.0, method.wait_time, 0.05)
988
+ assert_in_delta(0.0, method.self_time, 0.05)
989
+ assert_in_delta(0.1, method.children_time, 0.05)
990
+
991
+ method = methods[1]
992
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
993
+ assert_in_delta(0.1, method.total_time, 0.05)
994
+ assert_in_delta(0.0, method.wait_time, 0.05)
995
+ assert_in_delta(0.05, method.self_time, 0.05)
996
+ assert_in_delta(0.05, method.children_time, 0.05)
997
+
998
+ method = methods[2]
999
+ assert('<Module::Process>#clock_gettime' == method.full_name ||
1000
+ 'Float#<' == method.full_name)
1001
+ assert_in_delta(0.05, method.total_time, 0.05)
1002
+ assert_in_delta(0.0, method.wait_time, 0.05)
1003
+ assert_in_delta(0.05, method.self_time, 0.05)
1004
+ assert_in_delta(0.0, method.children_time, 0.05)
1005
+ end
1006
+
1007
+ def test_instance_methods_sleep
1008
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1009
+ RubyProf::C1.new.sleep_wait
1010
+ end
1011
+
1012
+ thread = result.threads.first
1013
+ assert_in_delta(0.0, thread.total_time, 0.05)
1014
+
1015
+ methods = result.threads.first.methods.sort.reverse
1016
+ assert_equal(5, methods.length)
1017
+
1018
+ # Check times
1019
+ method = methods[0]
1020
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
1021
+ assert_in_delta(0.0, method.total_time, 0.05)
1022
+ assert_in_delta(0.0, method.wait_time, 0.05)
1023
+ assert_in_delta(0.0, method.self_time, 0.05)
1024
+ assert_in_delta(0.0, method.children_time, 0.05)
1025
+
1026
+ method = methods[1]
1027
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1028
+ assert_in_delta(0.0, method.total_time, 0.05)
1029
+ assert_in_delta(0.0, method.wait_time, 0.05)
1030
+ assert_in_delta(0.0, method.self_time, 0.05)
1031
+ assert_in_delta(0.0, method.children_time, 0.05)
1032
+
1033
+ method = methods[2]
1034
+ assert_equal('Class#new', method.full_name)
1035
+ assert_in_delta(0.0, method.total_time, 0.05)
1036
+ assert_in_delta(0.0, method.wait_time, 0.05)
1037
+ assert_in_delta(0.0, method.self_time, 0.05)
1038
+ assert_in_delta(0.0, method.children_time, 0.05)
1039
+
1040
+ method = methods[3]
1041
+ assert_equal('Kernel#sleep', method.full_name)
1042
+ assert_in_delta(0.0, method.total_time, 0.05)
1043
+ assert_in_delta(0.0, method.wait_time, 0.05)
1044
+ assert_in_delta(0.0, method.self_time, 0.05)
1045
+ assert_in_delta(0.0, method.children_time, 0.05)
1046
+
1047
+ method = methods[4]
1048
+ assert_equal('BasicObject#initialize', method.full_name)
1049
+ assert_in_delta(0.0, method.total_time, 0.05)
1050
+ assert_in_delta(0.0, method.wait_time, 0.05)
1051
+ assert_in_delta(0.0, method.self_time, 0.05)
1052
+ assert_in_delta(0.0, method.children_time, 0.05)
1053
+ end
1054
+
1055
+ def test_instance_methods_sleep_block
1056
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1057
+ 1.times { RubyProf::C1.new.sleep_wait }
1058
+ end
1059
+
1060
+ methods = result.threads.first.methods.sort.reverse
1061
+ assert_equal(6, methods.length)
1062
+
1063
+ # Check times
1064
+ method = methods[0]
1065
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
1066
+ assert_in_delta(0.0, method.total_time, 0.05)
1067
+ assert_in_delta(0.0, method.wait_time, 0.05)
1068
+ assert_in_delta(0.0, method.self_time, 0.05)
1069
+ assert_in_delta(0.0, method.children_time, 0.05)
1070
+
1071
+ method = methods[1]
1072
+ assert_equal('Integer#times', method.full_name)
1073
+ assert_in_delta(0.0, method.total_time, 0.05)
1074
+ assert_in_delta(0.0, method.wait_time, 0.05)
1075
+ assert_in_delta(0.0, method.self_time, 0.05)
1076
+ assert_in_delta(0.0, method.children_time, 0.05)
1077
+
1078
+ method = methods[2]
1079
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1080
+ assert_in_delta(0.0, method.total_time, 0.05)
1081
+ assert_in_delta(0.0, method.wait_time, 0.05)
1082
+ assert_in_delta(0.0, method.self_time, 0.05)
1083
+ assert_in_delta(0.0, method.children_time, 0.05)
1084
+
1085
+ method = methods[3]
1086
+ assert_equal('Class#new', method.full_name)
1087
+ assert_in_delta(0.0, method.total_time, 0.05)
1088
+ assert_in_delta(0.0, method.wait_time, 0.05)
1089
+ assert_in_delta(0.0, method.self_time, 0.05)
1090
+ assert_in_delta(0.0, method.children_time, 0.05)
1091
+
1092
+ method = methods[4]
1093
+ assert_equal('Kernel#sleep', method.full_name)
1094
+ assert_in_delta(0.0, method.total_time, 0.05)
1095
+ assert_in_delta(0.0, method.wait_time, 0.05)
1096
+ assert_in_delta(0.0, method.self_time, 0.05)
1097
+ assert_in_delta(0.0, method.children_time, 0.05)
1098
+
1099
+ method = methods[5]
1100
+ assert_equal('BasicObject#initialize', method.full_name)
1101
+ assert_in_delta(0.0, method.total_time, 0.05)
1102
+ assert_in_delta(0.0, method.wait_time, 0.05)
1103
+ assert_in_delta(0.0, method.self_time, 0.05)
1104
+ assert_in_delta(0.0, method.children_time, 0.05)
1105
+ end
1106
+
1107
+ def test_instance_methods_sleep_threaded
1108
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1109
+ background_thread = Thread.new do
1110
+ RubyProf::C1.new.sleep_wait
1111
+ end
1112
+ background_thread.join
1113
+ end
1114
+
1115
+ assert_equal(2, result.threads.count)
1116
+
1117
+ thread = result.threads.first
1118
+ assert_in_delta(0.0, thread.total_time, 0.05)
1119
+
1120
+ methods = result.threads.first.methods.sort.reverse
1121
+ assert_equal(4, methods.length)
1122
+
1123
+ # Check times
1124
+ method = methods[0]
1125
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1126
+ assert_in_delta(0.0, method.total_time, 0.05)
1127
+ assert_in_delta(0.0, method.wait_time, 0.05)
1128
+ assert_in_delta(0.0, method.self_time, 0.05)
1129
+ assert_in_delta(0.0, method.children_time, 0.05)
1130
+
1131
+ method = methods[1]
1132
+ assert_equal('Thread#join', method.full_name)
1133
+ assert_in_delta(0.0, method.total_time, 0.05)
1134
+ assert_in_delta(0.0, method.wait_time, 0.05)
1135
+ assert_in_delta(0.0, method.self_time, 0.05)
1136
+ assert_in_delta(0.0, method.children_time, 0.05)
1137
+
1138
+ method = methods[2]
1139
+ assert_equal('<Class::Thread>#new', method.full_name)
1140
+ assert_in_delta(0.0, method.total_time, 0.05)
1141
+ assert_in_delta(0.0, method.wait_time, 0.05)
1142
+ assert_in_delta(0.0, method.self_time, 0.05)
1143
+ assert_in_delta(0.0, method.children_time, 0.05)
1144
+
1145
+ method = methods[3]
1146
+ assert_equal('Thread#initialize', method.full_name)
1147
+ assert_in_delta(0.0, method.total_time, 0.05)
1148
+ assert_in_delta(0.0, method.wait_time, 0.05)
1149
+ assert_in_delta(0.0, method.self_time, 0.05)
1150
+ assert_in_delta(0.0, method.children_time, 0.05)
1151
+
1152
+ thread = result.threads.last
1153
+ assert_in_delta(0.0, thread.total_time, 0.05)
1154
+
1155
+ methods = result.threads.first.methods.sort.reverse
1156
+ assert_equal(4, methods.length)
1157
+
1158
+ methods = result.threads.last.methods.sort.reverse
1159
+ assert_equal(5, methods.length)
1160
+
1161
+ # Check times
1162
+ method = methods[0]
1163
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1164
+ assert_in_delta(0.0, method.total_time, 0.05)
1165
+ assert_in_delta(0.0, method.wait_time, 0.05)
1166
+ assert_in_delta(0.0, method.self_time, 0.05)
1167
+ assert_in_delta(0.0, method.children_time, 0.05)
1168
+
1169
+ method = methods[1]
1170
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1171
+ assert_in_delta(0.0, method.total_time, 0.05)
1172
+ assert_in_delta(0.0, method.wait_time, 0.05)
1173
+ assert_in_delta(0.0, method.self_time, 0.05)
1174
+ assert_in_delta(0.0, method.children_time, 0.05)
1175
+
1176
+ method = methods[2]
1177
+ assert_equal('Class#new', method.full_name)
1178
+ assert_in_delta(0.0, method.total_time, 0.05)
1179
+ assert_in_delta(0.0, method.wait_time, 0.05)
1180
+ assert_in_delta(0.0, method.self_time, 0.05)
1181
+ assert_in_delta(0.0, method.children_time, 0.05)
1182
+
1183
+ method = methods[3]
1184
+ assert_equal('Kernel#sleep', method.full_name)
1185
+ assert_in_delta(0.0, method.total_time, 0.05)
1186
+ assert_in_delta(0.0, method.wait_time, 0.05)
1187
+ assert_in_delta(0.0, method.self_time, 0.05)
1188
+ assert_in_delta(0.0, method.children_time, 0.05)
1189
+
1190
+ method = methods[4]
1191
+ assert_equal('BasicObject#initialize', method.full_name)
1192
+ assert_in_delta(0.0, method.total_time, 0.05)
1193
+ assert_in_delta(0.0, method.wait_time, 0.05)
1194
+ assert_in_delta(0.0, method.self_time, 0.05)
1195
+ assert_in_delta(0.0, method.children_time, 0.05)
1196
+ end
1197
+
1198
+ def test_instance_methods_busy
1199
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1200
+ RubyProf::C1.new.busy_wait
1201
+ end
1202
+
1203
+ thread = result.threads.first
1204
+ assert_in_delta(0.2, thread.total_time, 0.05)
1205
+
1206
+ methods = result.threads.first.methods.sort.reverse
1207
+ assert_equal(7, methods.length)
1208
+
1209
+ # Check times
1210
+ method = methods[0]
1211
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
1212
+ assert_in_delta(0.2, method.total_time, 0.05)
1213
+ assert_in_delta(0.0, method.wait_time, 0.05)
1214
+ assert_in_delta(0.0, method.self_time, 0.05)
1215
+ assert_in_delta(0.2, method.children_time, 0.05)
1216
+
1217
+ method = methods[1]
1218
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
1219
+ assert_in_delta(0.2, method.total_time, 0.05)
1220
+ assert_in_delta(0.0, method.wait_time, 0.05)
1221
+ assert_in_delta(0.09, method.self_time, 0.05)
1222
+ assert_in_delta(0.11, method.children_time, 0.05)
1223
+
1224
+ method = methods[2]
1225
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1226
+ assert_in_delta(0.033, method.total_time, 0.05)
1227
+ assert_in_delta(0.0, method.wait_time, 0.05)
1228
+ assert_in_delta(0.033, method.self_time, 0.05)
1229
+ assert_in_delta(0.0, method.children_time, 0.05)
1230
+
1231
+ method = methods[3]
1232
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1233
+ assert_in_delta(0.0, method.total_time, 0.05)
1234
+ assert_in_delta(0.0, method.wait_time, 0.05)
1235
+ assert_in_delta(0.0, method.self_time, 0.05)
1236
+ assert_in_delta(0.0, method.children_time, 0.05)
1237
+
1238
+ method = methods[4]
1239
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1240
+ assert_in_delta(0.0, method.total_time, 0.05)
1241
+ assert_in_delta(0.0, method.wait_time, 0.05)
1242
+ assert_in_delta(0.0, method.self_time, 0.05)
1243
+ assert_in_delta(0.0, method.children_time, 0.05)
1244
+
1245
+ method = methods[5]
1246
+ assert_equal('Class#new', method.full_name)
1247
+ assert_in_delta(0.0, method.total_time, 0.05)
1248
+ assert_in_delta(0.0, method.wait_time, 0.05)
1249
+ assert_in_delta(0.0, method.self_time, 0.05)
1250
+ assert_in_delta(0.0, method.children_time, 0.05)
1251
+
1252
+ method = methods[6]
1253
+ assert_equal('BasicObject#initialize', method.full_name)
1254
+ assert_in_delta(0.0, method.total_time, 0.05)
1255
+ assert_in_delta(0.0, method.wait_time, 0.05)
1256
+ assert_in_delta(0.0, method.self_time, 0.05)
1257
+ assert_in_delta(0.0, method.children_time, 0.05)
1258
+ end
1259
+
1260
+ def test_instance_methods_busy_block
1261
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1262
+ 1.times { RubyProf::C1.new.busy_wait }
1263
+ end
1264
+
1265
+ methods = result.threads.first.methods.sort.reverse
1266
+ assert_equal(8, methods.length)
1267
+
1268
+ # Check times
1269
+ method = methods[0]
1270
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
1271
+ assert_in_delta(0.2, method.total_time, 0.05)
1272
+ assert_in_delta(0.0, method.wait_time, 0.05)
1273
+ assert_in_delta(0.0, method.self_time, 0.05)
1274
+ assert_in_delta(0.2, method.children_time, 0.05)
1275
+
1276
+ method = methods[1]
1277
+ assert_equal('Integer#times', method.full_name)
1278
+ assert_in_delta(0.2, method.total_time, 0.05)
1279
+ assert_in_delta(0.0, method.wait_time, 0.05)
1280
+ assert_in_delta(0.0, method.self_time, 0.05)
1281
+ assert_in_delta(0.2, method.children_time, 0.05)
1282
+
1283
+ method = methods[2]
1284
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
1285
+ assert_in_delta(0.2, method.total_time, 0.05)
1286
+ assert_in_delta(0.0, method.wait_time, 0.05)
1287
+ assert_in_delta(0.09, method.self_time, 0.05)
1288
+ assert_in_delta(0.11, method.children_time, 0.05)
1289
+
1290
+ method = methods[3]
1291
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1292
+ assert_in_delta(0.033, method.total_time, 0.05)
1293
+ assert_in_delta(0.0, method.wait_time, 0.05)
1294
+ assert_in_delta(0.033, method.self_time, 0.05)
1295
+ assert_in_delta(0.0, method.children_time, 0.05)
1296
+
1297
+ method = methods[4]
1298
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1299
+ assert_in_delta(0.03, method.total_time, 0.03)
1300
+ assert_in_delta(0.03, method.wait_time, 0.03)
1301
+ assert_in_delta(0.03, method.self_time, 0.03)
1302
+ assert_in_delta(0.03, method.children_time, 0.03)
1303
+
1304
+ method = methods[5]
1305
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1306
+ assert_in_delta(0.03, method.total_time, 0.03)
1307
+ assert_in_delta(0.03, method.wait_time, 0.03)
1308
+ assert_in_delta(0.03, method.self_time, 0.03)
1309
+ assert_in_delta(0.03, method.children_time, 0.03)
1310
+
1311
+ method = methods[6]
1312
+ assert_equal('Class#new', method.full_name)
1313
+ assert_in_delta(0.0, method.total_time, 0.01)
1314
+ assert_in_delta(0.0, method.wait_time, 0.01)
1315
+ assert_in_delta(0.0, method.self_time, 0.01)
1316
+ assert_in_delta(0.0, method.children_time, 0.01)
1317
+
1318
+ method = methods[7]
1319
+ assert_equal('BasicObject#initialize', method.full_name)
1320
+ assert_in_delta(0.0, method.total_time, 0.05)
1321
+ assert_in_delta(0.0, method.wait_time, 0.05)
1322
+ assert_in_delta(0.0, method.self_time, 0.05)
1323
+ assert_in_delta(0.0, method.children_time, 0.05)
1324
+ end
1325
+
1326
+ def test_instance_methods_busy_threaded
1327
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1328
+ background_thread = Thread.new do
1329
+ RubyProf::C1.new.busy_wait
1330
+ end
1331
+ background_thread.join
1332
+ end
1333
+
1334
+ assert_equal(2, result.threads.count)
1335
+
1336
+ thread = result.threads.first
1337
+ assert_in_delta(0.2, thread.total_time, 0.05)
1338
+
1339
+ methods = result.threads.first.methods.sort.reverse
1340
+ assert_equal(4, methods.length)
1341
+
1342
+ # Check times
1343
+ method = methods[0]
1344
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
1345
+ assert_in_delta(0.2, method.total_time, 0.05)
1346
+ assert_in_delta(0.0, method.wait_time, 0.05)
1347
+ assert_in_delta(0.0, method.self_time, 0.05)
1348
+ assert_in_delta(0.2, method.children_time, 0.05)
1349
+
1350
+ method = methods[1]
1351
+ assert_equal('Thread#join', method.full_name)
1352
+ assert_in_delta(0.2, method.total_time, 0.05)
1353
+ assert_in_delta(0.2, method.wait_time, 0.05)
1354
+ assert_in_delta(0.0, method.self_time, 0.05)
1355
+ assert_in_delta(0.0, method.children_time, 0.05)
1356
+
1357
+ method = methods[2]
1358
+ assert_equal('<Class::Thread>#new', method.full_name)
1359
+ assert_in_delta(0.0, method.total_time, 0.05)
1360
+ assert_in_delta(0.0, method.wait_time, 0.05)
1361
+ assert_in_delta(0.0, method.self_time, 0.05)
1362
+ assert_in_delta(0.0, method.children_time, 0.05)
1363
+
1364
+ method = methods[3]
1365
+ assert_equal('Thread#initialize', method.full_name)
1366
+ assert_in_delta(0.0, method.total_time, 0.05)
1367
+ assert_in_delta(0.0, method.wait_time, 0.05)
1368
+ assert_in_delta(0.0, method.self_time, 0.05)
1369
+ assert_in_delta(0.0, method.children_time, 0.05)
1370
+
1371
+ thread = result.threads.last
1372
+ assert_in_delta(0.2, thread.total_time, 0.05)
1373
+
1374
+ methods = result.threads.first.methods.sort.reverse
1375
+ assert_equal(4, methods.length)
1376
+
1377
+ methods = result.threads.last.methods.sort.reverse
1378
+ assert_equal(7, methods.length)
1379
+
1380
+ # Check times
1381
+ method = methods[0]
1382
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
1383
+ assert_in_delta(0.2, method.total_time, 0.05)
1384
+ assert_in_delta(0.0, method.wait_time, 0.05)
1385
+ assert_in_delta(0.0, method.self_time, 0.05)
1386
+ assert_in_delta(0.2, method.children_time, 0.05)
1387
+
1388
+ method = methods[1]
1389
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
1390
+ assert_in_delta(0.2, method.total_time, 0.05)
1391
+ assert_in_delta(0.0, method.wait_time, 0.05)
1392
+ assert_in_delta(0.1, method.self_time, 0.05)
1393
+ assert_in_delta(0.1, method.children_time, 0.05)
1394
+
1395
+ method = methods[2]
1396
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1397
+ assert_in_delta(0.03, method.total_time, 0.05)
1398
+ assert_in_delta(0.0, method.wait_time, 0.05)
1399
+ assert_in_delta(0.03, method.self_time, 0.05)
1400
+ assert_in_delta(0.0, method.children_time, 0.05)
1401
+
1402
+ method = methods[3]
1403
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1404
+ assert_in_delta(0.0, method.total_time, 0.05)
1405
+ assert_in_delta(0.0, method.wait_time, 0.05)
1406
+ assert_in_delta(0.0, method.self_time, 0.05)
1407
+ assert_in_delta(0.0, method.children_time, 0.05)
1408
+
1409
+ method = methods[4]
1410
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1411
+ assert_in_delta(0.0, method.total_time, 0.05)
1412
+ assert_in_delta(0.0, method.wait_time, 0.05)
1413
+ assert_in_delta(0.0, method.self_time, 0.05)
1414
+ assert_in_delta(0.0, method.children_time, 0.05)
1415
+
1416
+ method = methods[5]
1417
+ assert_equal('Class#new', method.full_name)
1418
+ assert_in_delta(0.0, method.total_time, 0.05)
1419
+ assert_in_delta(0.0, method.wait_time, 0.05)
1420
+ assert_in_delta(0.0, method.self_time, 0.05)
1421
+ assert_in_delta(0.0, method.children_time, 0.05)
1422
+
1423
+ method = methods[6]
1424
+ assert_equal('BasicObject#initialize', method.full_name)
1425
+ assert_in_delta(0.0, method.total_time, 0.05)
1426
+ assert_in_delta(0.0, method.wait_time, 0.05)
1427
+ assert_in_delta(0.0, method.self_time, 0.05)
1428
+ assert_in_delta(0.0, method.children_time, 0.05)
1429
+ end
1430
+
1431
+ def test_module_methods_sleep
1432
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1433
+ RubyProf::C2.sleep_wait
1434
+ end
1435
+
1436
+ thread = result.threads.first
1437
+ assert_in_delta(0.0, thread.total_time, 0.05)
1438
+
1439
+ methods = result.threads.first.methods.sort.reverse
1440
+ assert_equal(3, methods.length)
1441
+
1442
+ # Check times
1443
+ method = methods[0]
1444
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
1445
+ assert_in_delta(0.0, method.total_time, 0.05)
1446
+ assert_in_delta(0.0, method.wait_time, 0.05)
1447
+ assert_in_delta(0.0, method.self_time, 0.05)
1448
+ assert_in_delta(0.0, method.children_time, 0.05)
1449
+
1450
+ method = methods[1]
1451
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
1452
+ assert_in_delta(0.0, method.total_time, 0.05)
1453
+ assert_in_delta(0.0, method.wait_time, 0.05)
1454
+ assert_in_delta(0.0, method.self_time, 0.05)
1455
+ assert_in_delta(0.0, method.children_time, 0.05)
1456
+
1457
+ method = methods[2]
1458
+ assert_equal('Kernel#sleep', method.full_name)
1459
+ assert_in_delta(0.0, method.total_time, 0.05)
1460
+ assert_in_delta(0.0, method.wait_time, 0.05)
1461
+ assert_in_delta(0.0, method.self_time, 0.05)
1462
+ assert_in_delta(0.0, method.children_time, 0.05)
1463
+ end
1464
+
1465
+ def test_module_methods_busy
1466
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1467
+ RubyProf::C2.busy_wait
1468
+ end
1469
+
1470
+ thread = result.threads.first
1471
+ assert_in_delta(0.3, thread.total_time, 0.05)
1472
+
1473
+ methods = result.threads.first.methods.sort.reverse
1474
+ assert_equal(5, methods.length)
1475
+
1476
+ # Check times
1477
+ method = methods[0]
1478
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
1479
+ assert_in_delta(0.3, method.total_time, 0.05)
1480
+ assert_in_delta(0.0, method.wait_time, 0.05)
1481
+ assert_in_delta(0.0, method.self_time, 0.05)
1482
+ assert_in_delta(0.3, method.children_time, 0.05)
1483
+
1484
+ method = methods[1]
1485
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
1486
+ assert_in_delta(0.3, method.total_time, 0.05)
1487
+ assert_in_delta(0.0, method.wait_time, 0.05)
1488
+ assert_in_delta(0.15, method.self_time, 0.05)
1489
+ assert_in_delta(0.15, method.children_time, 0.05)
1490
+
1491
+ method = methods[2]
1492
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1493
+ assert_in_delta(0.05, method.total_time, 0.05)
1494
+ assert_in_delta(0.0, method.wait_time, 0.05)
1495
+ assert_in_delta(0.05, method.self_time, 0.05)
1496
+ assert_in_delta(0.0, method.children_time, 0.05)
1497
+ end
1498
+
1499
+ def test_module_instance_methods_sleep
1500
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1501
+ RubyProf::C2.new.sleep_wait
1502
+ end
1503
+
1504
+ thread = result.threads.first
1505
+ assert_in_delta(0.0, thread.total_time, 0.05)
1506
+
1507
+ methods = result.threads.first.methods.sort.reverse
1508
+ assert_equal(5, methods.length)
1509
+
1510
+ # Check times
1511
+ method = methods[0]
1512
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
1513
+ assert_in_delta(0.0, method.total_time, 0.05)
1514
+ assert_in_delta(0.0, method.wait_time, 0.05)
1515
+ assert_in_delta(0.0, method.self_time, 0.05)
1516
+ assert_in_delta(0.0, method.children_time, 0.05)
1517
+
1518
+ method = methods[1]
1519
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
1520
+ assert_in_delta(0.0, method.total_time, 0.05)
1521
+ assert_in_delta(0.0, method.wait_time, 0.05)
1522
+ assert_in_delta(0.0, method.self_time, 0.05)
1523
+ assert_in_delta(0.0, method.children_time, 0.05)
1524
+
1525
+ method = methods[2]
1526
+ assert_equal('Class#new', method.full_name)
1527
+ assert_in_delta(0.0, method.total_time, 0.05)
1528
+ assert_in_delta(0.0, method.wait_time, 0.05)
1529
+ assert_in_delta(0.0, method.self_time, 0.05)
1530
+ assert_in_delta(0.0, method.children_time, 0.05)
1531
+
1532
+ method = methods[3]
1533
+ assert_equal('Kernel#sleep', method.full_name)
1534
+ assert_in_delta(0.0, method.total_time, 0.05)
1535
+ assert_in_delta(0.0, method.wait_time, 0.05)
1536
+ assert_in_delta(0.0, method.self_time, 0.05)
1537
+ assert_in_delta(0.0, method.children_time, 0.05)
1538
+
1539
+ method = methods[4]
1540
+ assert_equal('BasicObject#initialize', method.full_name)
1541
+ assert_in_delta(0.0, method.total_time, 0.05)
1542
+ assert_in_delta(0.0, method.wait_time, 0.05)
1543
+ assert_in_delta(0.0, method.self_time, 0.05)
1544
+ assert_in_delta(0.0, method.children_time, 0.05)
1545
+ end
1546
+
1547
+ def test_module_instance_methods_busy
1548
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1549
+ RubyProf::C2.new.busy_wait
1550
+ end
1551
+
1552
+ thread = result.threads.first
1553
+ assert_in_delta(0.3, thread.total_time, 0.05)
1554
+
1555
+ methods = result.threads.first.methods.sort.reverse
1556
+ assert_equal(7, methods.length)
1557
+
1558
+ # Check times
1559
+ method = methods[0]
1560
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
1561
+ assert_in_delta(0.3, method.total_time, 0.05)
1562
+ assert_in_delta(0.0, method.wait_time, 0.05)
1563
+ assert_in_delta(0.0, method.self_time, 0.05)
1564
+ assert_in_delta(0.3, method.children_time, 0.05)
1565
+
1566
+ method = methods[1]
1567
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
1568
+ assert_in_delta(0.3, method.total_time, 0.05)
1569
+ assert_in_delta(0.0, method.wait_time, 0.05)
1570
+ assert_in_delta(0.15, method.self_time, 0.05)
1571
+ assert_in_delta(0.15, method.children_time, 0.05)
1572
+
1573
+ method = methods[2]
1574
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1575
+ assert_in_delta(0.05, method.total_time, 0.05)
1576
+ assert_in_delta(0.0, method.wait_time, 0.05)
1577
+ assert_in_delta(0.05, method.self_time, 0.05)
1578
+ assert_in_delta(0.0, method.children_time, 0.05)
1579
+
1580
+ method = methods[3]
1581
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1582
+ assert_in_delta(0.0, method.total_time, 0.05)
1583
+ assert_in_delta(0.0, method.wait_time, 0.05)
1584
+ assert_in_delta(0.0, method.self_time, 0.05)
1585
+ assert_in_delta(0.0, method.children_time, 0.05)
1586
+
1587
+ method = methods[4]
1588
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1589
+ assert_in_delta(0.0, method.total_time, 0.05)
1590
+ assert_in_delta(0.0, method.wait_time, 0.05)
1591
+ assert_in_delta(0.0, method.self_time, 0.05)
1592
+ assert_in_delta(0.0, method.children_time, 0.05)
1593
+
1594
+ method = methods[5]
1595
+ assert_equal('Class#new', method.full_name)
1596
+ assert_in_delta(0.0, method.total_time, 0.05)
1597
+ assert_in_delta(0.0, method.wait_time, 0.05)
1598
+ assert_in_delta(0.0, method.self_time, 0.05)
1599
+ assert_in_delta(0.0, method.children_time, 0.05)
1600
+
1601
+ method = methods[6]
1602
+ assert_equal('BasicObject#initialize', method.full_name)
1603
+ assert_in_delta(0.0, method.total_time, 0.05)
1604
+ assert_in_delta(0.0, method.wait_time, 0.05)
1605
+ assert_in_delta(0.0, method.self_time, 0.05)
1606
+ assert_in_delta(0.0, method.children_time, 0.05)
1607
+ end
1608
+ elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4')
1609
+ def test_class_methods_sleep
1610
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1611
+ RubyProf::C1.sleep_wait
1612
+ end
1613
+
1614
+ thread = result.threads.first
1615
+ assert_in_delta(0.0, thread.total_time, 0.05)
1616
+
1617
+ methods = result.threads.first.methods.sort.reverse
1618
+ assert_equal(3, methods.length)
1619
+
1620
+ # Check times
1621
+ method = methods[0]
1622
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
1623
+ assert_in_delta(0.0, method.total_time, 0.05)
1624
+ assert_in_delta(0.0, method.wait_time, 0.05)
1625
+ assert_in_delta(0.0, method.self_time, 0.05)
1626
+ assert_in_delta(0.0, method.children_time, 0.05)
1627
+
1628
+ method = methods[1]
1629
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
1630
+ assert_in_delta(0.0, method.total_time, 0.05)
1631
+ assert_in_delta(0.0, method.wait_time, 0.05)
1632
+ assert_in_delta(0.0, method.self_time, 0.05)
1633
+ assert_in_delta(0.0, method.children_time, 0.05)
1634
+
1635
+ method = methods[2]
1636
+ assert_equal('Kernel#sleep', method.full_name)
1637
+ assert_in_delta(0.0, method.total_time, 0.05)
1638
+ assert_in_delta(0.0, method.wait_time, 0.05)
1639
+ assert_in_delta(0.0, method.self_time, 0.05)
1640
+ assert_in_delta(0.0, method.children_time, 0.05)
1641
+ end
1642
+
1643
+ def test_class_methods_sleep_threaded
1644
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1645
+ background_thread = Thread.new do
1646
+ RubyProf::C1.sleep_wait
1647
+ end
1648
+ background_thread.join
1649
+ end
1650
+
1651
+ assert_equal(2, result.threads.count)
1652
+
1653
+ thread = result.threads.first
1654
+ assert_in_delta(0.0, thread.total_time, 0.05)
1655
+
1656
+ methods = result.threads.first.methods.sort.reverse
1657
+ assert_equal(4, methods.length)
1658
+
1659
+ # Check times
1660
+ method = methods[0]
1661
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
1662
+ assert_in_delta(0.0, method.total_time, 0.05)
1663
+ assert_in_delta(0.0, method.wait_time, 0.05)
1664
+ assert_in_delta(0.0, method.self_time, 0.05)
1665
+ assert_in_delta(0.0, method.children_time, 0.05)
1666
+
1667
+ method = methods[1]
1668
+ assert_equal('Thread#join', method.full_name)
1669
+ assert_in_delta(0.0, method.total_time, 0.05)
1670
+ assert_in_delta(0.0, method.wait_time, 0.05)
1671
+ assert_in_delta(0.0, method.self_time, 0.05)
1672
+ assert_in_delta(0.0, method.children_time, 0.05)
1673
+
1674
+ method = methods[2]
1675
+ assert_equal('<Class::Thread>#new', method.full_name)
1676
+ assert_in_delta(0.0, method.total_time, 0.05)
1677
+ assert_in_delta(0.0, method.wait_time, 0.05)
1678
+ assert_in_delta(0.0, method.self_time, 0.05)
1679
+ assert_in_delta(0.0, method.children_time, 0.05)
1680
+
1681
+ method = methods[3]
1682
+ assert_equal('Thread#initialize', method.full_name)
1683
+ assert_in_delta(0.0, method.total_time, 0.05)
1684
+ assert_in_delta(0.0, method.wait_time, 0.05)
1685
+ assert_in_delta(0.0, method.self_time, 0.05)
1686
+ assert_in_delta(0.0, method.children_time, 0.05)
1687
+
1688
+ thread = result.threads.last
1689
+ assert_in_delta(0.0, thread.total_time, 0.05)
1690
+
1691
+ methods = result.threads.first.methods.sort.reverse
1692
+ assert_equal(4, methods.length)
1693
+
1694
+ methods = result.threads.last.methods.sort.reverse
1695
+ assert_equal(3, methods.length)
1696
+
1697
+ # Check times
1698
+ method = methods[0]
1699
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
1700
+ assert_in_delta(0.0, method.total_time, 0.05)
1701
+ assert_in_delta(0.0, method.wait_time, 0.05)
1702
+ assert_in_delta(0.0, method.self_time, 0.05)
1703
+ assert_in_delta(0.0, method.children_time, 0.05)
1704
+
1705
+ method = methods[1]
1706
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
1707
+ assert_in_delta(0.0, method.total_time, 0.05)
1708
+ assert_in_delta(0.0, method.wait_time, 0.05)
1709
+ assert_in_delta(0.0, method.self_time, 0.05)
1710
+ assert_in_delta(0.0, method.children_time, 0.05)
1711
+
1712
+ method = methods[2]
1713
+ assert_equal('Kernel#sleep', method.full_name)
1714
+ assert_in_delta(0.0, method.total_time, 0.05)
1715
+ assert_in_delta(0.0, method.wait_time, 0.05)
1716
+ assert_in_delta(0.0, method.self_time, 0.05)
1717
+ assert_in_delta(0.0, method.children_time, 0.05)
1718
+ end
1719
+
1720
+ def test_class_methods_busy
1721
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1722
+ RubyProf::C1.busy_wait
1723
+ end
1724
+
1725
+ thread = result.threads.first
1726
+ assert_in_delta(0.08, thread.total_time, 0.05)
1727
+
1728
+ methods = result.threads.first.methods.sort.reverse
1729
+ assert_equal(5, methods.length)
1730
+
1731
+ # Check times
1732
+ method = methods[0]
1733
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
1734
+ assert_in_delta(0.1, method.total_time, 0.05)
1735
+ assert_in_delta(0.0, method.wait_time, 0.05)
1736
+ assert_in_delta(0.0, method.self_time, 0.05)
1737
+ assert_in_delta(0.1, method.children_time, 0.05)
1738
+
1739
+ method = methods[1]
1740
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
1741
+ assert_in_delta(0.1, method.total_time, 0.05)
1742
+ assert_in_delta(0.0, method.wait_time, 0.05)
1743
+ assert_in_delta(0.06, method.self_time, 0.05)
1744
+ assert_in_delta(0.07, method.children_time, 0.05)
1745
+
1746
+ method = methods[2]
1747
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1748
+ assert_in_delta(0.05, method.total_time, 0.05)
1749
+ assert_in_delta(0.0, method.wait_time, 0.05)
1750
+ assert_in_delta(0.05, method.self_time, 0.05)
1751
+ assert_in_delta(0.0, method.children_time, 0.05)
1752
+ end
1753
+
1754
+ def test_class_methods_busy_threaded
1755
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1756
+ background_thread = Thread.new do
1757
+ RubyProf::C1.busy_wait
1758
+ end
1759
+ background_thread.join
1760
+ end
1761
+
1762
+ assert_equal(2, result.threads.count)
1763
+
1764
+ thread = result.threads.first
1765
+ assert_in_delta(0.1, thread.total_time, 0.05)
1766
+
1767
+ methods = result.threads.first.methods.sort.reverse
1768
+ assert_equal(4, methods.length)
1769
+
1770
+ # Check times
1771
+ method = methods[0]
1772
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
1773
+ assert_in_delta(0.1, method.total_time, 0.05)
1774
+ assert_in_delta(0.0, method.wait_time, 0.05)
1775
+ assert_in_delta(0.0, method.self_time, 0.05)
1776
+ assert_in_delta(0.1, method.children_time, 0.05)
1777
+
1778
+ method = methods[1]
1779
+ assert_equal('Thread#join', method.full_name)
1780
+ assert_in_delta(0.1, method.total_time, 0.05)
1781
+ assert_in_delta(0.1, method.wait_time, 0.05)
1782
+ assert_in_delta(0.0, method.self_time, 0.05)
1783
+ assert_in_delta(0.0, method.children_time, 0.05)
1784
+
1785
+ method = methods[2]
1786
+ assert_equal('<Class::Thread>#new', method.full_name)
1787
+ assert_in_delta(0.0, method.total_time, 0.05)
1788
+ assert_in_delta(0.0, method.wait_time, 0.05)
1789
+ assert_in_delta(0.0, method.self_time, 0.05)
1790
+ assert_in_delta(0.0, method.children_time, 0.05)
1791
+
1792
+ method = methods[3]
1793
+ assert_equal('Thread#initialize', method.full_name)
1794
+ assert_in_delta(0.0, method.total_time, 0.05)
1795
+ assert_in_delta(0.0, method.wait_time, 0.05)
1796
+ assert_in_delta(0.0, method.self_time, 0.05)
1797
+ assert_in_delta(0.0, method.children_time, 0.05)
1798
+
1799
+ thread = result.threads.last
1800
+ assert_in_delta(0.1, thread.total_time, 0.05)
1801
+
1802
+ methods = result.threads.first.methods.sort.reverse
1803
+ assert_equal(4, methods.length)
1804
+
1805
+ methods = result.threads.last.methods.sort.reverse
1806
+ assert_equal(5, methods.length)
1807
+
1808
+ # Check times
1809
+ method = methods[0]
1810
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
1811
+ assert_in_delta(0.1, method.total_time, 0.05)
1812
+ assert_in_delta(0.0, method.wait_time, 0.05)
1813
+ assert_in_delta(0.0, method.self_time, 0.05)
1814
+ assert_in_delta(0.1, method.children_time, 0.05)
1815
+
1816
+ method = methods[1]
1817
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
1818
+ assert_in_delta(0.1, method.total_time, 0.05)
1819
+ assert_in_delta(0.0, method.wait_time, 0.05)
1820
+ assert_in_delta(0.05, method.self_time, 0.05)
1821
+ assert_in_delta(0.05, method.children_time, 0.05)
1822
+
1823
+ method = methods[2]
1824
+ assert('<Module::Process>#clock_gettime' == method.full_name ||
1825
+ 'Float#<' == method.full_name)
1826
+ assert_in_delta(0.05, method.total_time, 0.05)
1827
+ assert_in_delta(0.0, method.wait_time, 0.05)
1828
+ assert_in_delta(0.05, method.self_time, 0.05)
1829
+ assert_in_delta(0.0, method.children_time, 0.05)
1830
+ end
1831
+
1832
+ def test_instance_methods_sleep
1833
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1834
+ RubyProf::C1.new.sleep_wait
1835
+ end
1836
+
1837
+ thread = result.threads.first
1838
+ assert_in_delta(0.0, thread.total_time, 0.05)
1839
+
1840
+ methods = result.threads.first.methods.sort.reverse
1841
+ assert_equal(5, methods.length)
1842
+
1843
+ # Check times
1844
+ method = methods[0]
1845
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
1846
+ assert_in_delta(0.0, method.total_time, 0.05)
1847
+ assert_in_delta(0.0, method.wait_time, 0.05)
1848
+ assert_in_delta(0.0, method.self_time, 0.05)
1849
+ assert_in_delta(0.0, method.children_time, 0.05)
1850
+
1851
+ method = methods[1]
1852
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1853
+ assert_in_delta(0.0, method.total_time, 0.05)
1854
+ assert_in_delta(0.0, method.wait_time, 0.05)
1855
+ assert_in_delta(0.0, method.self_time, 0.05)
1856
+ assert_in_delta(0.0, method.children_time, 0.05)
1857
+
1858
+ method = methods[2]
1859
+ assert_equal('Class#new', method.full_name)
1860
+ assert_in_delta(0.0, method.total_time, 0.05)
1861
+ assert_in_delta(0.0, method.wait_time, 0.05)
1862
+ assert_in_delta(0.0, method.self_time, 0.05)
1863
+ assert_in_delta(0.0, method.children_time, 0.05)
1864
+
1865
+ method = methods[3]
1866
+ assert_equal('Kernel#sleep', method.full_name)
1867
+ assert_in_delta(0.0, method.total_time, 0.05)
1868
+ assert_in_delta(0.0, method.wait_time, 0.05)
1869
+ assert_in_delta(0.0, method.self_time, 0.05)
1870
+ assert_in_delta(0.0, method.children_time, 0.05)
1871
+
1872
+ method = methods[4]
1873
+ assert_equal('BasicObject#initialize', method.full_name)
1874
+ assert_in_delta(0.0, method.total_time, 0.05)
1875
+ assert_in_delta(0.0, method.wait_time, 0.05)
1876
+ assert_in_delta(0.0, method.self_time, 0.05)
1877
+ assert_in_delta(0.0, method.children_time, 0.05)
1878
+ end
1879
+
1880
+ def test_instance_methods_sleep_block
1881
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1882
+ 1.times { RubyProf::C1.new.sleep_wait }
1883
+ end
1884
+
1885
+ methods = result.threads.first.methods.sort.reverse
1886
+ assert_equal(9, methods.length)
1887
+
1888
+ # Check times
1889
+ method = methods[0]
1890
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
1891
+ assert_in_delta(0.0, method.total_time, 0.05)
1892
+ assert_in_delta(0.0, method.wait_time, 0.05)
1893
+ assert_in_delta(0.0, method.self_time, 0.05)
1894
+ assert_in_delta(0.0, method.children_time, 0.05)
1895
+
1896
+ method = methods[1]
1897
+ assert_equal('Integer#times', method.full_name)
1898
+ assert_in_delta(0.0, method.total_time, 0.05)
1899
+ assert_in_delta(0.0, method.wait_time, 0.05)
1900
+ assert_in_delta(0.0, method.self_time, 0.05)
1901
+ assert_in_delta(0.0, method.children_time, 0.05)
1902
+
1903
+ method = methods[2]
1904
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1905
+ assert_in_delta(0.0, method.total_time, 0.05)
1906
+ assert_in_delta(0.0, method.wait_time, 0.05)
1907
+ assert_in_delta(0.0, method.self_time, 0.05)
1908
+ assert_in_delta(0.0, method.children_time, 0.05)
1909
+
1910
+ method = methods[3]
1911
+ assert_equal('Kernel#block_given?', method.full_name)
1912
+ assert_in_delta(0.0, method.total_time, 0.05)
1913
+ assert_in_delta(0.0, method.wait_time, 0.05)
1914
+ assert_in_delta(0.0, method.self_time, 0.05)
1915
+ assert_in_delta(0.0, method.children_time, 0.05)
1916
+
1917
+ method = methods[4]
1918
+ assert_equal('Integer#succ', method.full_name)
1919
+ assert_in_delta(0.0, method.total_time, 0.05)
1920
+ assert_in_delta(0.0, method.wait_time, 0.05)
1921
+ assert_in_delta(0.0, method.self_time, 0.05)
1922
+ assert_in_delta(0.0, method.children_time, 0.05)
1923
+
1924
+ method = methods[5]
1925
+ assert_equal('Integer#<', method.full_name)
1926
+ assert_in_delta(0.0, method.total_time, 0.05)
1927
+ assert_in_delta(0.0, method.wait_time, 0.05)
1928
+ assert_in_delta(0.0, method.self_time, 0.05)
1929
+ assert_in_delta(0.0, method.children_time, 0.05)
1930
+
1931
+ method = methods[6]
1932
+ assert_equal('Class#new', method.full_name)
1933
+ assert_in_delta(0.0, method.total_time, 0.05)
1934
+ assert_in_delta(0.0, method.wait_time, 0.05)
1935
+ assert_in_delta(0.0, method.self_time, 0.05)
1936
+ assert_in_delta(0.0, method.children_time, 0.05)
1937
+
1938
+ method = methods[7]
1939
+ assert_equal('Kernel#sleep', method.full_name)
1940
+ assert_in_delta(0.0, method.total_time, 0.05)
1941
+ assert_in_delta(0.0, method.wait_time, 0.05)
1942
+ assert_in_delta(0.0, method.self_time, 0.05)
1943
+ assert_in_delta(0.0, method.children_time, 0.05)
1944
+
1945
+ method = methods[8]
1946
+ assert_equal('BasicObject#initialize', method.full_name)
1947
+ assert_in_delta(0.0, method.total_time, 0.05)
1948
+ assert_in_delta(0.0, method.wait_time, 0.05)
1949
+ assert_in_delta(0.0, method.self_time, 0.05)
1950
+ assert_in_delta(0.0, method.children_time, 0.05)
1951
+ end
1952
+
1953
+ def test_instance_methods_sleep_threaded
1954
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1955
+ background_thread = Thread.new do
1956
+ RubyProf::C1.new.sleep_wait
1957
+ end
1958
+ background_thread.join
1959
+ end
1960
+
1961
+ assert_equal(2, result.threads.count)
1962
+
1963
+ thread = result.threads.first
1964
+ assert_in_delta(0.0, thread.total_time, 0.05)
1965
+
1966
+ methods = result.threads.first.methods.sort.reverse
1967
+ assert_equal(4, methods.length)
1968
+
1969
+ # Check times
1970
+ method = methods[0]
1971
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1972
+ assert_in_delta(0.0, method.total_time, 0.05)
1973
+ assert_in_delta(0.0, method.wait_time, 0.05)
1974
+ assert_in_delta(0.0, method.self_time, 0.05)
1975
+ assert_in_delta(0.0, method.children_time, 0.05)
1976
+
1977
+ method = methods[1]
1978
+ assert_equal('Thread#join', method.full_name)
1979
+ assert_in_delta(0.0, method.total_time, 0.05)
1980
+ assert_in_delta(0.0, method.wait_time, 0.05)
1981
+ assert_in_delta(0.0, method.self_time, 0.05)
1982
+ assert_in_delta(0.0, method.children_time, 0.05)
1983
+
1984
+ method = methods[2]
1985
+ assert_equal('<Class::Thread>#new', method.full_name)
1986
+ assert_in_delta(0.0, method.total_time, 0.05)
1987
+ assert_in_delta(0.0, method.wait_time, 0.05)
1988
+ assert_in_delta(0.0, method.self_time, 0.05)
1989
+ assert_in_delta(0.0, method.children_time, 0.05)
1990
+
1991
+ method = methods[3]
1992
+ assert_equal('Thread#initialize', method.full_name)
1993
+ assert_in_delta(0.0, method.total_time, 0.05)
1994
+ assert_in_delta(0.0, method.wait_time, 0.05)
1995
+ assert_in_delta(0.0, method.self_time, 0.05)
1996
+ assert_in_delta(0.0, method.children_time, 0.05)
1997
+
1998
+ thread = result.threads.last
1999
+ assert_in_delta(0.0, thread.total_time, 0.05)
2000
+
2001
+ methods = result.threads.first.methods.sort.reverse
2002
+ assert_equal(4, methods.length)
2003
+
2004
+ methods = result.threads.last.methods.sort.reverse
2005
+ assert_equal(5, methods.length)
2006
+
2007
+ # Check times
2008
+ method = methods[0]
2009
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
2010
+ assert_in_delta(0.0, method.total_time, 0.05)
2011
+ assert_in_delta(0.0, method.wait_time, 0.05)
2012
+ assert_in_delta(0.0, method.self_time, 0.05)
2013
+ assert_in_delta(0.0, method.children_time, 0.05)
2014
+
2015
+ method = methods[1]
2016
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
2017
+ assert_in_delta(0.0, method.total_time, 0.05)
2018
+ assert_in_delta(0.0, method.wait_time, 0.05)
2019
+ assert_in_delta(0.0, method.self_time, 0.05)
2020
+ assert_in_delta(0.0, method.children_time, 0.05)
2021
+
2022
+ method = methods[2]
2023
+ assert_equal('Class#new', method.full_name)
2024
+ assert_in_delta(0.0, method.total_time, 0.05)
2025
+ assert_in_delta(0.0, method.wait_time, 0.05)
2026
+ assert_in_delta(0.0, method.self_time, 0.05)
2027
+ assert_in_delta(0.0, method.children_time, 0.05)
2028
+
2029
+ method = methods[3]
2030
+ assert_equal('Kernel#sleep', method.full_name)
2031
+ assert_in_delta(0.0, method.total_time, 0.05)
2032
+ assert_in_delta(0.0, method.wait_time, 0.05)
2033
+ assert_in_delta(0.0, method.self_time, 0.05)
2034
+ assert_in_delta(0.0, method.children_time, 0.05)
2035
+
2036
+ method = methods[4]
2037
+ assert_equal('BasicObject#initialize', method.full_name)
2038
+ assert_in_delta(0.0, method.total_time, 0.05)
2039
+ assert_in_delta(0.0, method.wait_time, 0.05)
2040
+ assert_in_delta(0.0, method.self_time, 0.05)
2041
+ assert_in_delta(0.0, method.children_time, 0.05)
2042
+ end
2043
+
2044
+ def test_instance_methods_busy
2045
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2046
+ RubyProf::C1.new.busy_wait
2047
+ end
2048
+
2049
+ thread = result.threads.first
2050
+ assert_in_delta(0.2, thread.total_time, 0.05)
2051
+
2052
+ methods = result.threads.first.methods.sort.reverse
2053
+ assert_equal(7, methods.length)
2054
+
2055
+ # Check times
2056
+ method = methods[0]
2057
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
2058
+ assert_in_delta(0.2, method.total_time, 0.05)
2059
+ assert_in_delta(0.0, method.wait_time, 0.05)
2060
+ assert_in_delta(0.0, method.self_time, 0.05)
2061
+ assert_in_delta(0.2, method.children_time, 0.05)
2062
+
2063
+ method = methods[1]
2064
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2065
+ assert_in_delta(0.2, method.total_time, 0.05)
2066
+ assert_in_delta(0.0, method.wait_time, 0.05)
2067
+ assert_in_delta(0.09, method.self_time, 0.05)
2068
+ assert_in_delta(0.11, method.children_time, 0.05)
2069
+
2070
+ method = methods[2]
2071
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2072
+ assert_in_delta(0.033, method.total_time, 0.05)
2073
+ assert_in_delta(0.0, method.wait_time, 0.05)
2074
+ assert_in_delta(0.033, method.self_time, 0.05)
2075
+ assert_in_delta(0.0, method.children_time, 0.05)
2076
+
2077
+ method = methods[3]
2078
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2079
+ assert_in_delta(0.0, method.total_time, 0.05)
2080
+ assert_in_delta(0.0, method.wait_time, 0.05)
2081
+ assert_in_delta(0.0, method.self_time, 0.05)
2082
+ assert_in_delta(0.0, method.children_time, 0.05)
2083
+
2084
+ method = methods[4]
2085
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2086
+ assert_in_delta(0.0, method.total_time, 0.05)
2087
+ assert_in_delta(0.0, method.wait_time, 0.05)
2088
+ assert_in_delta(0.0, method.self_time, 0.05)
2089
+ assert_in_delta(0.0, method.children_time, 0.05)
2090
+
2091
+ method = methods[5]
2092
+ assert_equal('Class#new', method.full_name)
2093
+ assert_in_delta(0.0, method.total_time, 0.05)
2094
+ assert_in_delta(0.0, method.wait_time, 0.05)
2095
+ assert_in_delta(0.0, method.self_time, 0.05)
2096
+ assert_in_delta(0.0, method.children_time, 0.05)
2097
+
2098
+ method = methods[6]
2099
+ assert_equal('BasicObject#initialize', method.full_name)
2100
+ assert_in_delta(0.0, method.total_time, 0.05)
2101
+ assert_in_delta(0.0, method.wait_time, 0.05)
2102
+ assert_in_delta(0.0, method.self_time, 0.05)
2103
+ assert_in_delta(0.0, method.children_time, 0.05)
2104
+ end
2105
+
2106
+ def test_instance_methods_busy_block
2107
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2108
+ 1.times { RubyProf::C1.new.busy_wait }
2109
+ end
2110
+
2111
+ methods = result.threads.first.methods.sort.reverse
2112
+ assert_equal(11, methods.length)
2113
+
2114
+ # Check times
2115
+ method = methods[0]
2116
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
2117
+ assert_in_delta(0.2, method.total_time, 0.05)
2118
+ assert_in_delta(0.0, method.wait_time, 0.05)
2119
+ assert_in_delta(0.0, method.self_time, 0.05)
2120
+ assert_in_delta(0.2, method.children_time, 0.05)
2121
+
2122
+ method = methods[1]
2123
+ assert_equal('Integer#times', method.full_name)
2124
+ assert_in_delta(0.2, method.total_time, 0.05)
2125
+ assert_in_delta(0.0, method.wait_time, 0.05)
2126
+ assert_in_delta(0.0, method.self_time, 0.05)
2127
+ assert_in_delta(0.2, method.children_time, 0.05)
2128
+
2129
+ method = methods[2]
2130
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2131
+ assert_in_delta(0.2, method.total_time, 0.05)
2132
+ assert_in_delta(0.0, method.wait_time, 0.05)
2133
+ assert_in_delta(0.09, method.self_time, 0.05)
2134
+ assert_in_delta(0.11, method.children_time, 0.05)
2135
+
2136
+ method = methods[3]
2137
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2138
+ assert_in_delta(0.033, method.total_time, 0.05)
2139
+ assert_in_delta(0.0, method.wait_time, 0.05)
2140
+ assert_in_delta(0.033, method.self_time, 0.05)
2141
+ assert_in_delta(0.0, method.children_time, 0.05)
2142
+
2143
+ method = methods[4]
2144
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2145
+ assert_in_delta(0.03, method.total_time, 0.03)
2146
+ assert_in_delta(0.03, method.wait_time, 0.03)
2147
+ assert_in_delta(0.03, method.self_time, 0.03)
2148
+ assert_in_delta(0.03, method.children_time, 0.03)
2149
+
2150
+ method = methods[5]
2151
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2152
+ assert_in_delta(0.03, method.total_time, 0.03)
2153
+ assert_in_delta(0.03, method.wait_time, 0.03)
2154
+ assert_in_delta(0.03, method.self_time, 0.03)
2155
+ assert_in_delta(0.03, method.children_time, 0.03)
2156
+
2157
+ method = methods[6]
2158
+ assert_equal('Kernel#block_given?', method.full_name)
2159
+ assert_in_delta(0.0, method.total_time, 0.05)
2160
+ assert_in_delta(0.0, method.wait_time, 0.05)
2161
+ assert_in_delta(0.0, method.self_time, 0.05)
2162
+ assert_in_delta(0.0, method.children_time, 0.05)
2163
+
2164
+ method = methods[7]
2165
+ assert_equal('Integer#succ', method.full_name)
2166
+ assert_in_delta(0.0, method.total_time, 0.05)
2167
+ assert_in_delta(0.0, method.wait_time, 0.05)
2168
+ assert_in_delta(0.0, method.self_time, 0.05)
2169
+ assert_in_delta(0.0, method.children_time, 0.05)
2170
+
2171
+ method = methods[8]
2172
+ assert_equal('Integer#<', method.full_name)
2173
+ assert_in_delta(0.0, method.total_time, 0.05)
2174
+ assert_in_delta(0.0, method.wait_time, 0.05)
2175
+ assert_in_delta(0.0, method.self_time, 0.05)
2176
+ assert_in_delta(0.0, method.children_time, 0.05)
2177
+
2178
+ method = methods[9]
2179
+ assert_equal('Class#new', method.full_name)
2180
+ assert_in_delta(0.0, method.total_time, 0.01)
2181
+ assert_in_delta(0.0, method.wait_time, 0.01)
2182
+ assert_in_delta(0.0, method.self_time, 0.01)
2183
+ assert_in_delta(0.0, method.children_time, 0.01)
2184
+
2185
+ method = methods[10]
2186
+ assert_equal('BasicObject#initialize', method.full_name)
2187
+ assert_in_delta(0.0, method.total_time, 0.05)
2188
+ assert_in_delta(0.0, method.wait_time, 0.05)
2189
+ assert_in_delta(0.0, method.self_time, 0.05)
2190
+ assert_in_delta(0.0, method.children_time, 0.05)
2191
+ end
2192
+
2193
+ def test_instance_methods_busy_threaded
2194
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2195
+ background_thread = Thread.new do
2196
+ RubyProf::C1.new.busy_wait
2197
+ end
2198
+ background_thread.join
2199
+ end
2200
+
2201
+ assert_equal(2, result.threads.count)
2202
+
2203
+ thread = result.threads.first
2204
+ assert_in_delta(0.2, thread.total_time, 0.05)
2205
+
2206
+ methods = result.threads.first.methods.sort.reverse
2207
+ assert_equal(4, methods.length)
2208
+
2209
+ # Check times
2210
+ method = methods[0]
2211
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
2212
+ assert_in_delta(0.2, method.total_time, 0.05)
2213
+ assert_in_delta(0.0, method.wait_time, 0.05)
2214
+ assert_in_delta(0.0, method.self_time, 0.05)
2215
+ assert_in_delta(0.2, method.children_time, 0.05)
2216
+
2217
+ method = methods[1]
2218
+ assert_equal('Thread#join', method.full_name)
2219
+ assert_in_delta(0.2, method.total_time, 0.05)
2220
+ assert_in_delta(0.2, method.wait_time, 0.05)
2221
+ assert_in_delta(0.0, method.self_time, 0.05)
2222
+ assert_in_delta(0.0, method.children_time, 0.05)
2223
+
2224
+ method = methods[2]
2225
+ assert_equal('<Class::Thread>#new', method.full_name)
2226
+ assert_in_delta(0.0, method.total_time, 0.05)
2227
+ assert_in_delta(0.0, method.wait_time, 0.05)
2228
+ assert_in_delta(0.0, method.self_time, 0.05)
2229
+ assert_in_delta(0.0, method.children_time, 0.05)
2230
+
2231
+ method = methods[3]
2232
+ assert_equal('Thread#initialize', method.full_name)
2233
+ assert_in_delta(0.0, method.total_time, 0.05)
2234
+ assert_in_delta(0.0, method.wait_time, 0.05)
2235
+ assert_in_delta(0.0, method.self_time, 0.05)
2236
+ assert_in_delta(0.0, method.children_time, 0.05)
2237
+
2238
+ thread = result.threads.last
2239
+ assert_in_delta(0.2, thread.total_time, 0.05)
2240
+
2241
+ methods = result.threads.first.methods.sort.reverse
2242
+ assert_equal(4, methods.length)
2243
+
2244
+ methods = result.threads.last.methods.sort.reverse
2245
+ assert_equal(7, methods.length)
2246
+
2247
+ # Check times
2248
+ method = methods[0]
2249
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
2250
+ assert_in_delta(0.2, method.total_time, 0.05)
2251
+ assert_in_delta(0.0, method.wait_time, 0.05)
2252
+ assert_in_delta(0.0, method.self_time, 0.05)
2253
+ assert_in_delta(0.2, method.children_time, 0.05)
2254
+
2255
+ method = methods[1]
2256
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2257
+ assert_in_delta(0.2, method.total_time, 0.05)
2258
+ assert_in_delta(0.0, method.wait_time, 0.05)
2259
+ assert_in_delta(0.1, method.self_time, 0.05)
2260
+ assert_in_delta(0.1, method.children_time, 0.05)
2261
+
2262
+ method = methods[2]
2263
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2264
+ assert_in_delta(0.03, method.total_time, 0.05)
2265
+ assert_in_delta(0.0, method.wait_time, 0.05)
2266
+ assert_in_delta(0.03, method.self_time, 0.05)
2267
+ assert_in_delta(0.0, method.children_time, 0.05)
2268
+
2269
+ method = methods[3]
2270
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2271
+ assert_in_delta(0.0, method.total_time, 0.05)
2272
+ assert_in_delta(0.0, method.wait_time, 0.05)
2273
+ assert_in_delta(0.0, method.self_time, 0.05)
2274
+ assert_in_delta(0.0, method.children_time, 0.05)
2275
+
2276
+ method = methods[4]
2277
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2278
+ assert_in_delta(0.0, method.total_time, 0.05)
2279
+ assert_in_delta(0.0, method.wait_time, 0.05)
2280
+ assert_in_delta(0.0, method.self_time, 0.05)
2281
+ assert_in_delta(0.0, method.children_time, 0.05)
2282
+
2283
+ method = methods[5]
2284
+ assert_equal('Class#new', method.full_name)
2285
+ assert_in_delta(0.0, method.total_time, 0.05)
2286
+ assert_in_delta(0.0, method.wait_time, 0.05)
2287
+ assert_in_delta(0.0, method.self_time, 0.05)
2288
+ assert_in_delta(0.0, method.children_time, 0.05)
2289
+
2290
+ method = methods[6]
2291
+ assert_equal('BasicObject#initialize', method.full_name)
2292
+ assert_in_delta(0.0, method.total_time, 0.05)
2293
+ assert_in_delta(0.0, method.wait_time, 0.05)
2294
+ assert_in_delta(0.0, method.self_time, 0.05)
2295
+ assert_in_delta(0.0, method.children_time, 0.05)
2296
+ end
2297
+
2298
+ def test_module_methods_sleep
2299
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2300
+ RubyProf::C2.sleep_wait
2301
+ end
2302
+
2303
+ thread = result.threads.first
2304
+ assert_in_delta(0.0, thread.total_time, 0.05)
2305
+
2306
+ methods = result.threads.first.methods.sort.reverse
2307
+ assert_equal(3, methods.length)
2308
+
2309
+ # Check times
2310
+ method = methods[0]
2311
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
2312
+ assert_in_delta(0.0, method.total_time, 0.05)
2313
+ assert_in_delta(0.0, method.wait_time, 0.05)
2314
+ assert_in_delta(0.0, method.self_time, 0.05)
2315
+ assert_in_delta(0.0, method.children_time, 0.05)
2316
+
2317
+ method = methods[1]
2318
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
2319
+ assert_in_delta(0.0, method.total_time, 0.05)
2320
+ assert_in_delta(0.0, method.wait_time, 0.05)
2321
+ assert_in_delta(0.0, method.self_time, 0.05)
2322
+ assert_in_delta(0.0, method.children_time, 0.05)
2323
+
2324
+ method = methods[2]
2325
+ assert_equal('Kernel#sleep', method.full_name)
2326
+ assert_in_delta(0.0, method.total_time, 0.05)
2327
+ assert_in_delta(0.0, method.wait_time, 0.05)
2328
+ assert_in_delta(0.0, method.self_time, 0.05)
2329
+ assert_in_delta(0.0, method.children_time, 0.05)
2330
+ end
2331
+
2332
+ def test_module_methods_busy
2333
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2334
+ RubyProf::C2.busy_wait
2335
+ end
2336
+
2337
+ thread = result.threads.first
2338
+ assert_in_delta(0.3, thread.total_time, 0.05)
2339
+
2340
+ methods = result.threads.first.methods.sort.reverse
2341
+ assert_equal(5, methods.length)
2342
+
2343
+ # Check times
2344
+ method = methods[0]
2345
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
2346
+ assert_in_delta(0.3, method.total_time, 0.05)
2347
+ assert_in_delta(0.0, method.wait_time, 0.05)
2348
+ assert_in_delta(0.0, method.self_time, 0.05)
2349
+ assert_in_delta(0.3, method.children_time, 0.05)
2350
+
2351
+ method = methods[1]
2352
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
2353
+ assert_in_delta(0.3, method.total_time, 0.05)
2354
+ assert_in_delta(0.0, method.wait_time, 0.05)
2355
+ assert_in_delta(0.15, method.self_time, 0.05)
2356
+ assert_in_delta(0.15, method.children_time, 0.05)
2357
+
2358
+ method = methods[2]
2359
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2360
+ assert_in_delta(0.05, method.total_time, 0.05)
2361
+ assert_in_delta(0.0, method.wait_time, 0.05)
2362
+ assert_in_delta(0.05, method.self_time, 0.05)
2363
+ assert_in_delta(0.0, method.children_time, 0.05)
2364
+ end
2365
+
2366
+ def test_module_instance_methods_sleep
2367
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2368
+ RubyProf::C2.new.sleep_wait
2369
+ end
2370
+
2371
+ thread = result.threads.first
2372
+ assert_in_delta(0.0, thread.total_time, 0.05)
2373
+
2374
+ methods = result.threads.first.methods.sort.reverse
2375
+ assert_equal(5, methods.length)
2376
+
2377
+ # Check times
2378
+ method = methods[0]
2379
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
2380
+ assert_in_delta(0.0, method.total_time, 0.05)
2381
+ assert_in_delta(0.0, method.wait_time, 0.05)
2382
+ assert_in_delta(0.0, method.self_time, 0.05)
2383
+ assert_in_delta(0.0, method.children_time, 0.05)
2384
+
2385
+ method = methods[1]
2386
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
2387
+ assert_in_delta(0.0, method.total_time, 0.05)
2388
+ assert_in_delta(0.0, method.wait_time, 0.05)
2389
+ assert_in_delta(0.0, method.self_time, 0.05)
2390
+ assert_in_delta(0.0, method.children_time, 0.05)
2391
+
2392
+ method = methods[2]
2393
+ assert_equal('Class#new', method.full_name)
2394
+ assert_in_delta(0.0, method.total_time, 0.05)
2395
+ assert_in_delta(0.0, method.wait_time, 0.05)
2396
+ assert_in_delta(0.0, method.self_time, 0.05)
2397
+ assert_in_delta(0.0, method.children_time, 0.05)
2398
+
2399
+ method = methods[3]
2400
+ assert_equal('Kernel#sleep', method.full_name)
2401
+ assert_in_delta(0.0, method.total_time, 0.05)
2402
+ assert_in_delta(0.0, method.wait_time, 0.05)
2403
+ assert_in_delta(0.0, method.self_time, 0.05)
2404
+ assert_in_delta(0.0, method.children_time, 0.05)
2405
+
2406
+ method = methods[4]
2407
+ assert_equal('BasicObject#initialize', method.full_name)
2408
+ assert_in_delta(0.0, method.total_time, 0.05)
2409
+ assert_in_delta(0.0, method.wait_time, 0.05)
2410
+ assert_in_delta(0.0, method.self_time, 0.05)
2411
+ assert_in_delta(0.0, method.children_time, 0.05)
2412
+ end
2413
+
2414
+ def test_module_instance_methods_busy
2415
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2416
+ RubyProf::C2.new.busy_wait
2417
+ end
2418
+
2419
+ thread = result.threads.first
2420
+ assert_in_delta(0.3, thread.total_time, 0.05)
2421
+
2422
+ methods = result.threads.first.methods.sort.reverse
2423
+ assert_equal(7, methods.length)
2424
+
2425
+ # Check times
2426
+ method = methods[0]
2427
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
2428
+ assert_in_delta(0.3, method.total_time, 0.05)
2429
+ assert_in_delta(0.0, method.wait_time, 0.05)
2430
+ assert_in_delta(0.0, method.self_time, 0.05)
2431
+ assert_in_delta(0.3, method.children_time, 0.05)
2432
+
2433
+ method = methods[1]
2434
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
2435
+ assert_in_delta(0.3, method.total_time, 0.05)
2436
+ assert_in_delta(0.0, method.wait_time, 0.05)
2437
+ assert_in_delta(0.15, method.self_time, 0.05)
2438
+ assert_in_delta(0.15, method.children_time, 0.05)
2439
+
2440
+ method = methods[2]
2441
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2442
+ assert_in_delta(0.05, method.total_time, 0.05)
2443
+ assert_in_delta(0.0, method.wait_time, 0.05)
2444
+ assert_in_delta(0.05, method.self_time, 0.05)
2445
+ assert_in_delta(0.0, method.children_time, 0.05)
2446
+
2447
+ method = methods[3]
2448
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2449
+ assert_in_delta(0.0, method.total_time, 0.05)
2450
+ assert_in_delta(0.0, method.wait_time, 0.05)
2451
+ assert_in_delta(0.0, method.self_time, 0.05)
2452
+ assert_in_delta(0.0, method.children_time, 0.05)
2453
+
2454
+ method = methods[4]
2455
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2456
+ assert_in_delta(0.0, method.total_time, 0.05)
2457
+ assert_in_delta(0.0, method.wait_time, 0.05)
2458
+ assert_in_delta(0.0, method.self_time, 0.05)
2459
+ assert_in_delta(0.0, method.children_time, 0.05)
2460
+
2461
+ method = methods[5]
2462
+ assert_equal('Class#new', method.full_name)
2463
+ assert_in_delta(0.0, method.total_time, 0.05)
2464
+ assert_in_delta(0.0, method.wait_time, 0.05)
2465
+ assert_in_delta(0.0, method.self_time, 0.05)
2466
+ assert_in_delta(0.0, method.children_time, 0.05)
2467
+
2468
+ method = methods[6]
2469
+ assert_equal('BasicObject#initialize', method.full_name)
2470
+ assert_in_delta(0.0, method.total_time, 0.05)
2471
+ assert_in_delta(0.0, method.wait_time, 0.05)
2472
+ assert_in_delta(0.0, method.self_time, 0.05)
2473
+ assert_in_delta(0.0, method.children_time, 0.05)
2474
+ end
2475
+ else
2476
+ def test_class_methods_sleep
2477
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2478
+ RubyProf::C1.sleep_wait
2479
+ end
2480
+
2481
+ thread = result.threads.first
2482
+ assert_in_delta(0.0, thread.total_time, 0.05)
2483
+
2484
+ methods = result.threads.first.methods.sort.reverse
2485
+ assert_equal(3, methods.length)
2486
+
2487
+ # Check times
2488
+ method = methods[0]
2489
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
2490
+ assert_in_delta(0.0, method.total_time, 0.05)
2491
+ assert_in_delta(0.0, method.wait_time, 0.05)
2492
+ assert_in_delta(0.0, method.self_time, 0.05)
2493
+ assert_in_delta(0.0, method.children_time, 0.05)
2494
+
2495
+ method = methods[1]
2496
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
2497
+ assert_in_delta(0.0, method.total_time, 0.05)
2498
+ assert_in_delta(0.0, method.wait_time, 0.05)
2499
+ assert_in_delta(0.0, method.self_time, 0.05)
2500
+ assert_in_delta(0.0, method.children_time, 0.05)
2501
+
2502
+ method = methods[2]
2503
+ assert_equal('Kernel#sleep', method.full_name)
2504
+ assert_in_delta(0.0, method.total_time, 0.05)
2505
+ assert_in_delta(0.0, method.wait_time, 0.05)
2506
+ assert_in_delta(0.0, method.self_time, 0.05)
2507
+ assert_in_delta(0.0, method.children_time, 0.05)
2508
+ end
2509
+
2510
+ def test_class_methods_sleep_threaded
2511
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2512
+ background_thread = Thread.new do
2513
+ RubyProf::C1.sleep_wait
2514
+ end
2515
+ background_thread.join
2516
+ end
2517
+
2518
+ assert_equal(2, result.threads.count)
2519
+
2520
+ thread = result.threads.first
2521
+ assert_in_delta(0.0, thread.total_time, 0.05)
2522
+
2523
+ methods = result.threads.first.methods.sort.reverse
2524
+ assert_equal(4, methods.length)
2525
+
2526
+ # Check times
2527
+ method = methods[0]
2528
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
2529
+ assert_in_delta(0.0, method.total_time, 0.05)
2530
+ assert_in_delta(0.0, method.wait_time, 0.05)
2531
+ assert_in_delta(0.0, method.self_time, 0.05)
2532
+ assert_in_delta(0.0, method.children_time, 0.05)
2533
+
2534
+ method = methods[1]
2535
+ assert_equal('Thread#join', method.full_name)
2536
+ assert_in_delta(0.0, method.total_time, 0.05)
2537
+ assert_in_delta(0.0, method.wait_time, 0.05)
2538
+ assert_in_delta(0.0, method.self_time, 0.05)
2539
+ assert_in_delta(0.0, method.children_time, 0.05)
2540
+
2541
+ method = methods[2]
2542
+ assert_equal('<Class::Thread>#new', method.full_name)
2543
+ assert_in_delta(0.0, method.total_time, 0.05)
2544
+ assert_in_delta(0.0, method.wait_time, 0.05)
2545
+ assert_in_delta(0.0, method.self_time, 0.05)
2546
+ assert_in_delta(0.0, method.children_time, 0.05)
2547
+
2548
+ method = methods[3]
2549
+ assert_equal('Thread#initialize', method.full_name)
2550
+ assert_in_delta(0.0, method.total_time, 0.05)
2551
+ assert_in_delta(0.0, method.wait_time, 0.05)
2552
+ assert_in_delta(0.0, method.self_time, 0.05)
2553
+ assert_in_delta(0.0, method.children_time, 0.05)
2554
+
2555
+ thread = result.threads.last
2556
+ assert_in_delta(0.0, thread.total_time, 0.05)
2557
+
2558
+ methods = result.threads.first.methods.sort.reverse
2559
+ assert_equal(4, methods.length)
2560
+
2561
+ methods = result.threads.last.methods.sort.reverse
2562
+ assert_equal(3, methods.length)
2563
+
2564
+ # Check times
2565
+ method = methods[0]
2566
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
2567
+ assert_in_delta(0.0, method.total_time, 0.05)
2568
+ assert_in_delta(0.0, method.wait_time, 0.05)
2569
+ assert_in_delta(0.0, method.self_time, 0.05)
2570
+ assert_in_delta(0.0, method.children_time, 0.05)
2571
+
2572
+ method = methods[1]
2573
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
2574
+ assert_in_delta(0.0, method.total_time, 0.05)
2575
+ assert_in_delta(0.0, method.wait_time, 0.05)
2576
+ assert_in_delta(0.0, method.self_time, 0.05)
2577
+ assert_in_delta(0.0, method.children_time, 0.05)
2578
+
2579
+ method = methods[2]
2580
+ assert_equal('Kernel#sleep', method.full_name)
2581
+ assert_in_delta(0.0, method.total_time, 0.05)
2582
+ assert_in_delta(0.0, method.wait_time, 0.05)
2583
+ assert_in_delta(0.0, method.self_time, 0.05)
2584
+ assert_in_delta(0.0, method.children_time, 0.05)
2585
+ end
2586
+
2587
+ def test_class_methods_busy
2588
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2589
+ RubyProf::C1.busy_wait
2590
+ end
2591
+
2592
+ thread = result.threads.first
2593
+ assert_in_delta(0.08, thread.total_time, 0.05)
2594
+
2595
+ methods = result.threads.first.methods.sort.reverse
2596
+ assert_equal(5, methods.length)
2597
+
2598
+ # Check times
2599
+ method = methods[0]
2600
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
2601
+ assert_in_delta(0.1, method.total_time, 0.05)
2602
+ assert_in_delta(0.0, method.wait_time, 0.05)
2603
+ assert_in_delta(0.0, method.self_time, 0.05)
2604
+ assert_in_delta(0.1, method.children_time, 0.05)
2605
+
2606
+ method = methods[1]
2607
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
2608
+ assert_in_delta(0.1, method.total_time, 0.05)
2609
+ assert_in_delta(0.0, method.wait_time, 0.05)
2610
+ assert_in_delta(0.06, method.self_time, 0.05)
2611
+ assert_in_delta(0.07, method.children_time, 0.05)
2612
+
2613
+ method = methods[2]
2614
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2615
+ assert_in_delta(0.05, method.total_time, 0.05)
2616
+ assert_in_delta(0.0, method.wait_time, 0.05)
2617
+ assert_in_delta(0.05, method.self_time, 0.05)
2618
+ assert_in_delta(0.0, method.children_time, 0.05)
2619
+ end
2620
+
2621
+ def test_class_methods_busy_threaded
2622
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2623
+ background_thread = Thread.new do
2624
+ RubyProf::C1.busy_wait
2625
+ end
2626
+ background_thread.join
2627
+ end
2628
+
2629
+ assert_equal(2, result.threads.count)
2630
+
2631
+ thread = result.threads.first
2632
+ assert_in_delta(0.1, thread.total_time, 0.05)
2633
+
2634
+ methods = result.threads.first.methods.sort.reverse
2635
+ assert_equal(4, methods.length)
2636
+
2637
+ # Check times
2638
+ method = methods[0]
2639
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
2640
+ assert_in_delta(0.1, method.total_time, 0.05)
2641
+ assert_in_delta(0.0, method.wait_time, 0.05)
2642
+ assert_in_delta(0.0, method.self_time, 0.05)
2643
+ assert_in_delta(0.1, method.children_time, 0.05)
2644
+
2645
+ method = methods[1]
2646
+ assert_equal('Thread#join', method.full_name)
2647
+ assert_in_delta(0.1, method.total_time, 0.05)
2648
+ assert_in_delta(0.1, method.wait_time, 0.05)
2649
+ assert_in_delta(0.0, method.self_time, 0.05)
2650
+ assert_in_delta(0.0, method.children_time, 0.05)
2651
+
2652
+ method = methods[2]
2653
+ assert_equal('<Class::Thread>#new', method.full_name)
2654
+ assert_in_delta(0.0, method.total_time, 0.05)
2655
+ assert_in_delta(0.0, method.wait_time, 0.05)
2656
+ assert_in_delta(0.0, method.self_time, 0.05)
2657
+ assert_in_delta(0.0, method.children_time, 0.05)
2658
+
2659
+ method = methods[3]
2660
+ assert_equal('Thread#initialize', method.full_name)
2661
+ assert_in_delta(0.0, method.total_time, 0.05)
2662
+ assert_in_delta(0.0, method.wait_time, 0.05)
2663
+ assert_in_delta(0.0, method.self_time, 0.05)
2664
+ assert_in_delta(0.0, method.children_time, 0.05)
2665
+
2666
+ thread = result.threads.last
2667
+ assert_in_delta(0.1, thread.total_time, 0.05)
2668
+
2669
+ methods = result.threads.first.methods.sort.reverse
2670
+ assert_equal(4, methods.length)
2671
+
2672
+ methods = result.threads.last.methods.sort.reverse
2673
+ assert_equal(5, methods.length)
2674
+
2675
+ # Check times
2676
+ method = methods[0]
2677
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
2678
+ assert_in_delta(0.1, method.total_time, 0.05)
2679
+ assert_in_delta(0.0, method.wait_time, 0.05)
2680
+ assert_in_delta(0.0, method.self_time, 0.05)
2681
+ assert_in_delta(0.1, method.children_time, 0.05)
2682
+
2683
+ method = methods[1]
2684
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
2685
+ assert_in_delta(0.1, method.total_time, 0.05)
2686
+ assert_in_delta(0.0, method.wait_time, 0.05)
2687
+ assert_in_delta(0.05, method.self_time, 0.05)
2688
+ assert_in_delta(0.05, method.children_time, 0.05)
2689
+
2690
+ method = methods[2]
2691
+ assert('<Module::Process>#clock_gettime' == method.full_name ||
2692
+ 'Float#<' == method.full_name)
2693
+ assert_in_delta(0.05, method.total_time, 0.05)
2694
+ assert_in_delta(0.0, method.wait_time, 0.05)
2695
+ assert_in_delta(0.05, method.self_time, 0.05)
2696
+ assert_in_delta(0.0, method.children_time, 0.05)
2697
+ end
2698
+
2699
+ def test_instance_methods_sleep
2700
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2701
+ RubyProf::C1.new.sleep_wait
2702
+ end
2703
+
2704
+ thread = result.threads.first
2705
+ assert_in_delta(0.0, thread.total_time, 0.05)
2706
+
2707
+ methods = result.threads.first.methods.sort.reverse
2708
+ assert_equal(5, methods.length)
2709
+
2710
+ # Check times
2711
+ method = methods[0]
2712
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
2713
+ assert_in_delta(0.0, method.total_time, 0.05)
2714
+ assert_in_delta(0.0, method.wait_time, 0.05)
2715
+ assert_in_delta(0.0, method.self_time, 0.05)
2716
+ assert_in_delta(0.0, method.children_time, 0.05)
2717
+
2718
+ method = methods[1]
2719
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
2720
+ assert_in_delta(0.0, method.total_time, 0.05)
2721
+ assert_in_delta(0.0, method.wait_time, 0.05)
2722
+ assert_in_delta(0.0, method.self_time, 0.05)
2723
+ assert_in_delta(0.0, method.children_time, 0.05)
2724
+
2725
+ method = methods[2]
2726
+ assert_equal('Class#new', method.full_name)
2727
+ assert_in_delta(0.0, method.total_time, 0.05)
2728
+ assert_in_delta(0.0, method.wait_time, 0.05)
2729
+ assert_in_delta(0.0, method.self_time, 0.05)
2730
+ assert_in_delta(0.0, method.children_time, 0.05)
2731
+
2732
+ method = methods[3]
2733
+ assert_equal('Kernel#sleep', method.full_name)
2734
+ assert_in_delta(0.0, method.total_time, 0.05)
2735
+ assert_in_delta(0.0, method.wait_time, 0.05)
2736
+ assert_in_delta(0.0, method.self_time, 0.05)
2737
+ assert_in_delta(0.0, method.children_time, 0.05)
2738
+
2739
+ method = methods[4]
2740
+ assert_equal('BasicObject#initialize', method.full_name)
2741
+ assert_in_delta(0.0, method.total_time, 0.05)
2742
+ assert_in_delta(0.0, method.wait_time, 0.05)
2743
+ assert_in_delta(0.0, method.self_time, 0.05)
2744
+ assert_in_delta(0.0, method.children_time, 0.05)
2745
+ end
2746
+
2747
+ def test_instance_methods_sleep_block
2748
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2749
+ 1.times { RubyProf::C1.new.sleep_wait }
2750
+ end
2751
+
2752
+ methods = result.threads.first.methods.sort.reverse
2753
+ assert_equal(8, methods.length)
2754
+
2755
+ # Check times
2756
+ method = methods[0]
2757
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
2758
+ assert_in_delta(0.0, method.total_time, 0.05)
2759
+ assert_in_delta(0.0, method.wait_time, 0.05)
2760
+ assert_in_delta(0.0, method.self_time, 0.05)
2761
+ assert_in_delta(0.0, method.children_time, 0.05)
2762
+
2763
+ method = methods[1]
2764
+ assert_equal('Integer#times', method.full_name)
2765
+ assert_in_delta(0.0, method.total_time, 0.05)
2766
+ assert_in_delta(0.0, method.wait_time, 0.05)
2767
+ assert_in_delta(0.0, method.self_time, 0.05)
2768
+ assert_in_delta(0.0, method.children_time, 0.05)
2769
+
2770
+ method = methods[2]
2771
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
2772
+ assert_in_delta(0.0, method.total_time, 0.05)
2773
+ assert_in_delta(0.0, method.wait_time, 0.05)
2774
+ assert_in_delta(0.0, method.self_time, 0.05)
2775
+ assert_in_delta(0.0, method.children_time, 0.05)
2776
+
2777
+ method = methods[3]
2778
+ assert_equal('Integer#succ', method.full_name)
2779
+ assert_in_delta(0.0, method.total_time, 0.05)
2780
+ assert_in_delta(0.0, method.wait_time, 0.05)
2781
+ assert_in_delta(0.0, method.self_time, 0.05)
2782
+ assert_in_delta(0.0, method.children_time, 0.05)
2783
+
2784
+ method = methods[4]
2785
+ assert_equal('Integer#<', method.full_name)
2786
+ assert_in_delta(0.0, method.total_time, 0.05)
2787
+ assert_in_delta(0.0, method.wait_time, 0.05)
2788
+ assert_in_delta(0.0, method.self_time, 0.05)
2789
+ assert_in_delta(0.0, method.children_time, 0.05)
2790
+
2791
+ method = methods[5]
2792
+ assert_equal('Class#new', method.full_name)
2793
+ assert_in_delta(0.0, method.total_time, 0.05)
2794
+ assert_in_delta(0.0, method.wait_time, 0.05)
2795
+ assert_in_delta(0.0, method.self_time, 0.05)
2796
+ assert_in_delta(0.0, method.children_time, 0.05)
2797
+
2798
+ method = methods[6]
2799
+ assert_equal('Kernel#sleep', method.full_name)
2800
+ assert_in_delta(0.0, method.total_time, 0.05)
2801
+ assert_in_delta(0.0, method.wait_time, 0.05)
2802
+ assert_in_delta(0.0, method.self_time, 0.05)
2803
+ assert_in_delta(0.0, method.children_time, 0.05)
2804
+
2805
+ method = methods[7]
2806
+ assert_equal('BasicObject#initialize', method.full_name)
2807
+ assert_in_delta(0.0, method.total_time, 0.05)
2808
+ assert_in_delta(0.0, method.wait_time, 0.05)
2809
+ assert_in_delta(0.0, method.self_time, 0.05)
2810
+ assert_in_delta(0.0, method.children_time, 0.05)
2811
+ end
2812
+
2813
+ def test_instance_methods_sleep_threaded
2814
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2815
+ background_thread = Thread.new do
2816
+ RubyProf::C1.new.sleep_wait
2817
+ end
2818
+ background_thread.join
2819
+ end
2820
+
2821
+ assert_equal(2, result.threads.count)
2822
+
2823
+ thread = result.threads.first
2824
+ assert_in_delta(0.0, thread.total_time, 0.05)
2825
+
2826
+ methods = result.threads.first.methods.sort.reverse
2827
+ assert_equal(4, methods.length)
2828
+
2829
+ # Check times
2830
+ method = methods[0]
2831
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
2832
+ assert_in_delta(0.0, method.total_time, 0.05)
2833
+ assert_in_delta(0.0, method.wait_time, 0.05)
2834
+ assert_in_delta(0.0, method.self_time, 0.05)
2835
+ assert_in_delta(0.0, method.children_time, 0.05)
2836
+
2837
+ method = methods[1]
2838
+ assert_equal('Thread#join', method.full_name)
2839
+ assert_in_delta(0.0, method.total_time, 0.05)
2840
+ assert_in_delta(0.0, method.wait_time, 0.05)
2841
+ assert_in_delta(0.0, method.self_time, 0.05)
2842
+ assert_in_delta(0.0, method.children_time, 0.05)
2843
+
2844
+ method = methods[2]
2845
+ assert_equal('<Class::Thread>#new', method.full_name)
2846
+ assert_in_delta(0.0, method.total_time, 0.05)
2847
+ assert_in_delta(0.0, method.wait_time, 0.05)
2848
+ assert_in_delta(0.0, method.self_time, 0.05)
2849
+ assert_in_delta(0.0, method.children_time, 0.05)
2850
+
2851
+ method = methods[3]
2852
+ assert_equal('Thread#initialize', method.full_name)
2853
+ assert_in_delta(0.0, method.total_time, 0.05)
2854
+ assert_in_delta(0.0, method.wait_time, 0.05)
2855
+ assert_in_delta(0.0, method.self_time, 0.05)
2856
+ assert_in_delta(0.0, method.children_time, 0.05)
2857
+
2858
+ thread = result.threads.last
2859
+ assert_in_delta(0.0, thread.total_time, 0.05)
2860
+
2861
+ methods = result.threads.first.methods.sort.reverse
2862
+ assert_equal(4, methods.length)
2863
+
2864
+ methods = result.threads.last.methods.sort.reverse
2865
+ assert_equal(5, methods.length)
2866
+
2867
+ # Check times
2868
+ method = methods[0]
2869
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
2870
+ assert_in_delta(0.0, method.total_time, 0.05)
2871
+ assert_in_delta(0.0, method.wait_time, 0.05)
2872
+ assert_in_delta(0.0, method.self_time, 0.05)
2873
+ assert_in_delta(0.0, method.children_time, 0.05)
2874
+
2875
+ method = methods[1]
2876
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
2877
+ assert_in_delta(0.0, method.total_time, 0.05)
2878
+ assert_in_delta(0.0, method.wait_time, 0.05)
2879
+ assert_in_delta(0.0, method.self_time, 0.05)
2880
+ assert_in_delta(0.0, method.children_time, 0.05)
2881
+
2882
+ method = methods[2]
2883
+ assert_equal('Class#new', method.full_name)
2884
+ assert_in_delta(0.0, method.total_time, 0.05)
2885
+ assert_in_delta(0.0, method.wait_time, 0.05)
2886
+ assert_in_delta(0.0, method.self_time, 0.05)
2887
+ assert_in_delta(0.0, method.children_time, 0.05)
2888
+
2889
+ method = methods[3]
2890
+ assert_equal('Kernel#sleep', method.full_name)
2891
+ assert_in_delta(0.0, method.total_time, 0.05)
2892
+ assert_in_delta(0.0, method.wait_time, 0.05)
2893
+ assert_in_delta(0.0, method.self_time, 0.05)
2894
+ assert_in_delta(0.0, method.children_time, 0.05)
2895
+
2896
+ method = methods[4]
2897
+ assert_equal('BasicObject#initialize', method.full_name)
2898
+ assert_in_delta(0.0, method.total_time, 0.05)
2899
+ assert_in_delta(0.0, method.wait_time, 0.05)
2900
+ assert_in_delta(0.0, method.self_time, 0.05)
2901
+ assert_in_delta(0.0, method.children_time, 0.05)
2902
+ end
2903
+
2904
+ def test_instance_methods_busy
2905
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2906
+ RubyProf::C1.new.busy_wait
2907
+ end
2908
+
2909
+ thread = result.threads.first
2910
+ assert_in_delta(0.2, thread.total_time, 0.05)
2911
+
2912
+ methods = result.threads.first.methods.sort.reverse
2913
+ assert_equal(7, methods.length)
2914
+
2915
+ # Check times
2916
+ method = methods[0]
2917
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
2918
+ assert_in_delta(0.2, method.total_time, 0.05)
2919
+ assert_in_delta(0.0, method.wait_time, 0.05)
2920
+ assert_in_delta(0.0, method.self_time, 0.05)
2921
+ assert_in_delta(0.2, method.children_time, 0.05)
2922
+
2923
+ method = methods[1]
2924
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2925
+ assert_in_delta(0.2, method.total_time, 0.05)
2926
+ assert_in_delta(0.0, method.wait_time, 0.05)
2927
+ assert_in_delta(0.09, method.self_time, 0.05)
2928
+ assert_in_delta(0.11, method.children_time, 0.05)
2929
+
2930
+ method = methods[2]
2931
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2932
+ assert_in_delta(0.033, method.total_time, 0.05)
2933
+ assert_in_delta(0.0, method.wait_time, 0.05)
2934
+ assert_in_delta(0.033, method.self_time, 0.05)
2935
+ assert_in_delta(0.0, method.children_time, 0.05)
2936
+
2937
+ method = methods[3]
2938
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2939
+ assert_in_delta(0.0, method.total_time, 0.05)
2940
+ assert_in_delta(0.0, method.wait_time, 0.05)
2941
+ assert_in_delta(0.0, method.self_time, 0.05)
2942
+ assert_in_delta(0.0, method.children_time, 0.05)
2943
+
2944
+ method = methods[4]
2945
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2946
+ assert_in_delta(0.0, method.total_time, 0.05)
2947
+ assert_in_delta(0.0, method.wait_time, 0.05)
2948
+ assert_in_delta(0.0, method.self_time, 0.05)
2949
+ assert_in_delta(0.0, method.children_time, 0.05)
2950
+
2951
+ method = methods[5]
2952
+ assert_equal('Class#new', method.full_name)
2953
+ assert_in_delta(0.0, method.total_time, 0.05)
2954
+ assert_in_delta(0.0, method.wait_time, 0.05)
2955
+ assert_in_delta(0.0, method.self_time, 0.05)
2956
+ assert_in_delta(0.0, method.children_time, 0.05)
2957
+
2958
+ method = methods[6]
2959
+ assert_equal('BasicObject#initialize', method.full_name)
2960
+ assert_in_delta(0.0, method.total_time, 0.05)
2961
+ assert_in_delta(0.0, method.wait_time, 0.05)
2962
+ assert_in_delta(0.0, method.self_time, 0.05)
2963
+ assert_in_delta(0.0, method.children_time, 0.05)
2964
+ end
2965
+
2966
+ def test_instance_methods_busy_block
2967
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2968
+ 1.times { RubyProf::C1.new.busy_wait }
2969
+ end
2970
+
2971
+ methods = result.threads.first.methods.sort.reverse
2972
+ assert_equal(10, methods.length)
2973
+
2974
+ # Check times
2975
+ method = methods[0]
2976
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
2977
+ assert_in_delta(0.2, method.total_time, 0.05)
2978
+ assert_in_delta(0.0, method.wait_time, 0.05)
2979
+ assert_in_delta(0.0, method.self_time, 0.05)
2980
+ assert_in_delta(0.2, method.children_time, 0.05)
2981
+
2982
+ method = methods[1]
2983
+ assert_equal('Integer#times', method.full_name)
2984
+ assert_in_delta(0.2, method.total_time, 0.05)
2985
+ assert_in_delta(0.0, method.wait_time, 0.05)
2986
+ assert_in_delta(0.0, method.self_time, 0.05)
2987
+ assert_in_delta(0.2, method.children_time, 0.05)
2988
+
2989
+ method = methods[2]
2990
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2991
+ assert_in_delta(0.2, method.total_time, 0.05)
2992
+ assert_in_delta(0.0, method.wait_time, 0.05)
2993
+ assert_in_delta(0.09, method.self_time, 0.05)
2994
+ assert_in_delta(0.11, method.children_time, 0.05)
2995
+
2996
+ method = methods[3]
2997
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2998
+ assert_in_delta(0.033, method.total_time, 0.05)
2999
+ assert_in_delta(0.0, method.wait_time, 0.05)
3000
+ assert_in_delta(0.033, method.self_time, 0.05)
3001
+ assert_in_delta(0.0, method.children_time, 0.05)
3002
+
3003
+ method = methods[4]
3004
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
3005
+ assert_in_delta(0.03, method.total_time, 0.03)
3006
+ assert_in_delta(0.03, method.wait_time, 0.03)
3007
+ assert_in_delta(0.03, method.self_time, 0.03)
3008
+ assert_in_delta(0.03, method.children_time, 0.03)
3009
+
3010
+ method = methods[5]
3011
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
3012
+ assert_in_delta(0.03, method.total_time, 0.03)
3013
+ assert_in_delta(0.03, method.wait_time, 0.03)
3014
+ assert_in_delta(0.03, method.self_time, 0.03)
3015
+ assert_in_delta(0.03, method.children_time, 0.03)
3016
+
3017
+ method = methods[6]
3018
+ assert_equal('Integer#succ', method.full_name)
3019
+ assert_in_delta(0.0, method.total_time, 0.05)
3020
+ assert_in_delta(0.0, method.wait_time, 0.05)
3021
+ assert_in_delta(0.0, method.self_time, 0.05)
3022
+ assert_in_delta(0.0, method.children_time, 0.05)
3023
+
3024
+ method = methods[7]
3025
+ assert_equal('Integer#<', method.full_name)
3026
+ assert_in_delta(0.0, method.total_time, 0.05)
3027
+ assert_in_delta(0.0, method.wait_time, 0.05)
3028
+ assert_in_delta(0.0, method.self_time, 0.05)
3029
+ assert_in_delta(0.0, method.children_time, 0.05)
3030
+
3031
+ method = methods[8]
3032
+ assert_equal('Class#new', method.full_name)
3033
+ assert_in_delta(0.0, method.total_time, 0.01)
3034
+ assert_in_delta(0.0, method.wait_time, 0.01)
3035
+ assert_in_delta(0.0, method.self_time, 0.01)
3036
+ assert_in_delta(0.0, method.children_time, 0.01)
3037
+
3038
+ method = methods[9]
3039
+ assert_equal('BasicObject#initialize', method.full_name)
3040
+ assert_in_delta(0.0, method.total_time, 0.05)
3041
+ assert_in_delta(0.0, method.wait_time, 0.05)
3042
+ assert_in_delta(0.0, method.self_time, 0.05)
3043
+ assert_in_delta(0.0, method.children_time, 0.05)
3044
+ end
3045
+
3046
+ def test_instance_methods_busy_threaded
3047
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
3048
+ background_thread = Thread.new do
3049
+ RubyProf::C1.new.busy_wait
3050
+ end
3051
+ background_thread.join
3052
+ end
3053
+
3054
+ assert_equal(2, result.threads.count)
3055
+
3056
+ thread = result.threads.first
3057
+ assert_in_delta(0.2, thread.total_time, 0.05)
3058
+
3059
+ methods = result.threads.first.methods.sort.reverse
3060
+ assert_equal(4, methods.length)
3061
+
3062
+ # Check times
3063
+ method = methods[0]
3064
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
3065
+ assert_in_delta(0.2, method.total_time, 0.05)
3066
+ assert_in_delta(0.0, method.wait_time, 0.05)
3067
+ assert_in_delta(0.0, method.self_time, 0.05)
3068
+ assert_in_delta(0.2, method.children_time, 0.05)
3069
+
3070
+ method = methods[1]
3071
+ assert_equal('Thread#join', method.full_name)
3072
+ assert_in_delta(0.2, method.total_time, 0.05)
3073
+ assert_in_delta(0.2, method.wait_time, 0.05)
3074
+ assert_in_delta(0.0, method.self_time, 0.05)
3075
+ assert_in_delta(0.0, method.children_time, 0.05)
3076
+
3077
+ method = methods[2]
3078
+ assert_equal('<Class::Thread>#new', method.full_name)
3079
+ assert_in_delta(0.0, method.total_time, 0.05)
3080
+ assert_in_delta(0.0, method.wait_time, 0.05)
3081
+ assert_in_delta(0.0, method.self_time, 0.05)
3082
+ assert_in_delta(0.0, method.children_time, 0.05)
3083
+
3084
+ method = methods[3]
3085
+ assert_equal('Thread#initialize', method.full_name)
3086
+ assert_in_delta(0.0, method.total_time, 0.05)
3087
+ assert_in_delta(0.0, method.wait_time, 0.05)
3088
+ assert_in_delta(0.0, method.self_time, 0.05)
3089
+ assert_in_delta(0.0, method.children_time, 0.05)
3090
+
3091
+ thread = result.threads.last
3092
+ assert_in_delta(0.2, thread.total_time, 0.05)
3093
+
3094
+ methods = result.threads.first.methods.sort.reverse
3095
+ assert_equal(4, methods.length)
3096
+
3097
+ methods = result.threads.last.methods.sort.reverse
3098
+ assert_equal(7, methods.length)
3099
+
3100
+ # Check times
3101
+ method = methods[0]
3102
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
3103
+ assert_in_delta(0.2, method.total_time, 0.05)
3104
+ assert_in_delta(0.0, method.wait_time, 0.05)
3105
+ assert_in_delta(0.0, method.self_time, 0.05)
3106
+ assert_in_delta(0.2, method.children_time, 0.05)
3107
+
3108
+ method = methods[1]
3109
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
3110
+ assert_in_delta(0.2, method.total_time, 0.05)
3111
+ assert_in_delta(0.0, method.wait_time, 0.05)
3112
+ assert_in_delta(0.1, method.self_time, 0.05)
3113
+ assert_in_delta(0.1, method.children_time, 0.05)
3114
+
3115
+ method = methods[2]
3116
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
3117
+ assert_in_delta(0.03, method.total_time, 0.05)
3118
+ assert_in_delta(0.0, method.wait_time, 0.05)
3119
+ assert_in_delta(0.03, method.self_time, 0.05)
3120
+ assert_in_delta(0.0, method.children_time, 0.05)
3121
+
3122
+ method = methods[3]
3123
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
3124
+ assert_in_delta(0.0, method.total_time, 0.05)
3125
+ assert_in_delta(0.0, method.wait_time, 0.05)
3126
+ assert_in_delta(0.0, method.self_time, 0.05)
3127
+ assert_in_delta(0.0, method.children_time, 0.05)
3128
+
3129
+ method = methods[4]
3130
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
3131
+ assert_in_delta(0.0, method.total_time, 0.05)
3132
+ assert_in_delta(0.0, method.wait_time, 0.05)
3133
+ assert_in_delta(0.0, method.self_time, 0.05)
3134
+ assert_in_delta(0.0, method.children_time, 0.05)
3135
+
3136
+ method = methods[5]
3137
+ assert_equal('Class#new', method.full_name)
3138
+ assert_in_delta(0.0, method.total_time, 0.05)
3139
+ assert_in_delta(0.0, method.wait_time, 0.05)
3140
+ assert_in_delta(0.0, method.self_time, 0.05)
3141
+ assert_in_delta(0.0, method.children_time, 0.05)
3142
+
3143
+ method = methods[6]
3144
+ assert_equal('BasicObject#initialize', method.full_name)
3145
+ assert_in_delta(0.0, method.total_time, 0.05)
3146
+ assert_in_delta(0.0, method.wait_time, 0.05)
3147
+ assert_in_delta(0.0, method.self_time, 0.05)
3148
+ assert_in_delta(0.0, method.children_time, 0.05)
3149
+ end
3150
+
3151
+ def test_module_methods_sleep
3152
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
3153
+ RubyProf::C2.sleep_wait
3154
+ end
3155
+
3156
+ thread = result.threads.first
3157
+ assert_in_delta(0.0, thread.total_time, 0.05)
3158
+
3159
+ methods = result.threads.first.methods.sort.reverse
3160
+ assert_equal(3, methods.length)
3161
+
3162
+ # Check times
3163
+ method = methods[0]
3164
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
3165
+ assert_in_delta(0.0, method.total_time, 0.05)
3166
+ assert_in_delta(0.0, method.wait_time, 0.05)
3167
+ assert_in_delta(0.0, method.self_time, 0.05)
3168
+ assert_in_delta(0.0, method.children_time, 0.05)
3169
+
3170
+ method = methods[1]
3171
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
3172
+ assert_in_delta(0.0, method.total_time, 0.05)
3173
+ assert_in_delta(0.0, method.wait_time, 0.05)
3174
+ assert_in_delta(0.0, method.self_time, 0.05)
3175
+ assert_in_delta(0.0, method.children_time, 0.05)
3176
+
3177
+ method = methods[2]
3178
+ assert_equal('Kernel#sleep', method.full_name)
3179
+ assert_in_delta(0.0, method.total_time, 0.05)
3180
+ assert_in_delta(0.0, method.wait_time, 0.05)
3181
+ assert_in_delta(0.0, method.self_time, 0.05)
3182
+ assert_in_delta(0.0, method.children_time, 0.05)
3183
+ end
3184
+
3185
+ def test_module_methods_busy
3186
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
3187
+ RubyProf::C2.busy_wait
3188
+ end
3189
+
3190
+ thread = result.threads.first
3191
+ assert_in_delta(0.3, thread.total_time, 0.05)
3192
+
3193
+ methods = result.threads.first.methods.sort.reverse
3194
+ assert_equal(5, methods.length)
3195
+
3196
+ # Check times
3197
+ method = methods[0]
3198
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
3199
+ assert_in_delta(0.3, method.total_time, 0.05)
3200
+ assert_in_delta(0.0, method.wait_time, 0.05)
3201
+ assert_in_delta(0.0, method.self_time, 0.05)
3202
+ assert_in_delta(0.3, method.children_time, 0.05)
3203
+
3204
+ method = methods[1]
3205
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
3206
+ assert_in_delta(0.3, method.total_time, 0.05)
3207
+ assert_in_delta(0.0, method.wait_time, 0.05)
3208
+ assert_in_delta(0.15, method.self_time, 0.05)
3209
+ assert_in_delta(0.15, method.children_time, 0.05)
3210
+
3211
+ method = methods[2]
3212
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
3213
+ assert_in_delta(0.05, method.total_time, 0.05)
3214
+ assert_in_delta(0.0, method.wait_time, 0.05)
3215
+ assert_in_delta(0.05, method.self_time, 0.05)
3216
+ assert_in_delta(0.0, method.children_time, 0.05)
3217
+ end
3218
+
3219
+ def test_module_instance_methods_sleep
3220
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
3221
+ RubyProf::C2.new.sleep_wait
3222
+ end
3223
+
3224
+ thread = result.threads.first
3225
+ assert_in_delta(0.0, thread.total_time, 0.05)
3226
+
3227
+ methods = result.threads.first.methods.sort.reverse
3228
+ assert_equal(5, methods.length)
3229
+
3230
+ # Check times
3231
+ method = methods[0]
3232
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
3233
+ assert_in_delta(0.0, method.total_time, 0.05)
3234
+ assert_in_delta(0.0, method.wait_time, 0.05)
3235
+ assert_in_delta(0.0, method.self_time, 0.05)
3236
+ assert_in_delta(0.0, method.children_time, 0.05)
3237
+
3238
+ method = methods[1]
3239
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
3240
+ assert_in_delta(0.0, method.total_time, 0.05)
3241
+ assert_in_delta(0.0, method.wait_time, 0.05)
3242
+ assert_in_delta(0.0, method.self_time, 0.05)
3243
+ assert_in_delta(0.0, method.children_time, 0.05)
3244
+
3245
+ method = methods[2]
3246
+ assert_equal('Class#new', method.full_name)
3247
+ assert_in_delta(0.0, method.total_time, 0.05)
3248
+ assert_in_delta(0.0, method.wait_time, 0.05)
3249
+ assert_in_delta(0.0, method.self_time, 0.05)
3250
+ assert_in_delta(0.0, method.children_time, 0.05)
3251
+
3252
+ method = methods[3]
3253
+ assert_equal('Kernel#sleep', method.full_name)
3254
+ assert_in_delta(0.0, method.total_time, 0.05)
3255
+ assert_in_delta(0.0, method.wait_time, 0.05)
3256
+ assert_in_delta(0.0, method.self_time, 0.05)
3257
+ assert_in_delta(0.0, method.children_time, 0.05)
3258
+
3259
+ method = methods[4]
3260
+ assert_equal('BasicObject#initialize', method.full_name)
3261
+ assert_in_delta(0.0, method.total_time, 0.05)
3262
+ assert_in_delta(0.0, method.wait_time, 0.05)
3263
+ assert_in_delta(0.0, method.self_time, 0.05)
3264
+ assert_in_delta(0.0, method.children_time, 0.05)
3265
+ end
3266
+
3267
+ def test_module_instance_methods_busy
3268
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
3269
+ RubyProf::C2.new.busy_wait
3270
+ end
3271
+
3272
+ thread = result.threads.first
3273
+ assert_in_delta(0.3, thread.total_time, 0.05)
3274
+
3275
+ methods = result.threads.first.methods.sort.reverse
3276
+ assert_equal(7, methods.length)
3277
+
3278
+ # Check times
3279
+ method = methods[0]
3280
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
3281
+ assert_in_delta(0.3, method.total_time, 0.05)
3282
+ assert_in_delta(0.0, method.wait_time, 0.05)
3283
+ assert_in_delta(0.0, method.self_time, 0.05)
3284
+ assert_in_delta(0.3, method.children_time, 0.05)
3285
+
3286
+ method = methods[1]
3287
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
3288
+ assert_in_delta(0.3, method.total_time, 0.05)
3289
+ assert_in_delta(0.0, method.wait_time, 0.05)
3290
+ assert_in_delta(0.15, method.self_time, 0.05)
3291
+ assert_in_delta(0.15, method.children_time, 0.05)
3292
+
3293
+ method = methods[2]
3294
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
3295
+ assert_in_delta(0.05, method.total_time, 0.05)
3296
+ assert_in_delta(0.0, method.wait_time, 0.05)
3297
+ assert_in_delta(0.05, method.self_time, 0.05)
3298
+ assert_in_delta(0.0, method.children_time, 0.05)
3299
+
3300
+ method = methods[3]
3301
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
3302
+ assert_in_delta(0.0, method.total_time, 0.05)
3303
+ assert_in_delta(0.0, method.wait_time, 0.05)
3304
+ assert_in_delta(0.0, method.self_time, 0.05)
3305
+ assert_in_delta(0.0, method.children_time, 0.05)
3306
+
3307
+ method = methods[4]
3308
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
3309
+ assert_in_delta(0.0, method.total_time, 0.05)
3310
+ assert_in_delta(0.0, method.wait_time, 0.05)
3311
+ assert_in_delta(0.0, method.self_time, 0.05)
3312
+ assert_in_delta(0.0, method.children_time, 0.05)
3313
+
3314
+ method = methods[5]
3315
+ assert_equal('Class#new', method.full_name)
3316
+ assert_in_delta(0.0, method.total_time, 0.05)
3317
+ assert_in_delta(0.0, method.wait_time, 0.05)
3318
+ assert_in_delta(0.0, method.self_time, 0.05)
3319
+ assert_in_delta(0.0, method.children_time, 0.05)
3320
+
3321
+ method = methods[6]
3322
+ assert_equal('BasicObject#initialize', method.full_name)
3323
+ assert_in_delta(0.0, method.total_time, 0.05)
3324
+ assert_in_delta(0.0, method.wait_time, 0.05)
3325
+ assert_in_delta(0.0, method.self_time, 0.05)
3326
+ assert_in_delta(0.0, method.children_time, 0.05)
3327
+ end
3328
+ end
3329
+ end
3330
+ end