ruby-prof 1.4.3 → 1.6.3

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