ruby-prof 2.0.0 → 2.0.1

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.
@@ -1,39 +1,39 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- require 'stringio'
6
- require 'timeout'
7
-
8
- # -- Test for bug [#5657]
9
- # http://rubyforge.org/tracker/index.php?func=detail&aid=5657&group_id=1814&atid=7060
10
-
11
-
12
- class A
13
- attr_accessor :as
14
- def initialize
15
- @as = []
16
- class << @as
17
- def <<(an_a)
18
- super
19
- end
20
- end
21
- end
22
-
23
- def <<(an_a)
24
- @as << an_a
25
- end
26
- end
27
-
28
- class SingletonTest < TestCase
29
- def test_singleton
30
- result = RubyProf::Profile.profile do
31
- a = A.new
32
- a << :first_thing
33
- assert_equal(1, a.as.size)
34
- end
35
- printer = RubyProf::FlatPrinter.new(result)
36
- output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new
37
- printer.print(output)
38
- end
39
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'stringio'
6
+ require 'timeout'
7
+
8
+ # -- Test for bug [#5657]
9
+ # http://rubyforge.org/tracker/index.php?func=detail&aid=5657&group_id=1814&atid=7060
10
+
11
+
12
+ class A
13
+ attr_accessor :as
14
+ def initialize
15
+ @as = []
16
+ class << @as
17
+ def <<(an_a)
18
+ super
19
+ end
20
+ end
21
+ end
22
+
23
+ def <<(an_a)
24
+ @as << an_a
25
+ end
26
+ end
27
+
28
+ class SingletonTest < TestCase
29
+ def test_singleton
30
+ result = RubyProf::Profile.profile do
31
+ a = A.new
32
+ a << :first_thing
33
+ assert_equal(1, a.as.size)
34
+ end
35
+ printer = RubyProf::FlatPrinter.new(result)
36
+ output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new
37
+ printer.print(output)
38
+ end
39
+ end
data/test/thread_test.rb CHANGED
@@ -1,229 +1,229 @@
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
- thread_ids.each do |id|
130
- thread = threads.find { |t| t.object_id == id }
131
- refute_nil(thread)
132
- assert_instance_of(Thread, thread)
133
- end
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 * delta_multiplier)
160
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
161
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
162
- assert_in_delta(1, method.children_time, 0.1 * delta_multiplier)
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 * delta_multiplier)
169
- assert_in_delta(1.0, method.self_time, 0.05 * delta_multiplier)
170
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
171
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
189
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
190
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
191
- assert_in_delta(1, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
200
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
201
- assert_in_delta(1.0, method.wait_time, 0.05 * delta_multiplier)
202
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
211
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
212
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
213
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
222
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
223
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
224
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
225
-
226
- assert_equal(1, method.call_trees.callers.length)
227
- assert_equal(0, method.call_trees.callees.length)
228
- end
229
- 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
+ thread_ids.each do |id|
130
+ thread = threads.find { |t| t.object_id == id }
131
+ refute_nil(thread)
132
+ assert_instance_of(Thread, thread)
133
+ end
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 * delta_multiplier)
160
+ assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
161
+ assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
162
+ assert_in_delta(1, method.children_time, 0.1 * delta_multiplier)
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 * delta_multiplier)
169
+ assert_in_delta(1.0, method.self_time, 0.05 * delta_multiplier)
170
+ assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
171
+ assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
189
+ assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
190
+ assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
191
+ assert_in_delta(1, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
200
+ assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
201
+ assert_in_delta(1.0, method.wait_time, 0.05 * delta_multiplier)
202
+ assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
211
+ assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
212
+ assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
213
+ assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
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 * delta_multiplier)
222
+ assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
223
+ assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
224
+ assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
225
+
226
+ assert_equal(1, method.call_trees.callers.length)
227
+ assert_equal(0, method.call_trees.callees.length)
228
+ end
229
+ end
data/test/yarv_test.rb CHANGED
@@ -1,56 +1,56 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- # tests for bugs reported by users
7
- class YarvTest < TestCase
8
- def setup
9
- super
10
- define_methods
11
- end
12
-
13
- def test_array_push_unoptimized
14
- a = nil
15
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
16
- a = self.array_push_unoptimized
17
- end
18
- assert_equal 2, a.length
19
- assert_equal ["YarvTest#test_array_push_unoptimized", "YarvTest#array_push_unoptimized", 'Array#<<', "Array#push"], result.threads.first.methods.map(&:full_name)
20
- end
21
-
22
- def test_array_push_optimized
23
- a = nil
24
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
25
- a = self.array_push_optimized
26
- end
27
- assert_equal(2, a.length)
28
- assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#<<", "Array#push"], result.threads.first.methods.map(&:full_name))
29
- end
30
-
31
- private
32
-
33
- def define_methods
34
- return if respond_to?(:array_push_optimized)
35
- old_compile_option = RubyVM::InstructionSequence.compile_option
36
- RubyVM::InstructionSequence.compile_option = {
37
- trace_instruction: true,
38
- specialized_instruction: false
39
- }
40
- self.class.class_eval <<-"EOM"
41
- def array_push_unoptimized
42
- a = []
43
- a << 1
44
- a.push 2
45
- end
46
- EOM
47
- RubyVM::InstructionSequence.compile_option = old_compile_option
48
- self.class.class_eval <<-"EOM"
49
- def array_push_optimized
50
- a = []
51
- a << 1
52
- a.push 2
53
- end
54
- EOM
55
- end
56
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ # tests for bugs reported by users
7
+ class YarvTest < TestCase
8
+ def setup
9
+ super
10
+ define_methods
11
+ end
12
+
13
+ def test_array_push_unoptimized
14
+ a = nil
15
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
16
+ a = self.array_push_unoptimized
17
+ end
18
+ assert_equal 2, a.length
19
+ assert_equal ["YarvTest#test_array_push_unoptimized", "YarvTest#array_push_unoptimized", 'Array#<<', "Array#push"], result.threads.first.methods.map(&:full_name)
20
+ end
21
+
22
+ def test_array_push_optimized
23
+ a = nil
24
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
25
+ a = self.array_push_optimized
26
+ end
27
+ assert_equal(2, a.length)
28
+ assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#<<", "Array#push"], result.threads.first.methods.map(&:full_name))
29
+ end
30
+
31
+ private
32
+
33
+ def define_methods
34
+ return if respond_to?(:array_push_optimized)
35
+ old_compile_option = RubyVM::InstructionSequence.compile_option
36
+ RubyVM::InstructionSequence.compile_option = {
37
+ trace_instruction: true,
38
+ specialized_instruction: false
39
+ }
40
+ self.class.class_eval <<-"EOM"
41
+ def array_push_unoptimized
42
+ a = []
43
+ a << 1
44
+ a.push 2
45
+ end
46
+ EOM
47
+ RubyVM::InstructionSequence.compile_option = old_compile_option
48
+ self.class.class_eval <<-"EOM"
49
+ def array_push_optimized
50
+ a = []
51
+ a << 1
52
+ a.push 2
53
+ end
54
+ EOM
55
+ end
56
+ end