ruby-prof 1.4.4-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +608 -0
- data/LICENSE +25 -0
- data/README.md +5 -0
- data/Rakefile +98 -0
- data/bin/ruby-prof +328 -0
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +22 -0
- 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 +287 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_tree.c +367 -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 +47 -0
- data/ext/ruby_prof/rp_measure_memory.c +46 -0
- data/ext/ruby_prof/rp_measure_process_time.c +66 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +64 -0
- data/ext/ruby_prof/rp_measurement.c +237 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +491 -0
- data/ext/ruby_prof/rp_method.h +62 -0
- data/ext/ruby_prof/rp_profile.c +915 -0
- data/ext/ruby_prof/rp_profile.h +35 -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 +362 -0
- data/ext/ruby_prof/rp_thread.h +39 -0
- data/ext/ruby_prof/ruby_prof.c +52 -0
- data/ext/ruby_prof/ruby_prof.h +26 -0
- data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +160 -0
- data/lib/3.1/ruby_prof.so +0 -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 +99 -0
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +17 -0
- data/lib/ruby-prof/method_info.rb +78 -0
- data/lib/ruby-prof/printers/abstract_printer.rb +137 -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 +147 -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 +37 -0
- data/lib/ruby-prof/rack.rb +95 -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 +64 -0
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +122 -0
- data/test/basic_test.rb +43 -0
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/duplicate_names_test.rb +32 -0
- data/test/dynamic_method_test.rb +67 -0
- data/test/enumerable_test.rb +21 -0
- data/test/exceptions_test.rb +24 -0
- data/test/exclude_methods_test.rb +151 -0
- data/test/exclude_threads_test.rb +53 -0
- data/test/fiber_test.rb +129 -0
- data/test/gc_test.rb +100 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +158 -0
- data/test/marshal_test.rb +145 -0
- data/test/measure_allocations.rb +26 -0
- data/test/measure_allocations_test.rb +333 -0
- data/test/measure_memory_test.rb +688 -0
- data/test/measure_process_time_test.rb +1614 -0
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +426 -0
- data/test/multi_printer_test.rb +71 -0
- data/test/no_method_class_test.rb +15 -0
- data/test/pause_resume_test.rb +175 -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 +141 -0
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/profile_test.rb +16 -0
- data/test/rack_test.rb +93 -0
- data/test/recursive_test.rb +430 -0
- data/test/singleton_test.rb +38 -0
- data/test/stack_printer_test.rb +64 -0
- data/test/start_stop_test.rb +109 -0
- data/test/test_helper.rb +13 -0
- data/test/thread_test.rb +144 -0
- data/test/unique_call_path_test.rb +136 -0
- data/test/yarv_test.rb +60 -0
- metadata +187 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# Some classes used in measurement tests
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module RubyProf
|
5
|
+
class C1
|
6
|
+
def C1.sleep_wait
|
7
|
+
sleep(0.1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def C1.busy_wait
|
11
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
12
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def sleep_wait
|
17
|
+
sleep(0.2)
|
18
|
+
end
|
19
|
+
|
20
|
+
def busy_wait
|
21
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
22
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module M1
|
28
|
+
def sleep_wait
|
29
|
+
sleep(0.3)
|
30
|
+
end
|
31
|
+
|
32
|
+
def busy_wait
|
33
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
34
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.3
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class C2
|
40
|
+
include M1
|
41
|
+
extend M1
|
42
|
+
end
|
43
|
+
|
44
|
+
class C3
|
45
|
+
include Singleton
|
46
|
+
def sleep_wait
|
47
|
+
sleep(0.3)
|
48
|
+
end
|
49
|
+
|
50
|
+
def busy_wait
|
51
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
52
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,426 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require_relative './measure_times'
|
6
|
+
|
7
|
+
class MeasureWallTimeTest < TestCase
|
8
|
+
def setup
|
9
|
+
# Need to use wall time for this test due to the sleep calls
|
10
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_mode
|
14
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
15
|
+
assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_class_methods
|
19
|
+
result = RubyProf.profile do
|
20
|
+
RubyProf::C1.sleep_wait
|
21
|
+
end
|
22
|
+
|
23
|
+
thread = result.threads.first
|
24
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
25
|
+
|
26
|
+
methods = result.threads.first.methods.sort.reverse
|
27
|
+
assert_equal(3, methods.length)
|
28
|
+
|
29
|
+
# Check the names
|
30
|
+
assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
|
31
|
+
assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
|
32
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
33
|
+
|
34
|
+
# Check times
|
35
|
+
assert_in_delta(0.1, methods[0].total_time, 0.03)
|
36
|
+
assert_in_delta(0, methods[0].wait_time, 0.03)
|
37
|
+
assert_in_delta(0, methods[0].self_time, 0.03)
|
38
|
+
|
39
|
+
assert_in_delta(0.1, methods[1].total_time, 0.03)
|
40
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
41
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
42
|
+
|
43
|
+
assert_in_delta(0.1, methods[2].total_time, 0.03)
|
44
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
45
|
+
assert_in_delta(0.1, methods[2].self_time, 0.03)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_class_methods_threaded
|
49
|
+
result = RubyProf.profile do
|
50
|
+
background_thread = Thread.new do
|
51
|
+
RubyProf::C1.sleep_wait
|
52
|
+
end
|
53
|
+
background_thread.join
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_equal(2, result.threads.count)
|
57
|
+
|
58
|
+
thread = result.threads.first
|
59
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
60
|
+
|
61
|
+
methods = result.threads.first.methods.sort.reverse
|
62
|
+
assert_equal(4, methods.length)
|
63
|
+
|
64
|
+
# Check times
|
65
|
+
assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
|
66
|
+
assert_in_delta(0.1, methods[0].total_time, 0.03)
|
67
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
68
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
69
|
+
assert_in_delta(0.1, methods[0].children_time, 0.03)
|
70
|
+
|
71
|
+
assert_equal('Thread#join', methods[1].full_name)
|
72
|
+
assert_in_delta(0.1, methods[1].total_time, 0.03)
|
73
|
+
assert_in_delta(0.1, methods[1].wait_time, 0.03)
|
74
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
75
|
+
assert_in_delta(0.0, methods[1].children_time, 0.03)
|
76
|
+
|
77
|
+
assert_equal('<Class::Thread>#new', methods[2].full_name)
|
78
|
+
assert_in_delta(0.0, methods[2].total_time, 0.03)
|
79
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
80
|
+
assert_in_delta(0.0, methods[2].self_time, 0.03)
|
81
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
82
|
+
|
83
|
+
assert_equal('Thread#initialize', methods[3].full_name)
|
84
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
85
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
86
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
87
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
88
|
+
|
89
|
+
thread = result.threads.last
|
90
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
91
|
+
|
92
|
+
methods = result.threads.first.methods.sort.reverse
|
93
|
+
assert_equal(4, methods.length)
|
94
|
+
|
95
|
+
methods = result.threads.last.methods.sort.reverse
|
96
|
+
assert_equal(3, methods.length)
|
97
|
+
|
98
|
+
# Check times
|
99
|
+
assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
|
100
|
+
assert_in_delta(0.1, methods[0].total_time, 0.03)
|
101
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
102
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
103
|
+
assert_in_delta(0.1, methods[0].children_time, 0.03)
|
104
|
+
|
105
|
+
assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
|
106
|
+
assert_in_delta(0.1, methods[1].total_time, 0.03)
|
107
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.03)
|
108
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
109
|
+
assert_in_delta(0.1, methods[1].children_time, 0.03)
|
110
|
+
|
111
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
112
|
+
assert_in_delta(0.1, methods[2].total_time, 0.03)
|
113
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
114
|
+
assert_in_delta(0.1, methods[2].self_time, 0.03)
|
115
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_instance_methods
|
119
|
+
result = RubyProf.profile do
|
120
|
+
RubyProf::C1.new.sleep_wait
|
121
|
+
end
|
122
|
+
|
123
|
+
thread = result.threads.first
|
124
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
125
|
+
|
126
|
+
methods = result.threads.first.methods.sort.reverse
|
127
|
+
assert_equal(5, methods.length)
|
128
|
+
names = methods.map(&:full_name)
|
129
|
+
|
130
|
+
# order can differ
|
131
|
+
assert(names.include?("BasicObject#initialize"))
|
132
|
+
|
133
|
+
# Check times
|
134
|
+
method = methods[0]
|
135
|
+
assert_equal('MeasureWallTimeTest#test_instance_methods', method.full_name)
|
136
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
137
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
138
|
+
assert_in_delta(0, method.self_time, 0.03)
|
139
|
+
|
140
|
+
method = methods[1]
|
141
|
+
assert_equal('RubyProf::C1#sleep_wait', method.full_name)
|
142
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
143
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
144
|
+
assert_in_delta(0, method.self_time, 0.03)
|
145
|
+
|
146
|
+
method = methods[2]
|
147
|
+
assert_equal('Kernel#sleep', method.full_name)
|
148
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
149
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
150
|
+
assert_in_delta(0.2, method.self_time, 0.03)
|
151
|
+
|
152
|
+
method = methods[3]
|
153
|
+
assert_equal('Class#new', method.full_name)
|
154
|
+
assert_in_delta(0, method.total_time, 0.03)
|
155
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
156
|
+
assert_in_delta(0, method.self_time, 0.03)
|
157
|
+
|
158
|
+
method = methods[4]
|
159
|
+
assert_equal('BasicObject#initialize', method.full_name)
|
160
|
+
assert_in_delta(0, method.total_time, 0.03)
|
161
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
162
|
+
assert_in_delta(0, method.self_time, 0.03)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_instance_methods_block
|
166
|
+
result = RubyProf.profile do
|
167
|
+
1.times { RubyProf::C1.new.sleep_wait }
|
168
|
+
end
|
169
|
+
|
170
|
+
methods = result.threads.first.methods.sort.reverse
|
171
|
+
assert_equal(6, methods.length)
|
172
|
+
|
173
|
+
# Check times
|
174
|
+
method = methods[0]
|
175
|
+
assert_equal("MeasureWallTimeTest#test_instance_methods_block", method.full_name)
|
176
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
177
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
178
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
179
|
+
assert_in_delta(0.2, method.children_time, 0.03)
|
180
|
+
|
181
|
+
method = methods[1]
|
182
|
+
assert_equal("Integer#times", method.full_name)
|
183
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
184
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
185
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
186
|
+
assert_in_delta(0.2, method.children_time, 0.03)
|
187
|
+
|
188
|
+
method = methods[2]
|
189
|
+
assert_equal("RubyProf::C1#sleep_wait", method.full_name)
|
190
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
191
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
192
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
193
|
+
assert_in_delta(0.2, method.children_time, 0.03)
|
194
|
+
|
195
|
+
method = methods[3]
|
196
|
+
assert_equal("Kernel#sleep", method.full_name)
|
197
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
198
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
199
|
+
assert_in_delta(0.2, method.self_time, 0.03)
|
200
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
201
|
+
|
202
|
+
method = methods[4]
|
203
|
+
assert_equal("Class#new", method.full_name)
|
204
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
205
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
206
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
207
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
208
|
+
|
209
|
+
method = methods[5]
|
210
|
+
assert_equal("BasicObject#initialize", method.full_name)
|
211
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
212
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
213
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
214
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_instance_methods_threaded
|
218
|
+
result = RubyProf.profile do
|
219
|
+
background_thread = Thread.new do
|
220
|
+
RubyProf::C1.new.sleep_wait
|
221
|
+
end
|
222
|
+
background_thread.join
|
223
|
+
end
|
224
|
+
|
225
|
+
assert_equal(2, result.threads.count)
|
226
|
+
|
227
|
+
thread = result.threads.first
|
228
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
229
|
+
|
230
|
+
methods = result.threads.first.methods.sort.reverse
|
231
|
+
assert_equal(4, methods.length)
|
232
|
+
|
233
|
+
# Check times
|
234
|
+
assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
|
235
|
+
assert_in_delta(0.2, methods[0].total_time, 0.03)
|
236
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
237
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
238
|
+
assert_in_delta(0.2, methods[0].children_time, 0.03)
|
239
|
+
|
240
|
+
assert_equal('Thread#join', methods[1].full_name)
|
241
|
+
assert_in_delta(0.2, methods[1].total_time, 0.03)
|
242
|
+
assert_in_delta(0.2, methods[1].wait_time, 0.03)
|
243
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
244
|
+
assert_in_delta(0.0, methods[1].children_time, 0.03)
|
245
|
+
|
246
|
+
assert_equal('<Class::Thread>#new', methods[2].full_name)
|
247
|
+
assert_in_delta(0.0, methods[2].total_time, 0.03)
|
248
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
249
|
+
assert_in_delta(0.0, methods[2].self_time, 0.03)
|
250
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
251
|
+
|
252
|
+
assert_equal('Thread#initialize', methods[3].full_name)
|
253
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
254
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
255
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
256
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
257
|
+
|
258
|
+
thread = result.threads.last
|
259
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
260
|
+
|
261
|
+
methods = result.threads.first.methods.sort.reverse
|
262
|
+
assert_equal(4, methods.length)
|
263
|
+
|
264
|
+
methods = result.threads.last.methods.sort.reverse
|
265
|
+
assert_equal(5, methods.length)
|
266
|
+
|
267
|
+
# Check times
|
268
|
+
assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
|
269
|
+
assert_in_delta(0.2, methods[0].total_time, 0.03)
|
270
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
271
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
272
|
+
assert_in_delta(0.2, methods[0].children_time, 0.03)
|
273
|
+
|
274
|
+
assert_equal('RubyProf::C1#sleep_wait', methods[1].full_name)
|
275
|
+
assert_in_delta(0.2, methods[1].total_time, 0.03)
|
276
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.03)
|
277
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
278
|
+
assert_in_delta(0.2, methods[1].children_time, 0.03)
|
279
|
+
|
280
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
281
|
+
assert_in_delta(0.2, methods[2].total_time, 0.03)
|
282
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
283
|
+
assert_in_delta(0.2, methods[2].self_time, 0.03)
|
284
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
285
|
+
|
286
|
+
assert_equal('Class#new', methods[3].full_name)
|
287
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
288
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
289
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
290
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
291
|
+
|
292
|
+
assert_equal('BasicObject#initialize', methods[4].full_name)
|
293
|
+
assert_in_delta(0.0, methods[4].total_time, 0.03)
|
294
|
+
assert_in_delta(0.0, methods[4].wait_time, 0.03)
|
295
|
+
assert_in_delta(0.0, methods[4].self_time, 0.03)
|
296
|
+
assert_in_delta(0.0, methods[4].children_time, 0.03)
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_module_methods
|
300
|
+
result = RubyProf.profile do
|
301
|
+
RubyProf::C2.sleep_wait
|
302
|
+
end
|
303
|
+
|
304
|
+
thread = result.threads.first
|
305
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
306
|
+
|
307
|
+
methods = result.threads.first.methods.sort.reverse
|
308
|
+
assert_equal(3, methods.length)
|
309
|
+
|
310
|
+
assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
|
311
|
+
assert_equal('RubyProf::M1#sleep_wait', methods[1].full_name)
|
312
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
313
|
+
|
314
|
+
# Check times
|
315
|
+
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
316
|
+
assert_in_delta(0, methods[0].wait_time, 0.03)
|
317
|
+
assert_in_delta(0, methods[0].self_time, 0.03)
|
318
|
+
|
319
|
+
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
320
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
321
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
322
|
+
|
323
|
+
assert_in_delta(0.3, methods[2].total_time, 0.1)
|
324
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
325
|
+
assert_in_delta(0.3, methods[2].self_time, 0.1)
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_module_instance_methods
|
329
|
+
result = RubyProf.profile do
|
330
|
+
RubyProf::C2.new.sleep_wait
|
331
|
+
end
|
332
|
+
|
333
|
+
thread = result.threads.first
|
334
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
335
|
+
|
336
|
+
methods = result.threads.first.methods.sort.reverse
|
337
|
+
assert_equal(5, methods.length)
|
338
|
+
names = methods.map(&:full_name)
|
339
|
+
assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
|
340
|
+
assert_equal('RubyProf::M1#sleep_wait', names[1])
|
341
|
+
assert_equal('Kernel#sleep', names[2])
|
342
|
+
assert_equal('Class#new', names[3])
|
343
|
+
|
344
|
+
# order can differ
|
345
|
+
assert(names.include?("BasicObject#initialize"))
|
346
|
+
|
347
|
+
# Check times
|
348
|
+
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
349
|
+
assert_in_delta(0, methods[0].wait_time, 0.1)
|
350
|
+
assert_in_delta(0, methods[0].self_time, 0.1)
|
351
|
+
|
352
|
+
assert_in_delta(0.3, methods[1].total_time, 0.03)
|
353
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
354
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
355
|
+
|
356
|
+
assert_in_delta(0.3, methods[2].total_time, 0.03)
|
357
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
358
|
+
assert_in_delta(0.3, methods[2].self_time, 0.03)
|
359
|
+
|
360
|
+
assert_in_delta(0, methods[3].total_time, 0.03)
|
361
|
+
assert_in_delta(0, methods[3].wait_time, 0.03)
|
362
|
+
assert_in_delta(0, methods[3].self_time, 0.03)
|
363
|
+
|
364
|
+
assert_in_delta(0, methods[4].total_time, 0.03)
|
365
|
+
assert_in_delta(0, methods[4].wait_time, 0.03)
|
366
|
+
assert_in_delta(0, methods[4].self_time, 0.03)
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_singleton_methods
|
370
|
+
result = RubyProf.profile do
|
371
|
+
RubyProf::C3.instance.sleep_wait
|
372
|
+
end
|
373
|
+
|
374
|
+
thread = result.threads.first
|
375
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
376
|
+
|
377
|
+
methods = result.threads.first.methods.sort.reverse
|
378
|
+
assert_equal(7, methods.length)
|
379
|
+
|
380
|
+
assert_equal('MeasureWallTimeTest#test_singleton_methods', methods[0].full_name)
|
381
|
+
assert_in_delta(0.3, methods[0].total_time, 0.03)
|
382
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
383
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
384
|
+
assert_in_delta(0.3, methods[0].children_time, 0.03)
|
385
|
+
|
386
|
+
assert_equal('RubyProf::C3#sleep_wait', methods[1].full_name)
|
387
|
+
assert_in_delta(0.3, methods[1].total_time, 0.03)
|
388
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.03)
|
389
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
390
|
+
assert_in_delta(0.3, methods[1].children_time, 0.03)
|
391
|
+
|
392
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
393
|
+
assert_in_delta(0.3, methods[2].total_time, 0.03)
|
394
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
395
|
+
assert_in_delta(0.3, methods[2].self_time, 0.03)
|
396
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
397
|
+
|
398
|
+
method = methods.detect {|a_method| a_method.full_name == 'Singleton::SingletonClassMethods#instance'}
|
399
|
+
assert_equal('Singleton::SingletonClassMethods#instance', method.full_name)
|
400
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
401
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
402
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
403
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
404
|
+
|
405
|
+
method = methods.detect {|a_method| a_method.full_name == 'Thread::Mutex#synchronize'}
|
406
|
+
assert_equal('Thread::Mutex#synchronize', method.full_name)
|
407
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
408
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
409
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
410
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
411
|
+
|
412
|
+
method = methods.detect {|a_method| a_method.full_name == 'Class#new'}
|
413
|
+
assert_equal('Class#new', method.full_name)
|
414
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
415
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
416
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
417
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
418
|
+
|
419
|
+
method = methods.detect {|a_method| a_method.full_name == 'BasicObject#initialize'}
|
420
|
+
assert_equal('BasicObject#initialize', method.full_name)
|
421
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
422
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
423
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
424
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
425
|
+
end
|
426
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
|
6
|
+
# Test data
|
7
|
+
# A
|
8
|
+
# / \
|
9
|
+
# B C
|
10
|
+
# \
|
11
|
+
# B
|
12
|
+
|
13
|
+
class MSTPT
|
14
|
+
def a
|
15
|
+
100.times{b}
|
16
|
+
300.times{c}
|
17
|
+
c;c;c
|
18
|
+
end
|
19
|
+
|
20
|
+
def b
|
21
|
+
sleep 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def c
|
25
|
+
5.times{b}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class MultiPrinterTest < TestCase
|
30
|
+
def setup
|
31
|
+
# Need to use wall time for this test due to the sleep calls
|
32
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_refuses_io_objects
|
36
|
+
# we don't need a real profile for this test
|
37
|
+
p = RubyProf::MultiPrinter.new nil
|
38
|
+
begin
|
39
|
+
p.print(STDOUT)
|
40
|
+
flunk "should have raised an ArgumentError"
|
41
|
+
rescue ArgumentError => e
|
42
|
+
assert_match(/IO/, e.to_s)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_refuses_non_hashes
|
47
|
+
# we don't need a real profile for this test
|
48
|
+
p = RubyProf::MultiPrinter.new nil
|
49
|
+
begin
|
50
|
+
p.print([])
|
51
|
+
flunk "should have raised an ArgumentError"
|
52
|
+
rescue ArgumentError => e
|
53
|
+
assert_match(/hash/, e.to_s)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def print(result)
|
60
|
+
test = caller.first =~ /in `(.*)'/ ? $1 : "test"
|
61
|
+
path = Dir.tmpdir
|
62
|
+
profile = "ruby_prof_#{test}"
|
63
|
+
printer = RubyProf::MultiPrinter.new(result)
|
64
|
+
printer.print(:path => path, :profile => profile,
|
65
|
+
:threshold => 0, :min_percent => 0, :title => "ruby_prof #{test}")
|
66
|
+
if RUBY_PLATFORM =~ /darwin/ && ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT']=="1"
|
67
|
+
system("open '#{printer.stack_profile}'")
|
68
|
+
end
|
69
|
+
[File.read(printer.stack_profile), File.read(printer.graph_profile)]
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
|
6
|
+
# Make sure this works with no class or method
|
7
|
+
result = RubyProf.profile do
|
8
|
+
sleep 1
|
9
|
+
end
|
10
|
+
|
11
|
+
methods = result.threads.first.methods
|
12
|
+
global_method = methods.sort_by {|method| method.full_name}.first
|
13
|
+
if global_method.full_name != 'Kernel#sleep'
|
14
|
+
raise(RuntimeError, "Wrong method name. Expected: Global#[No method]. Actual: #{global_method.full_name}")
|
15
|
+
end
|