ruby-prof 1.7.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +8 -0
  3. data/ext/ruby_prof/extconf.rb +23 -22
  4. data/ext/ruby_prof/rp_call_trees.c +296 -296
  5. data/ext/ruby_prof/rp_call_trees.h +28 -28
  6. data/ext/ruby_prof/rp_measure_allocations.c +47 -47
  7. data/ext/ruby_prof/rp_measure_process_time.c +64 -66
  8. data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
  9. data/ext/ruby_prof/rp_method.c +551 -551
  10. data/ext/ruby_prof/rp_stack.c +212 -212
  11. data/ext/ruby_prof/ruby_prof.c +50 -50
  12. data/ext/ruby_prof/ruby_prof.h +3 -2
  13. data/ext/ruby_prof/vc/ruby_prof.vcxproj +3 -3
  14. data/lib/ruby-prof/compatibility.rb +113 -113
  15. data/lib/ruby-prof/exclude_common_methods.rb +204 -204
  16. data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
  17. data/lib/ruby-prof/version.rb +3 -3
  18. data/ruby-prof.gemspec +66 -65
  19. data/test/dynamic_method_test.rb +9 -21
  20. data/test/enumerable_test.rb +23 -21
  21. data/test/exclude_methods_test.rb +363 -257
  22. data/test/fiber_test.rb +195 -195
  23. data/test/gc_test.rb +104 -102
  24. data/test/line_number_test.rb +426 -289
  25. data/test/measure_allocations_test.rb +1172 -1081
  26. data/test/measure_memory_test.rb +1193 -1456
  27. data/test/measure_process_time_test.rb +3330 -2477
  28. data/test/measure_wall_time_test.rb +634 -568
  29. data/test/merge_test.rb +146 -146
  30. data/test/method_info_test.rb +100 -95
  31. data/test/printers_test.rb +178 -135
  32. data/test/recursive_test.rb +796 -622
  33. data/test/start_stop_test.rb +4 -4
  34. data/test/test_helper.rb +20 -20
  35. data/test/thread_test.rb +229 -231
  36. data/test/unique_call_path_test.rb +9 -22
  37. data/test/yarv_test.rb +1 -5
  38. metadata +19 -9
  39. data/test/crash2.rb +0 -144
@@ -76,10 +76,10 @@ class StartStopTest < TestCase
76
76
  method = methods[2]
77
77
  assert_equal('StartStopTest#method3', method.full_name)
78
78
  assert_equal(1, method.called)
79
- assert_in_delta(2, method.total_time, 0.02)
79
+ assert_in_delta(2, method.total_time, 0.05)
80
80
  assert_in_delta(0, method.wait_time, 0.02)
81
81
  assert_in_delta(0, method.self_time, 0.02)
82
- assert_in_delta(2, method.children_time, 0.02)
82
+ assert_in_delta(2, method.children_time, 0.05)
83
83
 
84
84
  assert_equal(1, method.call_trees.callers.length)
85
85
  call_tree = method.call_trees.callers[0]
@@ -92,10 +92,10 @@ class StartStopTest < TestCase
92
92
  method = methods[3]
93
93
  assert_equal('Kernel#sleep', method.full_name)
94
94
  assert_equal(1, method.called)
95
- assert_in_delta(2, method.total_time, 0.02)
95
+ assert_in_delta(2, method.total_time, 0.05)
96
96
  assert_in_delta(0, method.wait_time, 0.02)
97
97
  assert_in_delta(2, method.self_time, 0.02)
98
- assert_in_delta(0, method.children_time, 0.02)
98
+ assert_in_delta(0, method.children_time, 0.05)
99
99
 
100
100
  assert_equal(1, method.call_trees.callers.length)
101
101
  call_tree = method.call_trees.callers[0]
data/test/test_helper.rb CHANGED
@@ -1,20 +1,20 @@
1
- # encoding: UTF-8
2
-
3
- # To make testing/debugging easier test within this source tree versus an installed gem
4
- require 'bundler/setup'
5
-
6
- # Add ext directory to load path to make it easier to test locally built extensions
7
- ext_path = File.expand_path(File.join(__dir__, '..', 'ext', 'ruby_prof'))
8
- $LOAD_PATH.unshift(File.expand_path(ext_path))
9
-
10
- # Now load code
11
- require 'ruby-prof'
12
-
13
- # Disable minitest parallel tests. The problem is the thread switching will change test results
14
- # (self vs wait time)
15
- ENV["MT_CPU"] = "0" # New versions of minitest
16
- ENV["N"] = "0" # Older versions of minitest
17
-
18
- require 'minitest/autorun'
19
- class TestCase < Minitest::Test
20
- end
1
+ # encoding: UTF-8
2
+
3
+ # To make testing/debugging easier test within this source tree versus an installed gem
4
+ require 'bundler/setup'
5
+
6
+ # Add ext directory to load path to make it easier to test locally built extensions
7
+ ext_path = File.expand_path(File.join(__dir__, '..', 'ext', 'ruby_prof'))
8
+ $LOAD_PATH.unshift(ext_path)
9
+
10
+ # Now load code
11
+ require 'ruby-prof'
12
+
13
+ # Disable minitest parallel tests. The problem is the thread switching will change test results
14
+ # (self vs wait time)
15
+ ENV["MT_CPU"] = "0" # New versions of minitest
16
+ ENV["N"] = "0" # Older versions of minitest
17
+
18
+ require 'minitest/autorun'
19
+ class TestCase < Minitest::Test
20
+ end
data/test/thread_test.rb CHANGED
@@ -1,231 +1,229 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- require 'timeout'
6
- require 'benchmark'
7
- require_relative './call_tree_builder'
8
-
9
- # -- Tests ----
10
- class ThreadTest < TestCase
11
- def test_initialize
12
- method_info = RubyProf::MethodInfo.new(Array, :size)
13
- call_tree = RubyProf::CallTree.new(method_info)
14
- thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
15
-
16
- assert_equal(call_tree, thread.call_tree)
17
- assert(thread)
18
- assert(thread.id)
19
- assert(thread.fiber_id)
20
-
21
- assert_equal(1, thread.methods.size)
22
- assert_same(method_info, thread.methods[0])
23
- end
24
-
25
- def test_merge
26
- call_tree_1 = create_call_tree_1
27
- thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, Fiber.current)
28
- assert_equal(6, thread_1.methods.size)
29
-
30
- call_tree_2 = create_call_tree_2
31
- thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, Fiber.current)
32
- assert_equal(6, thread_2.methods.size)
33
-
34
- thread_1.merge!(thread_2)
35
- assert_equal(7, thread_1.methods.size)
36
-
37
- # Method times
38
- assert_in_delta(11.6, thread_1.methods[0].total_time, 0.00001) # root
39
- assert_in_delta(4.1, thread_1.methods[1].total_time, 0.00001) # a
40
- assert_in_delta(1.5, thread_1.methods[2].total_time, 0.00001) # aa
41
- assert_in_delta(2.6, thread_1.methods[3].total_time, 0.00001) # ab
42
- assert_in_delta(7.5, thread_1.methods[4].total_time, 0.00001) # b
43
- assert_in_delta(6.6, thread_1.methods[5].total_time, 0.00001) # bb
44
- assert_in_delta(0.9, thread_1.methods[6].total_time, 0.00001) # ba
45
-
46
- # Root
47
- call_tree = call_tree_1
48
- assert_equal(:root, call_tree.target.method_name)
49
- assert_in_delta(11.6, call_tree.total_time, 0.00001)
50
- assert_in_delta(0, call_tree.self_time, 0.00001)
51
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
52
- assert_in_delta(11.6, call_tree.children_time, 0.00001)
53
-
54
- # a
55
- call_tree = call_tree_1.children[0]
56
- assert_equal(:a, call_tree.target.method_name)
57
- assert_in_delta(4.1, call_tree.total_time, 0.00001)
58
- assert_in_delta(0, call_tree.self_time, 0.00001)
59
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
60
- assert_in_delta(4.1, call_tree.children_time, 0.00001)
61
-
62
- # aa
63
- call_tree = call_tree_1.children[0].children[0]
64
- assert_equal(:aa, call_tree.target.method_name)
65
- assert_in_delta(1.5, call_tree.total_time, 0.00001)
66
- assert_in_delta(1.5, call_tree.self_time, 0.00001)
67
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
68
- assert_in_delta(0.0, call_tree.children_time, 0.00001)
69
-
70
- # ab
71
- call_tree = call_tree_1.children[0].children[1]
72
- assert_equal(:ab, call_tree.target.method_name)
73
- assert_in_delta(2.6, call_tree.total_time, 0.00001)
74
- assert_in_delta(2.6, call_tree.self_time, 0.00001)
75
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
76
- assert_in_delta(0.0, call_tree.children_time, 0.00001)
77
-
78
- # # b
79
- # call_tree = call_tree_1.children[1]
80
- # assert_equal(:b, call_tree.target.method_name)
81
- # assert_in_delta(7.5, call_tree.total_time, 0.00001)
82
- # assert_in_delta(0, call_tree.self_time, 0.00001)
83
- # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
84
- # assert_in_delta(7.5, call_tree.children_time, 0.00001)
85
-
86
- # bb
87
- # call_tree = call_tree_1.children[1].children[0]
88
- # assert_equal(:bb, call_tree.target.method_name)
89
- # assert_in_delta(6.6, call_tree.total_time, 0.00001)
90
- # assert_in_delta(6.6, call_tree.self_time, 0.00001)
91
- # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
92
- # assert_in_delta(0.0, call_tree.children_time, 0.00001)
93
-
94
- # ba
95
- call_tree = call_tree_1.children[1].children[1]
96
- assert_equal(:ba, call_tree.target.method_name)
97
- assert_in_delta(0.9, call_tree.total_time, 0.00001)
98
- assert_in_delta(0.7, call_tree.self_time, 0.00001)
99
- assert_in_delta(0.2, call_tree.wait_time, 0.00001)
100
- assert_in_delta(0.0, call_tree.children_time, 0.00001)
101
- end
102
-
103
- def test_thread_count
104
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
105
- thread = Thread.new do
106
- sleep(1)
107
- end
108
-
109
- thread.join
110
- end
111
- assert_equal(2, result.threads.length)
112
- end
113
-
114
- def test_thread_identity
115
- profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
116
- profile.start
117
-
118
- sleep_thread = Thread.new do
119
- sleep(1)
120
- end
121
- sleep_thread.join
122
- result = profile.stop
123
-
124
- thread_ids = result.threads.map {|thread| thread.id}.sort
125
- threads = [Thread.current, sleep_thread]
126
- assert_equal(2, result.threads.length)
127
-
128
- assert(thread_ids.include?(threads[0].object_id))
129
- assert(thread_ids.include?(threads[1].object_id))
130
-
131
- assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[0]))
132
- assert(threads.include?(ObjectSpace._id2ref(thread_ids[0])))
133
-
134
- assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[1]))
135
- assert(threads.include?(ObjectSpace._id2ref(thread_ids[1])))
136
- end
137
-
138
- def test_thread_timings
139
- profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
140
- profile.start
141
-
142
- thread = Thread.new do
143
- sleep 0
144
- # force it to hit thread.join, below, first
145
- # thus forcing sleep(1), below, to be counted as (wall) self_time
146
- # since we currently count time "in some other thread" as self.wait_time
147
- sleep(1)
148
- end
149
- thread.join
150
- result = profile.stop
151
-
152
- # Check background thread
153
- assert_equal(2, result.threads.length)
154
-
155
- rp_thread = result.threads.detect {|t| t.id == thread.object_id}
156
- methods = rp_thread.methods.sort.reverse
157
-
158
- method = methods[0]
159
- assert_equal('ThreadTest#test_thread_timings', method.full_name)
160
- assert_equal(1, method.called)
161
- assert_in_delta(1, method.total_time, 0.1)
162
- assert_in_delta(0, method.self_time, 0.05)
163
- assert_in_delta(0, method.wait_time, 0.05)
164
- assert_in_delta(1, method.children_time, 0.1)
165
- assert_equal(0, method.call_trees.callers.length)
166
-
167
- method = methods[1]
168
- assert_equal('Kernel#sleep', method.full_name)
169
- assert_equal(2, method.called)
170
- assert_in_delta(1, method.total_time, 0.05)
171
- assert_in_delta(1.0, method.self_time, 0.05)
172
- assert_in_delta(0, method.wait_time, 0.05)
173
- assert_in_delta(0, method.children_time, 0.05)
174
-
175
- assert_equal(1, method.call_trees.callers.length)
176
- assert_equal(0, method.call_trees.callees.length)
177
-
178
- # Check foreground thread
179
- rp_thread = result.threads.detect {|athread| athread.id == Thread.current.object_id}
180
- methods = rp_thread.methods.sort.reverse
181
- assert_equal(4, methods.length)
182
- methods = methods.sort.reverse
183
-
184
- method = methods[0]
185
- assert_equal('ThreadTest#test_thread_timings', method.full_name)
186
- # the sub calls to Object#new, when popped,
187
- # cause the parent frame to be created for method #test_thread_timings, which means a +1 when it's popped in the end
188
- # xxxx a test that shows it the other way, too (never creates parent frame--if that's even possible)
189
- assert_equal(1, method.called)
190
- assert_in_delta(1, method.total_time, 0.05)
191
- assert_in_delta(0, method.self_time, 0.05)
192
- assert_in_delta(0, method.wait_time, 0.05)
193
- assert_in_delta(1, method.children_time, 0.05)
194
-
195
- assert_equal(0, method.call_trees.callers.length)
196
- assert_equal(2, method.call_trees.callees.length)
197
-
198
- method = methods[1]
199
- assert_equal('Thread#join', method.full_name)
200
- assert_equal(1, method.called)
201
- assert_in_delta(1, method.total_time, 0.05)
202
- assert_in_delta(0, method.self_time, 0.05)
203
- assert_in_delta(1.0, method.wait_time, 0.05)
204
- assert_in_delta(0, method.children_time, 0.05)
205
-
206
- assert_equal(1, method.call_trees.callers.length)
207
- assert_equal(0, method.call_trees.callees.length)
208
-
209
- method = methods[2]
210
- assert_equal('<Class::Thread>#new', method.full_name)
211
- assert_equal(1, method.called)
212
- assert_in_delta(0, method.total_time, 0.05)
213
- assert_in_delta(0, method.self_time, 0.05)
214
- assert_in_delta(0, method.wait_time, 0.05)
215
- assert_in_delta(0, method.children_time, 0.05)
216
-
217
- assert_equal(1, method.call_trees.callers.length)
218
- assert_equal(1, method.call_trees.callees.length)
219
-
220
- method = methods[3]
221
- assert_equal('Thread#initialize', method.full_name)
222
- assert_equal(1, method.called)
223
- assert_in_delta(0, method.total_time, 0.05)
224
- assert_in_delta(0, method.self_time, 0.05)
225
- assert_in_delta(0, method.wait_time, 0.05)
226
- assert_in_delta(0, method.children_time, 0.05)
227
-
228
- assert_equal(1, method.call_trees.callers.length)
229
- assert_equal(0, method.call_trees.callees.length)
230
- end
231
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './call_tree_builder'
6
+
7
+ # -- Tests ----
8
+ class ThreadTest < TestCase
9
+ def test_initialize
10
+ method_info = RubyProf::MethodInfo.new(Array, :size)
11
+ call_tree = RubyProf::CallTree.new(method_info)
12
+ thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
13
+
14
+ assert_equal(call_tree, thread.call_tree)
15
+ assert(thread)
16
+ assert(thread.id)
17
+ assert(thread.fiber_id)
18
+
19
+ assert_equal(1, thread.methods.size)
20
+ assert_same(method_info, thread.methods[0])
21
+ end
22
+
23
+ def test_merge
24
+ call_tree_1 = create_call_tree_1
25
+ thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, Fiber.current)
26
+ assert_equal(6, thread_1.methods.size)
27
+
28
+ call_tree_2 = create_call_tree_2
29
+ thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, Fiber.current)
30
+ assert_equal(6, thread_2.methods.size)
31
+
32
+ thread_1.merge!(thread_2)
33
+ assert_equal(7, thread_1.methods.size)
34
+
35
+ # Method times
36
+ assert_in_delta(11.6, thread_1.methods[0].total_time, 0.00001) # root
37
+ assert_in_delta(4.1, thread_1.methods[1].total_time, 0.00001) # a
38
+ assert_in_delta(1.5, thread_1.methods[2].total_time, 0.00001) # aa
39
+ assert_in_delta(2.6, thread_1.methods[3].total_time, 0.00001) # ab
40
+ assert_in_delta(7.5, thread_1.methods[4].total_time, 0.00001) # b
41
+ assert_in_delta(6.6, thread_1.methods[5].total_time, 0.00001) # bb
42
+ assert_in_delta(0.9, thread_1.methods[6].total_time, 0.00001) # ba
43
+
44
+ # Root
45
+ call_tree = call_tree_1
46
+ assert_equal(:root, call_tree.target.method_name)
47
+ assert_in_delta(11.6, call_tree.total_time, 0.00001)
48
+ assert_in_delta(0, call_tree.self_time, 0.00001)
49
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
50
+ assert_in_delta(11.6, call_tree.children_time, 0.00001)
51
+
52
+ # a
53
+ call_tree = call_tree_1.children[0]
54
+ assert_equal(:a, call_tree.target.method_name)
55
+ assert_in_delta(4.1, call_tree.total_time, 0.00001)
56
+ assert_in_delta(0, call_tree.self_time, 0.00001)
57
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
58
+ assert_in_delta(4.1, call_tree.children_time, 0.00001)
59
+
60
+ # aa
61
+ call_tree = call_tree_1.children[0].children[0]
62
+ assert_equal(:aa, call_tree.target.method_name)
63
+ assert_in_delta(1.5, call_tree.total_time, 0.00001)
64
+ assert_in_delta(1.5, call_tree.self_time, 0.00001)
65
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
66
+ assert_in_delta(0.0, call_tree.children_time, 0.00001)
67
+
68
+ # ab
69
+ call_tree = call_tree_1.children[0].children[1]
70
+ assert_equal(:ab, call_tree.target.method_name)
71
+ assert_in_delta(2.6, call_tree.total_time, 0.00001)
72
+ assert_in_delta(2.6, call_tree.self_time, 0.00001)
73
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
74
+ assert_in_delta(0.0, call_tree.children_time, 0.00001)
75
+
76
+ # # b
77
+ # call_tree = call_tree_1.children[1]
78
+ # assert_equal(:b, call_tree.target.method_name)
79
+ # assert_in_delta(7.5, call_tree.total_time, 0.00001)
80
+ # assert_in_delta(0, call_tree.self_time, 0.00001)
81
+ # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
82
+ # assert_in_delta(7.5, call_tree.children_time, 0.00001)
83
+
84
+ # bb
85
+ # call_tree = call_tree_1.children[1].children[0]
86
+ # assert_equal(:bb, call_tree.target.method_name)
87
+ # assert_in_delta(6.6, call_tree.total_time, 0.00001)
88
+ # assert_in_delta(6.6, call_tree.self_time, 0.00001)
89
+ # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
90
+ # assert_in_delta(0.0, call_tree.children_time, 0.00001)
91
+
92
+ # ba
93
+ call_tree = call_tree_1.children[1].children[1]
94
+ assert_equal(:ba, call_tree.target.method_name)
95
+ assert_in_delta(0.9, call_tree.total_time, 0.00001)
96
+ assert_in_delta(0.7, call_tree.self_time, 0.00001)
97
+ assert_in_delta(0.2, call_tree.wait_time, 0.00001)
98
+ assert_in_delta(0.0, call_tree.children_time, 0.00001)
99
+ end
100
+
101
+ def test_thread_count
102
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
103
+ thread = Thread.new do
104
+ sleep(1)
105
+ end
106
+
107
+ thread.join
108
+ end
109
+ assert_equal(2, result.threads.length)
110
+ end
111
+
112
+ def test_thread_identity
113
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
114
+ profile.start
115
+
116
+ sleep_thread = Thread.new do
117
+ sleep(1)
118
+ end
119
+ sleep_thread.join
120
+ result = profile.stop
121
+
122
+ thread_ids = result.threads.map {|thread| thread.id}.sort
123
+ threads = [Thread.current, sleep_thread]
124
+ assert_equal(2, result.threads.length)
125
+
126
+ assert(thread_ids.include?(threads[0].object_id))
127
+ assert(thread_ids.include?(threads[1].object_id))
128
+
129
+ assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[0]))
130
+ assert(threads.include?(ObjectSpace._id2ref(thread_ids[0])))
131
+
132
+ assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[1]))
133
+ assert(threads.include?(ObjectSpace._id2ref(thread_ids[1])))
134
+ end
135
+
136
+ def test_thread_timings
137
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
138
+ profile.start
139
+
140
+ thread = Thread.new do
141
+ sleep 0
142
+ # force it to hit thread.join, below, first
143
+ # thus forcing sleep(1), below, to be counted as (wall) self_time
144
+ # since we currently count time "in some other thread" as self.wait_time
145
+ sleep(1)
146
+ end
147
+ thread.join
148
+ result = profile.stop
149
+
150
+ # Check background thread
151
+ assert_equal(2, result.threads.length)
152
+
153
+ rp_thread = result.threads.detect {|t| t.id == thread.object_id}
154
+ methods = rp_thread.methods.sort.reverse
155
+
156
+ method = methods[0]
157
+ assert_equal('ThreadTest#test_thread_timings', method.full_name)
158
+ assert_equal(1, method.called)
159
+ assert_in_delta(1, method.total_time, 0.1)
160
+ assert_in_delta(0, method.self_time, 0.05)
161
+ assert_in_delta(0, method.wait_time, 0.05)
162
+ assert_in_delta(1, method.children_time, 0.1)
163
+ assert_equal(0, method.call_trees.callers.length)
164
+
165
+ method = methods[1]
166
+ assert_equal('Kernel#sleep', method.full_name)
167
+ assert_equal(2, method.called)
168
+ assert_in_delta(1, method.total_time, 0.05)
169
+ assert_in_delta(1.0, method.self_time, 0.05)
170
+ assert_in_delta(0, method.wait_time, 0.05)
171
+ assert_in_delta(0, method.children_time, 0.05)
172
+
173
+ assert_equal(1, method.call_trees.callers.length)
174
+ assert_equal(0, method.call_trees.callees.length)
175
+
176
+ # Check foreground thread
177
+ rp_thread = result.threads.detect {|athread| athread.id == Thread.current.object_id}
178
+ methods = rp_thread.methods.sort.reverse
179
+ assert_equal(4, methods.length)
180
+ methods = methods.sort.reverse
181
+
182
+ method = methods[0]
183
+ assert_equal('ThreadTest#test_thread_timings', method.full_name)
184
+ # the sub calls to Object#new, when popped,
185
+ # cause the parent frame to be created for method #test_thread_timings, which means a +1 when it's popped in the end
186
+ # xxxx a test that shows it the other way, too (never creates parent frame--if that's even possible)
187
+ assert_equal(1, method.called)
188
+ assert_in_delta(1, method.total_time, 0.05)
189
+ assert_in_delta(0, method.self_time, 0.05)
190
+ assert_in_delta(0, method.wait_time, 0.05)
191
+ assert_in_delta(1, method.children_time, 0.05)
192
+
193
+ assert_equal(0, method.call_trees.callers.length)
194
+ assert_equal(2, method.call_trees.callees.length)
195
+
196
+ method = methods[1]
197
+ assert_equal('Thread#join', method.full_name)
198
+ assert_equal(1, method.called)
199
+ assert_in_delta(1, method.total_time, 0.05)
200
+ assert_in_delta(0, method.self_time, 0.05)
201
+ assert_in_delta(1.0, method.wait_time, 0.05)
202
+ assert_in_delta(0, method.children_time, 0.05)
203
+
204
+ assert_equal(1, method.call_trees.callers.length)
205
+ assert_equal(0, method.call_trees.callees.length)
206
+
207
+ method = methods[2]
208
+ assert_equal('<Class::Thread>#new', method.full_name)
209
+ assert_equal(1, method.called)
210
+ assert_in_delta(0, method.total_time, 0.05)
211
+ assert_in_delta(0, method.self_time, 0.05)
212
+ assert_in_delta(0, method.wait_time, 0.05)
213
+ assert_in_delta(0, method.children_time, 0.05)
214
+
215
+ assert_equal(1, method.call_trees.callers.length)
216
+ assert_equal(1, method.call_trees.callees.length)
217
+
218
+ method = methods[3]
219
+ assert_equal('Thread#initialize', method.full_name)
220
+ assert_equal(1, method.called)
221
+ assert_in_delta(0, method.total_time, 0.05)
222
+ assert_in_delta(0, method.self_time, 0.05)
223
+ assert_in_delta(0, method.wait_time, 0.05)
224
+ assert_in_delta(0, method.children_time, 0.05)
225
+
226
+ assert_equal(1, method.call_trees.callers.length)
227
+ assert_equal(0, method.call_trees.callees.length)
228
+ end
229
+ end
@@ -79,14 +79,9 @@ class UniqueCallPathTest < TestCase
79
79
  array
80
80
  end
81
81
 
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
82
+ assert_equal(2, call_info_a.children.length)
83
+ assert_equal("Integer#==", call_info_a.children[0].target.full_name)
84
+ assert_equal("UniqueCallPath#method_b", call_info_a.children[1].target.full_name)
90
85
  end
91
86
 
92
87
  def test_unique_path
@@ -116,21 +111,13 @@ class UniqueCallPathTest < TestCase
116
111
  c1.target.full_name <=> c2.target.full_name
117
112
  end
118
113
 
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)
114
+ assert_equal(2, call_info_a.children.length)
115
+ assert_equal(2, children_of_a.length)
122
116
 
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)
117
+ assert_equal(1, children_of_a[0].called)
118
+ assert_equal("Integer#==", children_of_a[0].target.full_name)
128
119
 
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
120
+ assert_equal(1, children_of_a[1].called)
121
+ assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
135
122
  end
136
123
  end
data/test/yarv_test.rb CHANGED
@@ -25,11 +25,7 @@ class YarvTest < TestCase
25
25
  a = self.array_push_optimized
26
26
  end
27
27
  assert_equal(2, a.length)
28
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
29
- assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#push"], result.threads.first.methods.map(&:full_name))
30
- else
31
- assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#<<", "Array#push"], result.threads.first.methods.map(&:full_name))
32
- end
28
+ assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#<<", "Array#push"], result.threads.first.methods.map(&:full_name))
33
29
  end
34
30
 
35
31
  private