ruby-prof 1.8.0-x64-mswin64-140
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.
- checksums.yaml +7 -0
- data/CHANGES +665 -0
- data/LICENSE +25 -0
- data/README.md +5 -0
- data/Rakefile +98 -0
- data/bin/ruby-prof +341 -0
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +23 -0
- data/ext/ruby_prof/rp_allocation.c +327 -0
- data/ext/ruby_prof/rp_allocation.h +32 -0
- data/ext/ruby_prof/rp_call_tree.c +502 -0
- data/ext/ruby_prof/rp_call_tree.h +47 -0
- data/ext/ruby_prof/rp_call_trees.c +296 -0
- data/ext/ruby_prof/rp_call_trees.h +28 -0
- data/ext/ruby_prof/rp_measure_allocations.c +47 -0
- data/ext/ruby_prof/rp_measure_memory.c +46 -0
- data/ext/ruby_prof/rp_measure_process_time.c +64 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +52 -0
- data/ext/ruby_prof/rp_measurement.c +359 -0
- data/ext/ruby_prof/rp_measurement.h +52 -0
- data/ext/ruby_prof/rp_method.c +551 -0
- data/ext/ruby_prof/rp_method.h +66 -0
- data/ext/ruby_prof/rp_profile.c +933 -0
- data/ext/ruby_prof/rp_profile.h +36 -0
- data/ext/ruby_prof/rp_stack.c +212 -0
- data/ext/ruby_prof/rp_stack.h +53 -0
- data/ext/ruby_prof/rp_thread.c +433 -0
- data/ext/ruby_prof/rp_thread.h +39 -0
- data/ext/ruby_prof/ruby_prof.c +50 -0
- data/ext/ruby_prof/ruby_prof.h +35 -0
- data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +158 -0
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +711 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
- data/lib/ruby-prof/call_tree.rb +57 -0
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/compatibility.rb +113 -0
- data/lib/ruby-prof/exclude_common_methods.rb +204 -0
- data/lib/ruby-prof/measurement.rb +17 -0
- data/lib/ruby-prof/method_info.rb +87 -0
- data/lib/ruby-prof/printers/abstract_printer.rb +156 -0
- data/lib/ruby-prof/printers/call_info_printer.rb +53 -0
- data/lib/ruby-prof/printers/call_stack_printer.rb +180 -0
- data/lib/ruby-prof/printers/call_tree_printer.rb +145 -0
- data/lib/ruby-prof/printers/dot_printer.rb +132 -0
- data/lib/ruby-prof/printers/flat_printer.rb +53 -0
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
- data/lib/ruby-prof/printers/graph_printer.rb +113 -0
- data/lib/ruby-prof/printers/multi_printer.rb +127 -0
- data/lib/ruby-prof/profile.rb +70 -0
- data/lib/ruby-prof/rack.rb +105 -0
- data/lib/ruby-prof/task.rb +147 -0
- data/lib/ruby-prof/thread.rb +20 -0
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/ruby-prof.rb +52 -0
- data/lib/unprof.rb +10 -0
- data/ruby-prof.gemspec +67 -0
- data/test/abstract_printer_test.rb +27 -0
- data/test/alias_test.rb +117 -0
- data/test/call_tree_builder.rb +126 -0
- data/test/call_tree_test.rb +94 -0
- data/test/call_tree_visitor_test.rb +27 -0
- data/test/call_trees_test.rb +66 -0
- data/test/compatibility_test.rb +49 -0
- data/test/duplicate_names_test.rb +32 -0
- data/test/dynamic_method_test.rb +50 -0
- data/test/enumerable_test.rb +23 -0
- data/test/exceptions_test.rb +24 -0
- data/test/exclude_methods_test.rb +363 -0
- data/test/exclude_threads_test.rb +48 -0
- data/test/fiber_test.rb +195 -0
- data/test/gc_test.rb +104 -0
- data/test/inverse_call_tree_test.rb +174 -0
- data/test/line_number_test.rb +426 -0
- data/test/marshal_test.rb +145 -0
- data/test/measure_allocations.rb +26 -0
- data/test/measure_allocations_test.rb +1172 -0
- data/test/measure_process_time_test.rb +3330 -0
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +635 -0
- data/test/measurement_test.rb +82 -0
- data/test/merge_test.rb +146 -0
- data/test/method_info_test.rb +100 -0
- data/test/multi_printer_test.rb +66 -0
- data/test/no_method_class_test.rb +15 -0
- data/test/pause_resume_test.rb +171 -0
- data/test/prime.rb +54 -0
- data/test/prime_script.rb +6 -0
- data/test/printer_call_stack_test.rb +27 -0
- data/test/printer_call_tree_test.rb +30 -0
- data/test/printer_flat_test.rb +99 -0
- data/test/printer_graph_html_test.rb +59 -0
- data/test/printer_graph_test.rb +40 -0
- data/test/printers_test.rb +178 -0
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/profile_test.rb +101 -0
- data/test/rack_test.rb +93 -0
- data/test/recursive_test.rb +796 -0
- data/test/scheduler.rb +363 -0
- data/test/singleton_test.rb +38 -0
- data/test/stack_printer_test.rb +61 -0
- data/test/start_stop_test.rb +106 -0
- data/test/test_helper.rb +21 -0
- data/test/thread_test.rb +229 -0
- data/test/unique_call_path_test.rb +123 -0
- data/test/yarv_test.rb +56 -0
- metadata +228 -0
data/test/thread_test.rb
ADDED
|
@@ -0,0 +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
|
+
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
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
+
|
|
6
|
+
class UniqueCallPath
|
|
7
|
+
def method_a(i)
|
|
8
|
+
if i==1
|
|
9
|
+
method_b
|
|
10
|
+
else
|
|
11
|
+
method_c
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def method_b
|
|
16
|
+
method_c
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def method_c
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_k(i)
|
|
23
|
+
method_a(i)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# -- Tests ----
|
|
29
|
+
class UniqueCallPathTest < TestCase
|
|
30
|
+
def test_root
|
|
31
|
+
unique_call_path = UniqueCallPath.new
|
|
32
|
+
|
|
33
|
+
result = RubyProf::Profile.profile do
|
|
34
|
+
unique_call_path.method_a(1)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
root_call_info = result.threads.first.call_tree
|
|
38
|
+
assert_equal("UniqueCallPathTest#test_root", root_call_info.target.full_name)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_root_children
|
|
42
|
+
unique_call_path = UniqueCallPath.new
|
|
43
|
+
|
|
44
|
+
result = RubyProf::Profile.profile do
|
|
45
|
+
unique_call_path.method_a(1)
|
|
46
|
+
unique_call_path.method_k(2)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
root_call_info = result.threads.first.call_tree
|
|
50
|
+
children = root_call_info.children.sort do |c1, c2|
|
|
51
|
+
c1.target.full_name <=> c2.target.full_name
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
assert_equal(2, children.length)
|
|
55
|
+
assert_equal("UniqueCallPath#method_a", children[0].target.full_name)
|
|
56
|
+
assert_equal("UniqueCallPath#method_k", children[1].target.full_name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_children_of
|
|
60
|
+
unique_call_path = UniqueCallPath.new
|
|
61
|
+
|
|
62
|
+
result = RubyProf::Profile.profile do
|
|
63
|
+
unique_call_path.method_a(1)
|
|
64
|
+
unique_call_path.method_k(2)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
root_call_info = result.threads.first.call_tree
|
|
68
|
+
assert_equal("UniqueCallPathTest#test_children_of", root_call_info.target.full_name)
|
|
69
|
+
|
|
70
|
+
call_info_a = root_call_info.children.detect do |call_tree|
|
|
71
|
+
call_tree.target.full_name == "UniqueCallPath#method_a"
|
|
72
|
+
end
|
|
73
|
+
refute_nil(call_info_a)
|
|
74
|
+
|
|
75
|
+
_children_of_a = call_info_a.children.inject(Array.new) do |array, c|
|
|
76
|
+
if c.parent.eql?(call_info_a)
|
|
77
|
+
array << c
|
|
78
|
+
end
|
|
79
|
+
array
|
|
80
|
+
end
|
|
81
|
+
|
|
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)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_unique_path
|
|
88
|
+
unique_call_path = UniqueCallPath.new
|
|
89
|
+
|
|
90
|
+
result = RubyProf::Profile.profile do
|
|
91
|
+
unique_call_path.method_a(1)
|
|
92
|
+
unique_call_path.method_k(1)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
root_call_info = result.threads.first.call_tree
|
|
96
|
+
assert_equal("UniqueCallPathTest#test_unique_path", root_call_info.target.full_name)
|
|
97
|
+
|
|
98
|
+
call_info_a = root_call_info.children.detect do |call_tree|
|
|
99
|
+
call_tree.target.full_name == "UniqueCallPath#method_a"
|
|
100
|
+
end
|
|
101
|
+
refute_nil(call_info_a)
|
|
102
|
+
|
|
103
|
+
children_of_a = call_info_a.children.reduce(Array.new) do |array, c|
|
|
104
|
+
if c.parent.eql?(call_info_a)
|
|
105
|
+
array << c
|
|
106
|
+
end
|
|
107
|
+
array
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
children_of_a = children_of_a.sort do |c1, c2|
|
|
111
|
+
c1.target.full_name <=> c2.target.full_name
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
assert_equal(2, call_info_a.children.length)
|
|
115
|
+
assert_equal(2, children_of_a.length)
|
|
116
|
+
|
|
117
|
+
assert_equal(1, children_of_a[0].called)
|
|
118
|
+
assert_equal("Integer#==", children_of_a[0].target.full_name)
|
|
119
|
+
|
|
120
|
+
assert_equal(1, children_of_a[1].called)
|
|
121
|
+
assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
|
|
122
|
+
end
|
|
123
|
+
end
|
data/test/yarv_test.rb
ADDED
|
@@ -0,0 +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
|
metadata
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby-prof
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.8.0
|
|
5
|
+
platform: x64-mswin64-140
|
|
6
|
+
authors:
|
|
7
|
+
- Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-02-07 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: base64
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: ostruct
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: minitest
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rake-compiler
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rdoc
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
description: |
|
|
83
|
+
ruby-prof is a fast code profiler for Ruby. It is a C extension and
|
|
84
|
+
therefore is many times faster than the standard Ruby profiler. It
|
|
85
|
+
supports both flat and graph profiles. For each method, graph profiles
|
|
86
|
+
show how long the method ran, which methods called it and which
|
|
87
|
+
methods it called. RubyProf generate both text and html and can output
|
|
88
|
+
it to standard out or to a file.
|
|
89
|
+
email: shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de
|
|
90
|
+
executables:
|
|
91
|
+
- ruby-prof
|
|
92
|
+
- ruby-prof-check-trace
|
|
93
|
+
extensions: []
|
|
94
|
+
extra_rdoc_files: []
|
|
95
|
+
files:
|
|
96
|
+
- CHANGES
|
|
97
|
+
- LICENSE
|
|
98
|
+
- README.md
|
|
99
|
+
- Rakefile
|
|
100
|
+
- bin/ruby-prof
|
|
101
|
+
- bin/ruby-prof-check-trace
|
|
102
|
+
- ext/ruby_prof/extconf.rb
|
|
103
|
+
- ext/ruby_prof/rp_allocation.c
|
|
104
|
+
- ext/ruby_prof/rp_allocation.h
|
|
105
|
+
- ext/ruby_prof/rp_call_tree.c
|
|
106
|
+
- ext/ruby_prof/rp_call_tree.h
|
|
107
|
+
- ext/ruby_prof/rp_call_trees.c
|
|
108
|
+
- ext/ruby_prof/rp_call_trees.h
|
|
109
|
+
- ext/ruby_prof/rp_measure_allocations.c
|
|
110
|
+
- ext/ruby_prof/rp_measure_memory.c
|
|
111
|
+
- ext/ruby_prof/rp_measure_process_time.c
|
|
112
|
+
- ext/ruby_prof/rp_measure_wall_time.c
|
|
113
|
+
- ext/ruby_prof/rp_measurement.c
|
|
114
|
+
- ext/ruby_prof/rp_measurement.h
|
|
115
|
+
- ext/ruby_prof/rp_method.c
|
|
116
|
+
- ext/ruby_prof/rp_method.h
|
|
117
|
+
- ext/ruby_prof/rp_profile.c
|
|
118
|
+
- ext/ruby_prof/rp_profile.h
|
|
119
|
+
- ext/ruby_prof/rp_stack.c
|
|
120
|
+
- ext/ruby_prof/rp_stack.h
|
|
121
|
+
- ext/ruby_prof/rp_thread.c
|
|
122
|
+
- ext/ruby_prof/rp_thread.h
|
|
123
|
+
- ext/ruby_prof/ruby_prof.c
|
|
124
|
+
- ext/ruby_prof/ruby_prof.h
|
|
125
|
+
- ext/ruby_prof/vc/ruby_prof.sln
|
|
126
|
+
- ext/ruby_prof/vc/ruby_prof.vcxproj
|
|
127
|
+
- lib/ruby-prof.rb
|
|
128
|
+
- lib/ruby-prof/assets/call_stack_printer.html.erb
|
|
129
|
+
- lib/ruby-prof/assets/call_stack_printer.png
|
|
130
|
+
- lib/ruby-prof/assets/graph_printer.html.erb
|
|
131
|
+
- lib/ruby-prof/call_tree.rb
|
|
132
|
+
- lib/ruby-prof/call_tree_visitor.rb
|
|
133
|
+
- lib/ruby-prof/compatibility.rb
|
|
134
|
+
- lib/ruby-prof/exclude_common_methods.rb
|
|
135
|
+
- lib/ruby-prof/measurement.rb
|
|
136
|
+
- lib/ruby-prof/method_info.rb
|
|
137
|
+
- lib/ruby-prof/printers/abstract_printer.rb
|
|
138
|
+
- lib/ruby-prof/printers/call_info_printer.rb
|
|
139
|
+
- lib/ruby-prof/printers/call_stack_printer.rb
|
|
140
|
+
- lib/ruby-prof/printers/call_tree_printer.rb
|
|
141
|
+
- lib/ruby-prof/printers/dot_printer.rb
|
|
142
|
+
- lib/ruby-prof/printers/flat_printer.rb
|
|
143
|
+
- lib/ruby-prof/printers/graph_html_printer.rb
|
|
144
|
+
- lib/ruby-prof/printers/graph_printer.rb
|
|
145
|
+
- lib/ruby-prof/printers/multi_printer.rb
|
|
146
|
+
- lib/ruby-prof/profile.rb
|
|
147
|
+
- lib/ruby-prof/rack.rb
|
|
148
|
+
- lib/ruby-prof/task.rb
|
|
149
|
+
- lib/ruby-prof/thread.rb
|
|
150
|
+
- lib/ruby-prof/version.rb
|
|
151
|
+
- lib/unprof.rb
|
|
152
|
+
- ruby-prof.gemspec
|
|
153
|
+
- test/abstract_printer_test.rb
|
|
154
|
+
- test/alias_test.rb
|
|
155
|
+
- test/call_tree_builder.rb
|
|
156
|
+
- test/call_tree_test.rb
|
|
157
|
+
- test/call_tree_visitor_test.rb
|
|
158
|
+
- test/call_trees_test.rb
|
|
159
|
+
- test/compatibility_test.rb
|
|
160
|
+
- test/duplicate_names_test.rb
|
|
161
|
+
- test/dynamic_method_test.rb
|
|
162
|
+
- test/enumerable_test.rb
|
|
163
|
+
- test/exceptions_test.rb
|
|
164
|
+
- test/exclude_methods_test.rb
|
|
165
|
+
- test/exclude_threads_test.rb
|
|
166
|
+
- test/fiber_test.rb
|
|
167
|
+
- test/gc_test.rb
|
|
168
|
+
- test/inverse_call_tree_test.rb
|
|
169
|
+
- test/line_number_test.rb
|
|
170
|
+
- test/marshal_test.rb
|
|
171
|
+
- test/measure_allocations.rb
|
|
172
|
+
- test/measure_allocations_test.rb
|
|
173
|
+
- test/measure_process_time_test.rb
|
|
174
|
+
- test/measure_times.rb
|
|
175
|
+
- test/measure_wall_time_test.rb
|
|
176
|
+
- test/measurement_test.rb
|
|
177
|
+
- test/merge_test.rb
|
|
178
|
+
- test/method_info_test.rb
|
|
179
|
+
- test/multi_printer_test.rb
|
|
180
|
+
- test/no_method_class_test.rb
|
|
181
|
+
- test/pause_resume_test.rb
|
|
182
|
+
- test/prime.rb
|
|
183
|
+
- test/prime_script.rb
|
|
184
|
+
- test/printer_call_stack_test.rb
|
|
185
|
+
- test/printer_call_tree_test.rb
|
|
186
|
+
- test/printer_flat_test.rb
|
|
187
|
+
- test/printer_graph_html_test.rb
|
|
188
|
+
- test/printer_graph_test.rb
|
|
189
|
+
- test/printers_test.rb
|
|
190
|
+
- test/printing_recursive_graph_test.rb
|
|
191
|
+
- test/profile_test.rb
|
|
192
|
+
- test/rack_test.rb
|
|
193
|
+
- test/recursive_test.rb
|
|
194
|
+
- test/scheduler.rb
|
|
195
|
+
- test/singleton_test.rb
|
|
196
|
+
- test/stack_printer_test.rb
|
|
197
|
+
- test/start_stop_test.rb
|
|
198
|
+
- test/test_helper.rb
|
|
199
|
+
- test/thread_test.rb
|
|
200
|
+
- test/unique_call_path_test.rb
|
|
201
|
+
- test/yarv_test.rb
|
|
202
|
+
homepage: https://github.com/ruby-prof/ruby-prof
|
|
203
|
+
licenses:
|
|
204
|
+
- BSD-2-Clause
|
|
205
|
+
metadata:
|
|
206
|
+
bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
|
|
207
|
+
changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES
|
|
208
|
+
documentation_uri: https://ruby-prof.github.io/
|
|
209
|
+
source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.8.0
|
|
210
|
+
rdoc_options: []
|
|
211
|
+
require_paths:
|
|
212
|
+
- lib
|
|
213
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
|
+
requirements:
|
|
215
|
+
- - ">="
|
|
216
|
+
- !ruby/object:Gem::Version
|
|
217
|
+
version: 3.0.0
|
|
218
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
|
+
requirements:
|
|
220
|
+
- - ">="
|
|
221
|
+
- !ruby/object:Gem::Version
|
|
222
|
+
version: '0'
|
|
223
|
+
requirements: []
|
|
224
|
+
rubygems_version: 4.0.6
|
|
225
|
+
specification_version: 4
|
|
226
|
+
summary: Fast Ruby profiler
|
|
227
|
+
test_files:
|
|
228
|
+
- test/test_helper.rb
|