ruby-prof 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -395,21 +395,12 @@ class MeasureWallTimeTest < TestCase
395
395
  assert_in_delta(0.3, methods[2].self_time, 0.03)
396
396
  assert_in_delta(0.0, methods[2].children_time, 0.03)
397
397
 
398
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
399
- method = methods.detect {|a_method| a_method.full_name == '<Class::RubyProf::C3>#instance'}
400
- assert_equal('<Class::RubyProf::C3>#instance', method.full_name)
401
- assert_in_delta(0.0, method.total_time, 0.03)
402
- assert_in_delta(0.0, method.wait_time, 0.03)
403
- assert_in_delta(0.0, method.self_time, 0.03)
404
- assert_in_delta(0.0, method.children_time, 0.03)
405
- else
406
- method = methods.detect {|a_method| a_method.full_name == 'Singleton::SingletonClassMethods#instance'}
407
- assert_equal('Singleton::SingletonClassMethods#instance', method.full_name)
408
- assert_in_delta(0.0, method.total_time, 0.03)
409
- assert_in_delta(0.0, method.wait_time, 0.03)
410
- assert_in_delta(0.0, method.self_time, 0.03)
411
- assert_in_delta(0.0, method.children_time, 0.03)
412
- end
398
+ method = methods.detect {|a_method| a_method.full_name == 'Singleton::SingletonClassMethods#instance'}
399
+ assert_equal('Singleton::SingletonClassMethods#instance', method.full_name)
400
+ assert_in_delta(0.0, method.total_time, 0.03)
401
+ assert_in_delta(0.0, method.wait_time, 0.03)
402
+ assert_in_delta(0.0, method.self_time, 0.03)
403
+ assert_in_delta(0.0, method.children_time, 0.03)
413
404
 
414
405
  method = methods.detect {|a_method| a_method.full_name == 'Thread::Mutex#synchronize'}
415
406
  assert_equal('Thread::Mutex#synchronize', method.full_name)
@@ -19,8 +19,8 @@ class PrinterCallTreeTest < TestCase
19
19
  def test_call_tree_string
20
20
  printer = RubyProf::CallTreePrinter.new(@result)
21
21
 
22
- printer.print(:profile => "lolcat", :path => Dir.tmpdir)
23
- main_output_file_name = File.join(Dir.tmpdir, "lolcat.callgrind.out.#{$$}")
22
+ printer.print(:path => Dir.tmpdir)
23
+ main_output_file_name = File.join(Dir.tmpdir, "callgrind.out.#{$$}")
24
24
  assert(File.exist?(main_output_file_name))
25
25
  output = File.read(main_output_file_name)
26
26
  assert_match(/fn=Object::find_primes/i, output)
@@ -46,64 +46,158 @@ class RecursiveTest < TestCase
46
46
  end
47
47
 
48
48
  methods = result.threads.first.methods.sort.reverse
49
- assert_equal(3, methods.length)
50
-
51
- # Method 0: RecursiveTest#test_simple
52
- method = methods[0]
53
- assert_equal('RecursiveTest#test_simple', method.full_name)
54
- assert_equal(1, method.called)
55
- refute(method.recursive?)
56
- assert_in_delta(2, method.total_time, 0.1)
57
- assert_in_delta(0, method.self_time, 0.01)
58
- assert_in_delta(0, method.wait_time, 0.01)
59
- assert_in_delta(2, method.children_time, 0.1)
60
-
61
- assert_equal(0, method.call_trees.callers.length)
62
-
63
- assert_equal(1, method.call_trees.callees.length)
64
- call_tree = method.call_trees.callees[0]
65
- assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
66
-
67
- # Method 1: SimpleRecursion#simple
68
- method = methods[1]
69
- assert_equal('SimpleRecursion#simple', method.full_name)
70
- assert_equal(2, method.called)
71
- assert(method.recursive?)
72
- assert_in_delta(2, method.total_time, 0.1)
73
- assert_in_delta(0, method.self_time, 0.1)
74
- assert_in_delta(0, method.wait_time, 0.1)
75
- assert_in_delta(2, method.children_time, 0.1)
76
-
77
- assert_equal(2, method.call_trees.callers.length)
78
- call_tree = method.call_trees.callers[0]
79
- assert_equal('RecursiveTest#test_simple', call_tree.parent.target.full_name)
80
-
81
- call_tree = method.call_trees.callers[1]
82
- assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
83
-
84
- assert_equal(2, method.call_trees.callees.length)
85
- call_tree = method.call_trees.callees[0]
86
- assert_equal('Kernel#sleep', call_tree.target.full_name)
87
-
88
- call_tree = method.call_trees.callees[1]
89
- assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
90
-
91
- # Method 2: Kernel#sleep
92
- method = methods[2]
93
- assert_equal('Kernel#sleep', method.full_name)
94
- assert_equal(2, method.called)
95
- refute(method.recursive?)
96
- assert_in_delta(2, method.total_time, 0.1)
97
- assert_in_delta(2, method.self_time, 0.1)
98
- assert_in_delta(0, method.wait_time, 0.1)
99
- assert_in_delta(0, method.children_time, 0.1)
100
-
101
- assert_equal(1, method.call_trees.callers.length)
102
- call_tree = method.call_trees.callers[0]
103
- assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
104
- assert_equal(0, method.call_trees.callees.length)
105
-
106
- assert_equal(0, method.call_trees.callees.length)
49
+
50
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
51
+ assert_equal(3, methods.length)
52
+
53
+ # Method 0: RecursiveTest#test_simple
54
+ method = methods[0]
55
+ assert_equal('RecursiveTest#test_simple', method.full_name)
56
+ assert_equal(1, method.called)
57
+ refute(method.recursive?)
58
+ assert_in_delta(2, method.total_time, 0.1)
59
+ assert_in_delta(0, method.self_time, 0.01)
60
+ assert_in_delta(0, method.wait_time, 0.01)
61
+ assert_in_delta(2, method.children_time, 0.1)
62
+
63
+ assert_equal(0, method.call_trees.callers.length)
64
+
65
+ assert_equal(1, method.call_trees.callees.length)
66
+ call_tree = method.call_trees.callees[0]
67
+ assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
68
+
69
+ # Method 1: SimpleRecursion#simple
70
+ method = methods[1]
71
+ assert_equal('SimpleRecursion#simple', method.full_name)
72
+ assert_equal(2, method.called)
73
+ assert(method.recursive?)
74
+ assert_in_delta(2, method.total_time, 0.1)
75
+ assert_in_delta(0, method.self_time, 0.1)
76
+ assert_in_delta(0, method.wait_time, 0.1)
77
+ assert_in_delta(2, method.children_time, 0.1)
78
+
79
+ assert_equal(2, method.call_trees.callers.length)
80
+ call_tree = method.call_trees.callers[0]
81
+ assert_equal('RecursiveTest#test_simple', call_tree.parent.target.full_name)
82
+
83
+ call_tree = method.call_trees.callers[1]
84
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
85
+
86
+ assert_equal(2, method.call_trees.callees.length)
87
+ call_tree = method.call_trees.callees[0]
88
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
89
+
90
+ call_tree = method.call_trees.callees[1]
91
+ assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
92
+
93
+ # Method 2: Kernel#sleep
94
+ method = methods[2]
95
+ assert_equal('Kernel#sleep', method.full_name)
96
+ assert_equal(2, method.called)
97
+ refute(method.recursive?)
98
+
99
+ assert_in_delta(2, method.total_time, 0.1)
100
+ assert_in_delta(2, method.self_time, 0.1)
101
+ assert_in_delta(0, method.wait_time, 0.1)
102
+ assert_in_delta(0, method.children_time, 0.1)
103
+
104
+ assert_equal(1, method.call_trees.callers.length)
105
+ call_tree = method.call_trees.callers[0]
106
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
107
+ assert_equal(0, method.call_trees.callees.length)
108
+
109
+ assert_equal(0, method.call_trees.callees.length)
110
+ else
111
+ assert_equal(5, methods.length)
112
+
113
+ # Method 0: RecursiveTest#test_simple
114
+ method = methods[0]
115
+ assert_equal('RecursiveTest#test_simple', method.full_name)
116
+ assert_equal(1, method.called)
117
+ refute(method.recursive?)
118
+ assert_in_delta(2, method.total_time, 0.1)
119
+ assert_in_delta(0, method.self_time, 0.01)
120
+ assert_in_delta(0, method.wait_time, 0.01)
121
+ assert_in_delta(2, method.children_time, 0.1)
122
+
123
+ assert_equal(0, method.call_trees.callers.length)
124
+
125
+ assert_equal(1, method.call_trees.callees.length)
126
+ call_tree = method.call_trees.callees[0]
127
+ assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
128
+
129
+ # Method 1: SimpleRecursion#simple
130
+ method = methods[1]
131
+ assert_equal('SimpleRecursion#simple', method.full_name)
132
+ assert_equal(2, method.called)
133
+ assert(method.recursive?)
134
+ assert_in_delta(2, method.total_time, 0.1)
135
+ assert_in_delta(0, method.self_time, 0.1)
136
+ assert_in_delta(0, method.wait_time, 0.1)
137
+ assert_in_delta(2, method.children_time, 0.1)
138
+
139
+ assert_equal(2, method.call_trees.callers.length)
140
+ call_tree = method.call_trees.callers[0]
141
+ assert_equal('RecursiveTest#test_simple', call_tree.parent.target.full_name)
142
+
143
+ call_tree = method.call_trees.callers[1]
144
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
145
+
146
+ assert_equal(4, method.call_trees.callees.length)
147
+ call_tree = method.call_trees.callees[0]
148
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
149
+
150
+ call_tree = method.call_trees.callees[1]
151
+ assert_equal('Integer#==', call_tree.target.full_name)
152
+
153
+ call_tree = method.call_trees.callees[2]
154
+ assert_equal('Integer#-', call_tree.target.full_name)
155
+
156
+ call_tree = method.call_trees.callees[3]
157
+ assert_equal('SimpleRecursion#simple', call_tree.target.full_name)
158
+
159
+ # Method 2: Kernel#sleep
160
+ method = methods[2]
161
+ assert_equal('Kernel#sleep', method.full_name)
162
+ assert_equal(2, method.called)
163
+ refute(method.recursive?)
164
+
165
+ assert_in_delta(2, method.total_time, 0.1)
166
+ assert_in_delta(2, method.self_time, 0.1)
167
+ assert_in_delta(0, method.wait_time, 0.1)
168
+ assert_in_delta(0, method.children_time, 0.1)
169
+
170
+ assert_equal(1, method.call_trees.callers.length)
171
+ call_tree = method.call_trees.callers[0]
172
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
173
+ assert_equal(0, method.call_trees.callees.length)
174
+
175
+ assert_equal(0, method.call_trees.callees.length)
176
+
177
+ # Method 3
178
+ method = methods[3]
179
+ assert_equal('Integer#==', method.full_name)
180
+ assert_equal(2, method.called)
181
+ refute(method.recursive?)
182
+
183
+ assert_equal(1, method.call_trees.callers.length)
184
+ call_tree = method.call_trees.callers[0]
185
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
186
+
187
+ assert_equal(0, method.call_trees.callees.length)
188
+
189
+ # Method 4
190
+ method = methods[4]
191
+ assert_equal('Integer#-', method.full_name)
192
+ assert_equal(1, method.called)
193
+ refute(method.recursive?)
194
+
195
+ assert_equal(1, method.call_trees.callers.length)
196
+ call_tree = method.call_trees.callers[0]
197
+ assert_equal('SimpleRecursion#simple', call_tree.parent.target.full_name)
198
+
199
+ assert_equal(0, method.call_trees.callees.length)
200
+ end
107
201
  end
108
202
 
109
203
  def test_cycle
@@ -112,95 +206,225 @@ class RecursiveTest < TestCase
112
206
  end
113
207
 
114
208
  methods = result.threads.first.methods.sort.reverse
115
- assert_equal(5, methods.length)
116
-
117
- method = methods[0]
118
- assert_equal('RecursiveTest#test_cycle', method.full_name)
119
- assert_equal(1, method.called)
120
- refute(method.recursive?)
121
- assert_in_delta(5, method.total_time, 0.1)
122
- assert_in_delta(0, method.self_time, 0.01)
123
- assert_in_delta(0, method.wait_time, 0.01)
124
- assert_in_delta(5, method.children_time, 0.1)
125
-
126
- assert_equal(0, method.call_trees.callers.length)
127
-
128
- assert_equal(1, method.call_trees.callees.length)
129
- call_tree = method.call_trees.callees[0]
130
- assert_equal('SimpleRecursion#render', call_tree.target.full_name)
131
-
132
- method = methods[1]
133
- assert_equal('SimpleRecursion#render', method.full_name)
134
- assert_equal(1, method.called)
135
- refute(method.recursive?)
136
- assert_in_delta(5, method.total_time, 0.1)
137
- assert_in_delta(0, method.self_time, 0.01)
138
- assert_in_delta(0, method.wait_time, 0.01)
139
- assert_in_delta(5, method.children_time, 0.1)
140
-
141
- assert_equal(1, method.call_trees.callers.length)
142
- call_tree = method.call_trees.callers[0]
143
- assert_equal('RecursiveTest#test_cycle', call_tree.parent.target.full_name)
144
-
145
- assert_equal(1, method.call_trees.callees.length)
146
- call_tree = method.call_trees.callees[0]
147
- assert_equal('Integer#times', call_tree.target.full_name)
148
-
149
- method = methods[2]
150
- assert_equal('Integer#times', method.full_name)
151
- assert_equal(2, method.called)
152
- assert(method.recursive?)
153
- assert_in_delta(5, method.total_time, 0.1)
154
- assert_in_delta(0, method.self_time, 0.1)
155
- assert_in_delta(0, method.wait_time, 0.1)
156
- assert_in_delta(5, method.children_time, 0.1)
157
-
158
- assert_equal(2, method.call_trees.callers.length)
159
- call_tree = method.call_trees.callers[0]
160
- assert_equal('SimpleRecursion#render', call_tree.parent.target.full_name)
161
-
162
- call_tree = method.call_trees.callers[1]
163
- assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
164
-
165
- assert_equal(1, method.call_trees.callees.length)
166
- call_tree = method.call_trees.callees[0]
167
- assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
168
-
169
- method = methods[3]
170
- assert_equal('SimpleRecursion#render_partial', method.full_name)
171
- assert_equal(5, method.called)
172
- assert(method.recursive?)
173
- assert_in_delta(5, method.total_time, 0.1)
174
- assert_in_delta(0, method.self_time, 0.1)
175
- assert_in_delta(0, method.wait_time, 0.01)
176
- assert_in_delta(5, method.children_time, 0.05)
177
-
178
- assert_equal(2, method.call_trees.callers.length)
179
- call_tree = method.call_trees.callers[0]
180
- assert_equal('Integer#times', call_tree.parent.target.full_name)
181
-
182
- call_tree = method.call_trees.callers[1]
183
- assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
184
-
185
- assert_equal(3, method.call_trees.callees.length)
186
- call_tree = method.call_trees.callees[0]
187
- assert_equal('Kernel#sleep', call_tree.target.full_name)
188
-
189
- call_tree = method.call_trees.callees[1]
190
- assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
191
-
192
- call_tree = method.call_trees.callees[2]
193
- assert_equal('Integer#times', call_tree.target.full_name)
194
-
195
- method = methods[4]
196
- assert_equal('Kernel#sleep', method.full_name)
197
- assert_equal(5, method.called)
198
- refute(method.recursive?)
199
- assert_in_delta(5, method.total_time, 0.1)
200
- assert_in_delta(5, method.self_time, 0.1)
201
- assert_in_delta(0, method.wait_time, 0.01)
202
- assert_in_delta(0, method.children_time, 0.01)
203
-
204
- assert_equal(0, method.call_trees.callees.length)
209
+
210
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
211
+ assert_equal(5, methods.length)
212
+
213
+ # Method 0
214
+ method = methods[0]
215
+ assert_equal('RecursiveTest#test_cycle', method.full_name)
216
+ assert_equal(1, method.called)
217
+ refute(method.recursive?)
218
+ assert_in_delta(5, method.total_time, 0.1)
219
+ assert_in_delta(0, method.self_time, 0.01)
220
+ assert_in_delta(0, method.wait_time, 0.01)
221
+ assert_in_delta(5, method.children_time, 0.1)
222
+
223
+ assert_equal(0, method.call_trees.callers.length)
224
+
225
+ assert_equal(1, method.call_trees.callees.length)
226
+ call_tree = method.call_trees.callees[0]
227
+ assert_equal('SimpleRecursion#render', call_tree.target.full_name)
228
+
229
+ # Method 1
230
+ method = methods[1]
231
+ assert_equal('SimpleRecursion#render', method.full_name)
232
+ assert_equal(1, method.called)
233
+ refute(method.recursive?)
234
+ assert_in_delta(5, method.total_time, 0.1)
235
+ assert_in_delta(0, method.self_time, 0.01)
236
+ assert_in_delta(0, method.wait_time, 0.01)
237
+ assert_in_delta(5, method.children_time, 0.1)
238
+
239
+ assert_equal(1, method.call_trees.callers.length)
240
+ call_tree = method.call_trees.callers[0]
241
+ assert_equal('RecursiveTest#test_cycle', call_tree.parent.target.full_name)
242
+
243
+ assert_equal(1, method.call_trees.callees.length)
244
+ call_tree = method.call_trees.callees[0]
245
+ assert_equal('Integer#times', call_tree.target.full_name)
246
+
247
+ # Method 2
248
+ method = methods[2]
249
+ assert_equal('Integer#times', method.full_name)
250
+ assert_equal(2, method.called)
251
+ assert(method.recursive?)
252
+ assert_in_delta(5, method.total_time, 0.1)
253
+ assert_in_delta(0, method.self_time, 0.1)
254
+ assert_in_delta(0, method.wait_time, 0.1)
255
+ assert_in_delta(5, method.children_time, 0.1)
256
+
257
+ assert_equal(2, method.call_trees.callers.length)
258
+ call_tree = method.call_trees.callers[0]
259
+ assert_equal('SimpleRecursion#render', call_tree.parent.target.full_name)
260
+
261
+ call_tree = method.call_trees.callers[1]
262
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
263
+
264
+ assert_equal(1, method.call_trees.callees.length)
265
+ call_tree = method.call_trees.callees[0]
266
+ assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
267
+
268
+ # Method 3
269
+ method = methods[3]
270
+ assert_equal('SimpleRecursion#render_partial', method.full_name)
271
+ assert_equal(5, method.called)
272
+ assert(method.recursive?)
273
+ assert_in_delta(5, method.total_time, 0.1)
274
+ assert_in_delta(0, method.self_time, 0.1)
275
+ assert_in_delta(0, method.wait_time, 0.01)
276
+ assert_in_delta(5, method.children_time, 0.05)
277
+
278
+ assert_equal(2, method.call_trees.callers.length)
279
+ call_tree = method.call_trees.callers[0]
280
+ assert_equal('Integer#times', call_tree.parent.target.full_name)
281
+
282
+ call_tree = method.call_trees.callers[1]
283
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
284
+
285
+ assert_equal(3, method.call_trees.callees.length)
286
+ call_tree = method.call_trees.callees[0]
287
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
288
+
289
+ call_tree = method.call_trees.callees[1]
290
+ assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
291
+
292
+ call_tree = method.call_trees.callees[2]
293
+ assert_equal('Integer#times', call_tree.target.full_name)
294
+
295
+ # Method 4
296
+ method = methods[4]
297
+ assert_equal('Kernel#sleep', method.full_name)
298
+ assert_equal(5, method.called)
299
+ refute(method.recursive?)
300
+ assert_in_delta(5, method.total_time, 0.1)
301
+ assert_in_delta(5, method.self_time, 0.1)
302
+ assert_in_delta(0, method.wait_time, 0.01)
303
+ assert_in_delta(0, method.children_time, 0.01)
304
+
305
+ assert_equal(1, method.call_trees.callers.length)
306
+ call_tree = method.call_trees.callers[0]
307
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
308
+
309
+ assert_equal(0, method.call_trees.callees.length)
310
+ else
311
+ assert_equal(6, methods.length)
312
+
313
+ # Method 0
314
+ method = methods[0]
315
+ assert_equal('RecursiveTest#test_cycle', method.full_name)
316
+ assert_equal(1, method.called)
317
+ refute(method.recursive?)
318
+ assert_in_delta(5, method.total_time, 0.1)
319
+ assert_in_delta(0, method.self_time, 0.01)
320
+ assert_in_delta(0, method.wait_time, 0.01)
321
+ assert_in_delta(5, method.children_time, 0.1)
322
+
323
+ assert_equal(0, method.call_trees.callers.length)
324
+
325
+ assert_equal(1, method.call_trees.callees.length)
326
+ call_tree = method.call_trees.callees[0]
327
+ assert_equal('SimpleRecursion#render', call_tree.target.full_name)
328
+
329
+ # Method 1
330
+ method = methods[1]
331
+ assert_equal('SimpleRecursion#render', method.full_name)
332
+ assert_equal(1, method.called)
333
+ refute(method.recursive?)
334
+ assert_in_delta(5, method.total_time, 0.1)
335
+ assert_in_delta(0, method.self_time, 0.01)
336
+ assert_in_delta(0, method.wait_time, 0.01)
337
+ assert_in_delta(5, method.children_time, 0.1)
338
+
339
+ assert_equal(1, method.call_trees.callers.length)
340
+ call_tree = method.call_trees.callers[0]
341
+ assert_equal('RecursiveTest#test_cycle', call_tree.parent.target.full_name)
342
+
343
+ assert_equal(1, method.call_trees.callees.length)
344
+ call_tree = method.call_trees.callees[0]
345
+ assert_equal('Integer#times', call_tree.target.full_name)
346
+
347
+ # Method 2
348
+ method = methods[2]
349
+ assert_equal('Integer#times', method.full_name)
350
+ assert_equal(2, method.called)
351
+ assert(method.recursive?)
352
+ assert_in_delta(5, method.total_time, 0.1)
353
+ assert_in_delta(0, method.self_time, 0.1)
354
+ assert_in_delta(0, method.wait_time, 0.1)
355
+ assert_in_delta(5, method.children_time, 0.1)
356
+
357
+ assert_equal(2, method.call_trees.callers.length)
358
+ call_tree = method.call_trees.callers[0]
359
+ assert_equal('SimpleRecursion#render', call_tree.parent.target.full_name)
360
+
361
+ call_tree = method.call_trees.callers[1]
362
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
363
+
364
+ assert_equal(2, method.call_trees.callees.length)
365
+ call_tree = method.call_trees.callees[0]
366
+ assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
367
+ call_tree = method.call_trees.callees[1]
368
+ assert_equal('Integer#+', call_tree.target.full_name)
369
+
370
+ # Method 3
371
+ method = methods[3]
372
+ assert_equal('SimpleRecursion#render_partial', method.full_name)
373
+ assert_equal(5, method.called)
374
+ assert(method.recursive?)
375
+ assert_in_delta(5, method.total_time, 0.1)
376
+ assert_in_delta(0, method.self_time, 0.1)
377
+ assert_in_delta(0, method.wait_time, 0.01)
378
+ assert_in_delta(5, method.children_time, 0.05)
379
+
380
+ assert_equal(2, method.call_trees.callers.length)
381
+ call_tree = method.call_trees.callers[0]
382
+ assert_equal('Integer#times', call_tree.parent.target.full_name)
383
+
384
+ call_tree = method.call_trees.callers[1]
385
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
386
+
387
+ assert_equal(3, method.call_trees.callees.length)
388
+ call_tree = method.call_trees.callees[0]
389
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
390
+
391
+ call_tree = method.call_trees.callees[1]
392
+ assert_equal('SimpleRecursion#render_partial', call_tree.target.full_name)
393
+
394
+ call_tree = method.call_trees.callees[2]
395
+ assert_equal('Integer#times', call_tree.target.full_name)
396
+
397
+ # Method 4
398
+ method = methods[4]
399
+ assert_equal('Kernel#sleep', method.full_name)
400
+ assert_equal(5, method.called)
401
+ refute(method.recursive?)
402
+ assert_in_delta(5, method.total_time, 0.1)
403
+ assert_in_delta(5, method.self_time, 0.1)
404
+ assert_in_delta(0, method.wait_time, 0.01)
405
+ assert_in_delta(0, method.children_time, 0.01)
406
+
407
+ assert_equal(1, method.call_trees.callers.length)
408
+ call_tree = method.call_trees.callers[0]
409
+ assert_equal('SimpleRecursion#render_partial', call_tree.parent.target.full_name)
410
+
411
+ assert_equal(0, method.call_trees.callees.length)
412
+
413
+ # Method 5
414
+ method = methods[5]
415
+ assert_equal('Integer#+', method.full_name)
416
+ assert_equal(2, method.called)
417
+ refute(method.recursive?)
418
+ assert_in_delta(0, method.total_time, 0.1)
419
+ assert_in_delta(0, method.self_time, 0.1)
420
+ assert_in_delta(0, method.wait_time, 0.01)
421
+ assert_in_delta(0, method.children_time, 0.01)
422
+
423
+ assert_equal(1, method.call_trees.callers.length)
424
+ call_tree = method.call_trees.callers[0]
425
+ assert_equal('Integer#times', call_tree.parent.target.full_name)
426
+
427
+ assert_equal(0, method.call_trees.callees.length)
428
+ end
205
429
  end
206
430
  end
data/test/test_helper.rb CHANGED
@@ -1,17 +1,13 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'bundler/setup'
4
- require 'minitest/autorun'
4
+ require 'ruby-prof'
5
5
 
6
6
  # Disable minitest parallel tests. The problem is the thread switching will change test results
7
7
  # (self vs wait time)
8
- if Gem::Version.new(Minitest::VERSION) > Gem::Version.new('5.11.3')
9
- ENV["MT_CPU"] = "0" # Newer versions minitest
10
- else
11
- ENV["N"] = "0" # Older versions of minitest
12
- end
13
-
14
- require 'ruby-prof'
8
+ ENV["MT_CPU"] = "0" # New versions of minitest
9
+ ENV["N"] = "0" # Older versions of minitest
15
10
 
11
+ require 'minitest/autorun'
16
12
  class TestCase < Minitest::Test
17
13
  end
@@ -79,8 +79,14 @@ class UniqueCallPathTest < TestCase
79
79
  array
80
80
  end
81
81
 
82
- assert_equal(1, call_info_a.children.length)
83
- assert_equal("UniqueCallPath#method_b", call_info_a.children.first.target.full_name)
82
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
83
+ assert_equal(1, call_info_a.children.length)
84
+ assert_equal("UniqueCallPath#method_b", call_info_a.children[0].target.full_name)
85
+ else
86
+ assert_equal(2, call_info_a.children.length)
87
+ assert_equal("Integer#==", call_info_a.children[0].target.full_name)
88
+ assert_equal("UniqueCallPath#method_b", call_info_a.children[1].target.full_name)
89
+ end
84
90
  end
85
91
 
86
92
  def test_unique_path
@@ -106,15 +112,25 @@ class UniqueCallPathTest < TestCase
106
112
  array
107
113
  end
108
114
 
109
- assert_equal(1, call_info_a.children.length)
110
- assert_equal(1, children_of_a.length)
111
-
112
115
  children_of_a = children_of_a.sort do |c1, c2|
113
116
  c1.target.full_name <=> c2.target.full_name
114
117
  end
115
118
 
116
- assert_equal(1, children_of_a.length)
117
- assert_equal(1, children_of_a[0].called)
118
- assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
119
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
120
+ assert_equal(1, call_info_a.children.length)
121
+ assert_equal(1, children_of_a.length)
122
+
123
+ assert_equal(1, children_of_a[0].called)
124
+ assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
125
+ else
126
+ assert_equal(2, call_info_a.children.length)
127
+ assert_equal(2, children_of_a.length)
128
+
129
+ assert_equal(1, children_of_a[0].called)
130
+ assert_equal("Integer#==", children_of_a[0].target.full_name)
131
+
132
+ assert_equal(1, children_of_a[1].called)
133
+ assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
134
+ end
119
135
  end
120
136
  end