ruby-prof 1.1.0-x64-mingw32 → 1.3.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +19 -1
- data/bin/ruby-prof +100 -152
- data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +67 -59
- data/ext/ruby_prof/rp_allocation.h +3 -3
- data/ext/ruby_prof/rp_call_tree.c +369 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +288 -0
- data/ext/ruby_prof/rp_call_trees.h +28 -0
- data/ext/ruby_prof/rp_measure_allocations.c +11 -13
- data/ext/ruby_prof/rp_measure_process_time.c +11 -13
- data/ext/ruby_prof/rp_measure_wall_time.c +17 -15
- data/ext/ruby_prof/rp_measurement.c +47 -40
- data/ext/ruby_prof/rp_measurement.h +7 -7
- data/ext/ruby_prof/rp_method.c +116 -255
- data/ext/ruby_prof/rp_method.h +31 -39
- data/ext/ruby_prof/rp_profile.c +311 -281
- data/ext/ruby_prof/rp_profile.h +1 -2
- data/ext/ruby_prof/rp_stack.c +113 -105
- data/ext/ruby_prof/rp_stack.h +17 -20
- data/ext/ruby_prof/rp_thread.c +136 -111
- data/ext/ruby_prof/rp_thread.h +12 -9
- data/ext/ruby_prof/ruby_prof.c +27 -23
- data/ext/ruby_prof/ruby_prof.h +9 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +11 -7
- data/lib/ruby-prof.rb +2 -3
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +4 -7
- data/lib/ruby-prof/assets/graph_printer.html.erb +5 -6
- data/lib/ruby-prof/{call_info.rb → call_tree.rb} +6 -6
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/measurement.rb +5 -2
- data/lib/ruby-prof/method_info.rb +3 -15
- data/lib/ruby-prof/printers/call_info_printer.rb +12 -10
- data/lib/ruby-prof/printers/call_stack_printer.rb +19 -22
- data/lib/ruby-prof/printers/call_tree_printer.rb +1 -1
- data/lib/ruby-prof/printers/dot_printer.rb +3 -3
- data/lib/ruby-prof/printers/graph_printer.rb +3 -4
- data/lib/ruby-prof/printers/multi_printer.rb +2 -2
- data/lib/ruby-prof/rack.rb +3 -0
- data/lib/ruby-prof/thread.rb +3 -18
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +7 -0
- data/test/alias_test.rb +42 -45
- data/test/basic_test.rb +0 -86
- data/test/{call_info_visitor_test.rb → call_tree_visitor_test.rb} +6 -5
- data/test/call_trees_test.rb +66 -0
- data/test/exclude_methods_test.rb +17 -12
- data/test/fiber_test.rb +197 -9
- data/test/gc_test.rb +36 -42
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +67 -70
- data/test/marshal_test.rb +7 -11
- data/test/measure_allocations_test.rb +224 -234
- data/test/measure_allocations_trace_test.rb +224 -234
- data/test/measure_memory_trace_test.rb +814 -469
- data/test/measure_process_time_test.rb +0 -64
- data/test/measure_times.rb +2 -0
- data/test/measure_wall_time_test.rb +34 -58
- data/test/pause_resume_test.rb +19 -10
- data/test/prime.rb +1 -3
- data/test/prime_script.rb +6 -0
- data/test/printers_test.rb +1 -1
- data/test/recursive_test.rb +50 -54
- data/test/start_stop_test.rb +19 -19
- data/test/test_helper.rb +3 -15
- data/test/thread_test.rb +11 -11
- data/test/unique_call_path_test.rb +25 -95
- metadata +19 -10
- data/ext/ruby_prof/rp_call_info.c +0 -271
- data/ext/ruby_prof/rp_call_info.h +0 -35
- data/lib/2.6.5/ruby_prof.so +0 -0
- data/lib/ruby-prof/call_info_visitor.rb +0 -38
- data/test/parser_timings.rb +0 -24
@@ -43,13 +43,12 @@ class ExcludeMethodsTest < TestCase
|
|
43
43
|
obj = ExcludeMethodsClass.new
|
44
44
|
prf = RubyProf::Profile.new
|
45
45
|
|
46
|
-
result = prf.profile {
|
46
|
+
result = prf.profile {obj.a}
|
47
47
|
methods = result.threads.first.methods.sort.reverse
|
48
|
-
|
49
48
|
assert_equal(10, methods.count)
|
50
49
|
assert_equal('ExcludeMethodsTest#test_methods_can_be_profiled', methods[0].full_name)
|
51
|
-
assert_equal('
|
52
|
-
assert_equal('
|
50
|
+
assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
|
51
|
+
assert_equal('Integer#times', methods[2].full_name)
|
53
52
|
assert_equal('ExcludeMethodsClass#b', methods[3].full_name)
|
54
53
|
assert_equal('<Class::ExcludeMethodsClass>#e', methods[4].full_name)
|
55
54
|
assert_equal('<Class::ExcludeMethodsClass>#f', methods[5].full_name)
|
@@ -65,7 +64,7 @@ class ExcludeMethodsTest < TestCase
|
|
65
64
|
|
66
65
|
prf.exclude_methods!(Integer, :times)
|
67
66
|
|
68
|
-
result = prf.profile {
|
67
|
+
result = prf.profile {obj.a}
|
69
68
|
methods = result.threads.first.methods.sort.reverse
|
70
69
|
|
71
70
|
assert_equal(9, methods.count)
|
@@ -88,7 +87,7 @@ class ExcludeMethodsTest < TestCase
|
|
88
87
|
prf.exclude_methods!(ExcludeMethodsClass.singleton_class, :f)
|
89
88
|
prf.exclude_methods!(ExcludeMethodsModule.singleton_class, :d)
|
90
89
|
|
91
|
-
result = prf.profile {
|
90
|
+
result = prf.profile {obj.a}
|
92
91
|
methods = result.threads.first.methods.sort.reverse
|
93
92
|
|
94
93
|
assert_equal(7, methods.count)
|
@@ -107,13 +106,19 @@ class ExcludeMethodsTest < TestCase
|
|
107
106
|
|
108
107
|
prf.exclude_common_methods!
|
109
108
|
|
110
|
-
result = prf.profile {
|
109
|
+
result = prf.profile {obj.a}
|
111
110
|
methods = result.threads.first.methods.sort.reverse
|
112
111
|
|
113
112
|
assert_equal(9, methods.count)
|
114
113
|
assert_equal('ExcludeMethodsTest#test_exclude_common_methods1', methods[0].full_name)
|
115
114
|
assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
|
116
115
|
assert_equal('ExcludeMethodsClass#b', methods[2].full_name)
|
116
|
+
assert_equal('<Class::ExcludeMethodsClass>#e', methods[3].full_name)
|
117
|
+
assert_equal('<Class::ExcludeMethodsClass>#f', methods[4].full_name)
|
118
|
+
assert_equal('Kernel#sleep', methods[5].full_name)
|
119
|
+
assert_equal('ExcludeMethodsModule#c', methods[6].full_name)
|
120
|
+
assert_equal('<Module::ExcludeMethodsModule>#d', methods[7].full_name)
|
121
|
+
assert_equal('Kernel#class', methods[8].full_name)
|
117
122
|
end
|
118
123
|
|
119
124
|
def test_exclude_common_methods2
|
@@ -130,14 +135,14 @@ class ExcludeMethodsTest < TestCase
|
|
130
135
|
|
131
136
|
private
|
132
137
|
|
133
|
-
def
|
138
|
+
def assert_method_has_been_excluded(result, excluded_method)
|
134
139
|
result.threads.each do |thread|
|
135
140
|
thread.methods.each do |method|
|
136
|
-
method.
|
137
|
-
assert(ci.target !=
|
138
|
-
assert(ci.parent.target !=
|
141
|
+
method.call_trees.each do |ci|
|
142
|
+
assert(ci.target != excluded_method, "broken self")
|
143
|
+
assert(ci.parent.target != excluded_method, "broken parent") if ci.parent
|
139
144
|
ci.children.each do |callee|
|
140
|
-
assert(callee.target !=
|
145
|
+
assert(callee.target != excluded_method, "broken kid")
|
141
146
|
end
|
142
147
|
end
|
143
148
|
end
|
data/test/fiber_test.rb
CHANGED
@@ -8,7 +8,7 @@ require 'set'
|
|
8
8
|
|
9
9
|
# -- Tests ----
|
10
10
|
class FiberTest < TestCase
|
11
|
-
def
|
11
|
+
def enumerator_with_fibers
|
12
12
|
@fiber_ids << Fiber.current.object_id
|
13
13
|
enum = Enumerator.new do |yielder|
|
14
14
|
[1,2].each do |x|
|
@@ -36,7 +36,8 @@ class FiberTest < TestCase
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_fibers
|
39
|
-
result = RubyProf.profile {
|
39
|
+
result = RubyProf.profile { enumerator_with_fibers }
|
40
|
+
|
40
41
|
profiled_fiber_ids = result.threads.map(&:fiber_id)
|
41
42
|
assert_equal(2, result.threads.length)
|
42
43
|
assert_equal([@thread_id], result.threads.map(&:id).uniq)
|
@@ -45,19 +46,206 @@ class FiberTest < TestCase
|
|
45
46
|
assert profiled_fiber_ids.include?(@root_fiber)
|
46
47
|
assert(root_fiber_profile = result.threads.detect{|t| t.fiber_id == @root_fiber})
|
47
48
|
assert(enum_fiber_profile = result.threads.detect{|t| t.fiber_id != @root_fiber})
|
49
|
+
assert_in_delta(0.33, root_fiber_profile.total_time, 0.05)
|
50
|
+
assert_in_delta(0.33, enum_fiber_profile.total_time, 0.05)
|
48
51
|
|
49
|
-
|
50
|
-
|
52
|
+
methods = result.threads[0].methods.sort.reverse
|
53
|
+
assert_equal(12, methods.count)
|
51
54
|
|
52
|
-
|
53
|
-
|
55
|
+
method = methods[0]
|
56
|
+
assert_equal('FiberTest#test_fibers', method.full_name)
|
57
|
+
assert_equal(1, method.called)
|
58
|
+
assert_in_delta(0.33, method.total_time, 0.05)
|
59
|
+
assert_in_delta(0, method.self_time, 0.05)
|
60
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
61
|
+
assert_in_delta(0.33, method.children_time, 0.05)
|
54
62
|
|
55
|
-
|
56
|
-
|
63
|
+
method = methods[1]
|
64
|
+
assert_equal('FiberTest#enumerator_with_fibers', method.full_name)
|
65
|
+
assert_equal(1, method.called)
|
66
|
+
assert_in_delta(0.33, method.total_time, 0.05)
|
67
|
+
assert_in_delta(0, method.self_time, 0.05)
|
68
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
69
|
+
assert_in_delta(0.33, method.children_time, 0.05)
|
70
|
+
|
71
|
+
method = methods[2]
|
72
|
+
assert_equal('Enumerator#next', method.full_name)
|
73
|
+
assert_equal(3, method.called)
|
74
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
75
|
+
assert_in_delta(0, method.self_time, 0.05)
|
76
|
+
assert_in_delta(0.22, method.wait_time, 0.05)
|
77
|
+
assert_in_delta(0, method.children_time, 0.05)
|
78
|
+
|
79
|
+
method = methods[3]
|
80
|
+
assert_equal('Kernel#sleep', method.full_name)
|
81
|
+
assert_equal(1, method.called)
|
82
|
+
assert_in_delta(0.11, method.total_time, 0.05)
|
83
|
+
assert_in_delta(0.11, method.self_time, 0.05)
|
84
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
85
|
+
assert_in_delta(0, method.children_time, 0.05)
|
86
|
+
|
87
|
+
# Since these methods have such short times their order is a bit indeterminate
|
88
|
+
method = methods.detect {|a_method| a_method.full_name == 'Class#new'}
|
89
|
+
assert_equal('Class#new', method.full_name)
|
90
|
+
assert_equal(1, method.called)
|
91
|
+
assert_in_delta(0, method.total_time, 0.05)
|
92
|
+
assert_in_delta(0, method.self_time, 0.05)
|
93
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
94
|
+
assert_in_delta(0, method.children_time, 0.05)
|
95
|
+
|
96
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
97
|
+
method = methods.detect {|a_method| a_method.full_name == 'Set#<<'}
|
98
|
+
assert_equal('Set#<<', method.full_name)
|
99
|
+
assert_equal(1, method.called)
|
100
|
+
assert_in_delta(0, method.total_time, 0.05)
|
101
|
+
assert_in_delta(0, method.self_time, 0.05)
|
102
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
103
|
+
assert_in_delta(0, method.children_time, 0.05)
|
104
|
+
end
|
105
|
+
|
106
|
+
method = methods.detect {|a_method| a_method.full_name == 'Module#==='}
|
107
|
+
assert_equal('Module#===', method.full_name)
|
108
|
+
assert_equal(1, method.called)
|
109
|
+
assert_in_delta(0, method.total_time, 0.05)
|
110
|
+
assert_in_delta(0, method.self_time, 0.05)
|
111
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
112
|
+
assert_in_delta(0, method.children_time, 0.05)
|
113
|
+
|
114
|
+
method = methods.detect {|a_method| a_method.full_name == 'Kernel#object_id'}
|
115
|
+
assert_equal('Kernel#object_id', method.full_name)
|
116
|
+
assert_equal(1, method.called)
|
117
|
+
assert_in_delta(0, method.total_time, 0.05)
|
118
|
+
assert_in_delta(0, method.self_time, 0.05)
|
119
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
120
|
+
assert_in_delta(0, method.children_time, 0.05)
|
121
|
+
|
122
|
+
method = methods.detect {|a_method| a_method.full_name == '<Class::Fiber>#current'}
|
123
|
+
assert_equal('<Class::Fiber>#current', method.full_name)
|
124
|
+
assert_equal(1, method.called)
|
125
|
+
assert_in_delta(0, method.total_time, 0.05)
|
126
|
+
assert_in_delta(0, method.self_time, 0.05)
|
127
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
128
|
+
assert_in_delta(0, method.children_time, 0.05)
|
129
|
+
|
130
|
+
method = methods.detect {|a_method| a_method.full_name == 'Exception#exception'}
|
131
|
+
assert_equal('Exception#exception', method.full_name)
|
132
|
+
assert_equal(1, method.called)
|
133
|
+
assert_in_delta(0, method.total_time, 0.05)
|
134
|
+
assert_in_delta(0, method.self_time, 0.05)
|
135
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
136
|
+
assert_in_delta(0, method.children_time, 0.05)
|
137
|
+
|
138
|
+
method = methods.detect {|a_method| a_method.full_name == 'Exception#backtrace'}
|
139
|
+
assert_equal('Exception#backtrace', method.full_name)
|
140
|
+
assert_equal(1, method.called)
|
141
|
+
assert_in_delta(0, method.total_time, 0.05)
|
142
|
+
assert_in_delta(0, method.self_time, 0.05)
|
143
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
144
|
+
assert_in_delta(0, method.children_time, 0.05)
|
145
|
+
|
146
|
+
method = methods.detect {|a_method| a_method.full_name == 'Enumerator#initialize'}
|
147
|
+
assert_equal('Enumerator#initialize', method.full_name)
|
148
|
+
assert_equal(1, method.called)
|
149
|
+
assert_in_delta(0, method.total_time, 0.05)
|
150
|
+
assert_in_delta(0, method.self_time, 0.05)
|
151
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
152
|
+
assert_in_delta(0, method.children_time, 0.05)
|
153
|
+
|
154
|
+
methods = result.threads[1].methods.sort.reverse
|
155
|
+
|
156
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
|
157
|
+
assert_equal(10, methods.count)
|
158
|
+
else
|
159
|
+
assert_equal(11, methods.count)
|
160
|
+
end
|
161
|
+
|
162
|
+
method = methods[0]
|
163
|
+
assert_equal('RubyProf::Profile#_inserted_parent_', method.full_name)
|
164
|
+
assert_equal(1, method.called)
|
165
|
+
assert_in_delta(0.33, method.total_time, 0.05)
|
166
|
+
assert_in_delta(0, method.self_time, 0.05)
|
167
|
+
assert_in_delta(0.11, method.wait_time, 0.05)
|
168
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
169
|
+
|
170
|
+
method = methods[1]
|
171
|
+
assert_equal('Enumerator#each', method.full_name)
|
172
|
+
assert_equal(1, method.called)
|
173
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
174
|
+
assert_in_delta(0, method.self_time, 0.05)
|
175
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
176
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
177
|
+
|
178
|
+
method = methods[2]
|
179
|
+
assert_equal('Enumerator::Generator#each', method.full_name)
|
180
|
+
assert_equal(1, method.called)
|
181
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
182
|
+
assert_in_delta(0, method.self_time, 0.05)
|
183
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
184
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
185
|
+
|
186
|
+
method = methods[3]
|
187
|
+
assert_equal('Array#each', method.full_name)
|
188
|
+
assert_equal(1, method.called)
|
189
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
190
|
+
assert_in_delta(0, method.self_time, 0.05)
|
191
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
192
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
193
|
+
|
194
|
+
method = methods[4]
|
195
|
+
assert_equal('Kernel#sleep', method.full_name)
|
196
|
+
assert_equal(2, method.called)
|
197
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
198
|
+
assert_in_delta(0.22, method.self_time, 0.05)
|
199
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
200
|
+
assert_in_delta(0, method.children_time, 0.05)
|
201
|
+
|
202
|
+
# Since these methods have such short times their order is a bit indeterminate
|
203
|
+
method = methods.detect {|a_method| a_method.full_name == 'Exception#initialize'}
|
204
|
+
assert_equal('Exception#initialize', method.full_name)
|
205
|
+
assert_equal(1, method.called)
|
206
|
+
assert_in_delta(0, method.total_time, 0.05)
|
207
|
+
assert_in_delta(0, method.self_time, 0.05)
|
208
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
209
|
+
assert_in_delta(0, method.children_time, 0.05)
|
210
|
+
|
211
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
212
|
+
method = methods.detect {|a_method| a_method.full_name == 'Set#<<'}
|
213
|
+
assert_equal('Set#<<', method.full_name)
|
214
|
+
assert_equal(2, method.called)
|
215
|
+
assert_in_delta(0, method.total_time, 0.05)
|
216
|
+
assert_in_delta(0, method.self_time, 0.05)
|
217
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
218
|
+
assert_in_delta(0, method.children_time, 0.05)
|
219
|
+
end
|
220
|
+
|
221
|
+
method = methods.detect {|a_method| a_method.full_name == 'Kernel#object_id'}
|
222
|
+
assert_equal('Kernel#object_id', method.full_name)
|
223
|
+
assert_equal(2, method.called)
|
224
|
+
assert_in_delta(0, method.total_time, 0.05)
|
225
|
+
assert_in_delta(0, method.self_time, 0.05)
|
226
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
227
|
+
assert_in_delta(0, method.children_time, 0.05)
|
228
|
+
|
229
|
+
method = methods.detect {|a_method| a_method.full_name == 'Enumerator::Yielder#yield'}
|
230
|
+
assert_equal('Enumerator::Yielder#yield', method.full_name)
|
231
|
+
assert_equal(2, method.called)
|
232
|
+
assert_in_delta(0, method.total_time, 0.05)
|
233
|
+
assert_in_delta(0, method.self_time, 0.05)
|
234
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
235
|
+
assert_in_delta(0, method.children_time, 0.05)
|
236
|
+
|
237
|
+
method = methods.detect {|a_method| a_method.full_name == '<Class::Fiber>#current'}
|
238
|
+
assert_equal('<Class::Fiber>#current', method.full_name)
|
239
|
+
assert_equal(2, method.called)
|
240
|
+
assert_in_delta(0, method.total_time, 0.05)
|
241
|
+
assert_in_delta(0, method.self_time, 0.05)
|
242
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
243
|
+
assert_in_delta(0, method.children_time, 0.05)
|
57
244
|
end
|
58
245
|
|
59
246
|
def test_merged_fibers
|
60
|
-
result = RubyProf.profile(merge_fibers: true) {
|
247
|
+
result = RubyProf.profile(merge_fibers: true) { enumerator_with_fibers }
|
248
|
+
|
61
249
|
assert_equal(1, result.threads.length)
|
62
250
|
|
63
251
|
thread = result.threads.first
|
data/test/gc_test.rb
CHANGED
@@ -2,8 +2,17 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
Minitest::Test.i_suck_and_my_tests_are_order_dependent!
|
5
6
|
|
6
7
|
class GcTest < TestCase
|
8
|
+
def setup
|
9
|
+
GC.stress = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
GC.stress = false
|
14
|
+
end
|
15
|
+
|
7
16
|
def some_method
|
8
17
|
Array.new(3 * 4)
|
9
18
|
end
|
@@ -15,82 +24,67 @@ class GcTest < TestCase
|
|
15
24
|
end
|
16
25
|
|
17
26
|
def test_hold_onto_thread
|
18
|
-
threads =
|
27
|
+
threads = 5.times.reduce(Array.new) do |array, i|
|
19
28
|
array.concat(run_profile.threads)
|
20
|
-
GC.start
|
21
29
|
array
|
22
30
|
end
|
23
31
|
|
24
32
|
threads.each do |thread|
|
25
|
-
|
26
|
-
thread.id
|
27
|
-
end
|
28
|
-
assert_match(/has already been freed/, error.message)
|
33
|
+
refute_nil(thread.id)
|
29
34
|
end
|
30
|
-
assert(true)
|
31
35
|
end
|
32
36
|
|
37
|
+
|
33
38
|
def test_hold_onto_method
|
34
|
-
methods =
|
35
|
-
|
36
|
-
|
39
|
+
methods = 5.times.reduce(Array.new) do |array, i|
|
40
|
+
profile = run_profile
|
41
|
+
array.concat(profile.threads.map(&:methods).flatten)
|
37
42
|
array
|
38
43
|
end
|
39
44
|
|
40
45
|
methods.each do |method|
|
41
|
-
|
42
|
-
method.method_name
|
43
|
-
end
|
44
|
-
assert_match(/has already been freed/, error.message)
|
46
|
+
refute_nil(method.method_name)
|
45
47
|
end
|
46
|
-
assert(true)
|
47
48
|
end
|
48
49
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
def test_hold_onto_call_trees
|
51
|
+
method_call_infos = 5.times.reduce(Array.new) do |array, i|
|
52
|
+
profile = run_profile
|
53
|
+
call_trees = profile.threads.map(&:methods).flatten.map(&:call_trees).flatten
|
54
|
+
array.concat(call_trees)
|
53
55
|
array
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
call_info.source_file
|
59
|
-
end
|
60
|
-
assert_match(/has already been freed/, error.message)
|
58
|
+
method_call_infos.each do |call_trees|
|
59
|
+
refute_empty(call_trees.call_trees)
|
61
60
|
end
|
62
|
-
assert(true)
|
63
61
|
end
|
64
62
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
def test_hold_onto_measurements
|
64
|
+
measurements = 5.times.reduce(Array.new) do |array, i|
|
65
|
+
profile = run_profile
|
66
|
+
measurements = profile.threads.map(&:methods).flatten.map(&:measurement)
|
67
|
+
array.concat(measurements)
|
69
68
|
array
|
70
69
|
end
|
71
70
|
|
72
|
-
|
71
|
+
measurements.each do |measurement|
|
73
72
|
error = assert_raises(RuntimeError) do
|
74
|
-
|
73
|
+
measurement.total_time
|
75
74
|
end
|
76
|
-
assert_match(/has already been freed/, error.message)
|
75
|
+
assert_match(/RubyProf::Measurement instance has already been freed/, error.message)
|
77
76
|
end
|
78
77
|
assert(true)
|
79
78
|
end
|
80
79
|
|
81
|
-
def
|
82
|
-
|
83
|
-
array.concat(run_profile.threads.map(&:
|
84
|
-
GC.start
|
80
|
+
def test_hold_onto_root_call_tree
|
81
|
+
call_trees = 5.times.reduce(Array.new) do |array, i|
|
82
|
+
array.concat(run_profile.threads.map(&:call_tree))
|
85
83
|
array
|
86
84
|
end
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
measurement.total_time
|
91
|
-
end
|
92
|
-
assert_match(/has already been freed/, error.message)
|
86
|
+
call_trees.each do |call_tree|
|
87
|
+
refute_nil(call_tree.source_file)
|
93
88
|
end
|
94
|
-
assert(true)
|
95
89
|
end
|
96
90
|
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
|
6
|
+
class InverseCallTreeTest < TestCase
|
7
|
+
INVERSE_DEPTH = 5
|
8
|
+
|
9
|
+
def setup
|
10
|
+
# Need to use wall time for this test due to the sleep calls
|
11
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
12
|
+
end
|
13
|
+
|
14
|
+
INVERSE_DEPTH.times do |i|
|
15
|
+
if i == 0
|
16
|
+
define_method("method_#{i}") do
|
17
|
+
sleep_amount = (i + 1) * 0.05
|
18
|
+
RubyProf.start
|
19
|
+
sleep(sleep_amount)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
define_method("method_#{i}") do
|
23
|
+
method_name = "method_#{i-1}"
|
24
|
+
sleep_amount = (i + 1) * 0.05
|
25
|
+
self.send(method_name.to_sym)
|
26
|
+
sleep(sleep_amount)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_inverse
|
32
|
+
method_name = "method_#{INVERSE_DEPTH - 1}"
|
33
|
+
self.send(method_name.to_sym)
|
34
|
+
profile = RubyProf.stop
|
35
|
+
|
36
|
+
assert_equal(1, profile.threads.count)
|
37
|
+
|
38
|
+
thread = profile.threads.first
|
39
|
+
assert_in_delta(0.79, thread.total_time, 0.05)
|
40
|
+
|
41
|
+
assert_equal(7, thread.methods.length)
|
42
|
+
methods = thread.methods.sort.reverse
|
43
|
+
|
44
|
+
# InverseCallTreeTest#test_inverse
|
45
|
+
method = methods[0]
|
46
|
+
assert_equal('InverseCallTreeTest#test_inverse', method.full_name)
|
47
|
+
assert_equal(34, method.line)
|
48
|
+
|
49
|
+
assert_equal(0, method.call_trees.callers.count)
|
50
|
+
|
51
|
+
assert_equal(1, method.call_trees.callees.count)
|
52
|
+
call_tree = method.call_trees.callees[0]
|
53
|
+
assert_equal('InverseCallTreeTest#method_4', call_tree.target.full_name)
|
54
|
+
assert_equal(26, call_tree.line)
|
55
|
+
|
56
|
+
# InverseCallTreeTest#method_4
|
57
|
+
method = methods[1]
|
58
|
+
assert_equal('InverseCallTreeTest#method_4', method.full_name)
|
59
|
+
assert_equal(26, method.line)
|
60
|
+
|
61
|
+
assert_equal(1, method.call_trees.callers.count)
|
62
|
+
call_tree = method.call_trees.callers[0]
|
63
|
+
assert_equal('InverseCallTreeTest#test_inverse', call_tree.parent.target.full_name)
|
64
|
+
assert_equal(26, call_tree.line)
|
65
|
+
|
66
|
+
assert_equal(2, method.call_trees.callees.count)
|
67
|
+
call_tree = method.call_trees.callees[0]
|
68
|
+
assert_equal('InverseCallTreeTest#method_3', call_tree.target.full_name)
|
69
|
+
assert_equal(26, call_tree.line)
|
70
|
+
|
71
|
+
# Kernel#sleep
|
72
|
+
method = methods[2]
|
73
|
+
assert_equal('Kernel#sleep', method.full_name)
|
74
|
+
assert_equal(0, method.line)
|
75
|
+
|
76
|
+
assert_equal(5, method.call_trees.callers.count)
|
77
|
+
call_tree = method.call_trees.callers[0]
|
78
|
+
assert_equal('InverseCallTreeTest#method_0', call_tree.parent.target.full_name)
|
79
|
+
assert_equal(19, call_tree.line)
|
80
|
+
|
81
|
+
call_tree = method.call_trees.callers[1]
|
82
|
+
assert_equal('InverseCallTreeTest#method_1', call_tree.parent.target.full_name)
|
83
|
+
assert_equal(26, call_tree.line)
|
84
|
+
|
85
|
+
call_tree = method.call_trees.callers[2]
|
86
|
+
assert_equal('InverseCallTreeTest#method_2', call_tree.parent.target.full_name)
|
87
|
+
assert_equal(26, call_tree.line)
|
88
|
+
call_tree = method.call_trees.callers[3]
|
89
|
+
|
90
|
+
assert_equal('InverseCallTreeTest#method_3', call_tree.parent.target.full_name)
|
91
|
+
assert_equal(26, call_tree.line)
|
92
|
+
|
93
|
+
call_tree = method.call_trees.callers[4]
|
94
|
+
assert_equal('InverseCallTreeTest#method_4', call_tree.parent.target.full_name)
|
95
|
+
assert_equal(26, call_tree.line)
|
96
|
+
|
97
|
+
assert_equal(0, method.call_trees.callees.count)
|
98
|
+
|
99
|
+
# InverseCallTreeTest#method_3
|
100
|
+
method = methods[3]
|
101
|
+
assert_equal('InverseCallTreeTest#method_3', method.full_name)
|
102
|
+
assert_equal(26, method.line)
|
103
|
+
|
104
|
+
assert_equal(1, method.call_trees.callers.count)
|
105
|
+
call_tree = method.call_trees.callers[0]
|
106
|
+
assert_equal('InverseCallTreeTest#method_4', call_tree.parent.target.full_name)
|
107
|
+
assert_equal(26, call_tree.line)
|
108
|
+
|
109
|
+
assert_equal(2, method.call_trees.callees.count)
|
110
|
+
call_tree = method.call_trees.callees[0]
|
111
|
+
assert_equal('InverseCallTreeTest#method_2', call_tree.target.full_name)
|
112
|
+
assert_equal(26, call_tree.line)
|
113
|
+
|
114
|
+
call_tree = method.call_trees.callees[1]
|
115
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
116
|
+
assert_equal(26, call_tree.line)
|
117
|
+
|
118
|
+
# InverseCallTreeTest#method_2
|
119
|
+
method = methods[4]
|
120
|
+
assert_equal('InverseCallTreeTest#method_2', method.full_name)
|
121
|
+
assert_equal(26, method.line)
|
122
|
+
|
123
|
+
assert_equal(1, method.call_trees.callers.count)
|
124
|
+
call_tree = method.call_trees.callers[0]
|
125
|
+
assert_equal('InverseCallTreeTest#method_3', call_tree.parent.target.full_name)
|
126
|
+
assert_equal(26, call_tree.line)
|
127
|
+
|
128
|
+
assert_equal(2, method.call_trees.callees.count)
|
129
|
+
call_tree = method.call_trees.callees[0]
|
130
|
+
assert_equal('InverseCallTreeTest#method_1', call_tree.target.full_name)
|
131
|
+
assert_equal(26, call_tree.line)
|
132
|
+
|
133
|
+
call_tree = method.call_trees.callees[1]
|
134
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
135
|
+
assert_equal(26, call_tree.line)
|
136
|
+
|
137
|
+
call_tree = method.call_trees.callees[1]
|
138
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
139
|
+
assert_equal(26, call_tree.line)
|
140
|
+
|
141
|
+
# InverseCallTreeTest#method_1
|
142
|
+
method = methods[5]
|
143
|
+
assert_equal('InverseCallTreeTest#method_1', method.full_name)
|
144
|
+
assert_equal(26, method.line)
|
145
|
+
|
146
|
+
assert_equal(1, method.call_trees.callers.count)
|
147
|
+
call_tree = method.call_trees.callers[0]
|
148
|
+
assert_equal('InverseCallTreeTest#method_2', call_tree.parent.target.full_name)
|
149
|
+
assert_equal(26, call_tree.line)
|
150
|
+
|
151
|
+
assert_equal(2, method.call_trees.callees.count)
|
152
|
+
call_tree = method.call_trees.callees[0]
|
153
|
+
assert_equal('InverseCallTreeTest#method_0', call_tree.target.full_name)
|
154
|
+
assert_equal(19, call_tree.line)
|
155
|
+
|
156
|
+
call_tree = method.call_trees.callees[1]
|
157
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
158
|
+
assert_equal(26, call_tree.line)
|
159
|
+
|
160
|
+
# InverseCallTreeTest#method_0
|
161
|
+
method = methods[6]
|
162
|
+
assert_equal('InverseCallTreeTest#method_0', method.full_name)
|
163
|
+
assert_equal(19, method.line)
|
164
|
+
|
165
|
+
assert_equal(1, method.call_trees.callers.count)
|
166
|
+
call_tree = method.call_trees.callers[0]
|
167
|
+
assert_equal('InverseCallTreeTest#method_1', call_tree.parent.target.full_name)
|
168
|
+
assert_equal(19, call_tree.line)
|
169
|
+
|
170
|
+
assert_equal(1, method.call_trees.callees.count)
|
171
|
+
call_tree = method.call_trees.callees[0]
|
172
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
173
|
+
assert_equal(19, call_tree.line)
|
174
|
+
end
|
175
|
+
end
|