ruby-prof 0.13.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +579 -371
- data/LICENSE +24 -23
- data/README.rdoc +5 -433
- data/Rakefile +98 -110
- data/bin/ruby-prof +328 -329
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +16 -59
- 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 +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 +50 -65
- data/ext/ruby_prof/rp_measure_memory.c +42 -73
- data/ext/ruby_prof/rp_measure_process_time.c +65 -71
- data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
- 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 -420
- data/ext/ruby_prof/rp_method.h +62 -57
- data/ext/ruby_prof/rp_profile.c +908 -0
- data/ext/ruby_prof/rp_profile.h +35 -0
- data/ext/ruby_prof/rp_stack.c +212 -128
- data/ext/ruby_prof/rp_stack.h +53 -51
- data/ext/ruby_prof/rp_thread.c +362 -268
- data/ext/ruby_prof/rp_thread.h +39 -27
- data/ext/ruby_prof/ruby_prof.c +52 -695
- data/ext/ruby_prof/ruby_prof.h +26 -55
- data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
- data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
- data/lib/ruby-prof.rb +52 -67
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -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 -169
- 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 -131
- data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
- data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
- data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
- data/lib/ruby-prof/printers/dot_printer.rb +132 -132
- data/lib/ruby-prof/printers/flat_printer.rb +53 -69
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
- data/lib/ruby-prof/printers/graph_printer.rb +113 -116
- data/lib/ruby-prof/printers/multi_printer.rb +127 -56
- data/lib/ruby-prof/profile.rb +37 -77
- data/lib/ruby-prof/rack.rb +62 -15
- data/lib/ruby-prof/task.rb +147 -147
- data/lib/ruby-prof/thread.rb +10 -12
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -10
- data/ruby-prof.gemspec +65 -61
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +126 -0
- data/test/basic_test.rb +43 -128
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/duplicate_names_test.rb +32 -32
- data/test/dynamic_method_test.rb +53 -74
- data/test/enumerable_test.rb +21 -16
- data/test/exceptions_test.rb +24 -16
- data/test/exclude_methods_test.rb +151 -0
- data/test/exclude_threads_test.rb +53 -54
- data/test/fiber_test.rb +129 -65
- data/test/gc_test.rb +90 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +158 -71
- data/test/marshal_test.rb +113 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +375 -25
- data/test/measure_allocations_trace_test.rb +375 -0
- data/test/measure_memory_trace_test.rb +1101 -0
- data/test/measure_process_time_test.rb +785 -62
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +434 -254
- data/test/multi_printer_test.rb +71 -82
- data/test/no_method_class_test.rb +15 -15
- data/test/pause_resume_test.rb +175 -166
- data/test/prime.rb +54 -54
- 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 -257
- 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 +206 -215
- data/test/singleton_test.rb +38 -38
- data/test/stack_printer_test.rb +64 -78
- data/test/start_stop_test.rb +109 -112
- data/test/test_helper.rb +13 -115
- data/test/thread_test.rb +144 -178
- data/test/unique_call_path_test.rb +120 -224
- data/test/yarv_test.rb +56 -0
- metadata +77 -133
- data/doc/LICENSE.html +0 -155
- data/doc/README_rdoc.html +0 -648
- data/doc/Rack.html +0 -167
- data/doc/Rack/RubyProf.html +0 -319
- data/doc/RubyProf.html +0 -1000
- data/doc/RubyProf/AbstractPrinter.html +0 -580
- data/doc/RubyProf/AggregateCallInfo.html +0 -570
- data/doc/RubyProf/CallInfo.html +0 -512
- data/doc/RubyProf/CallInfoPrinter.html +0 -190
- data/doc/RubyProf/CallInfoVisitor.html +0 -332
- data/doc/RubyProf/CallStackPrinter.html +0 -1600
- data/doc/RubyProf/CallTreePrinter.html +0 -413
- data/doc/RubyProf/Cmd.html +0 -669
- data/doc/RubyProf/DotPrinter.html +0 -312
- data/doc/RubyProf/FlatPrinter.html +0 -229
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
- data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
- data/doc/RubyProf/GraphPrinter.html +0 -209
- data/doc/RubyProf/MethodInfo.html +0 -713
- data/doc/RubyProf/MultiPrinter.html +0 -407
- data/doc/RubyProf/Profile.html +0 -821
- data/doc/RubyProf/ProfileTask.html +0 -532
- data/doc/RubyProf/Test.html +0 -578
- data/doc/RubyProf/Thread.html +0 -262
- data/doc/created.rid +0 -32
- data/doc/examples/flat_txt.html +0 -191
- data/doc/examples/graph_txt.html +0 -305
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -647
- data/doc/js/darkfish.js +0 -155
- data/doc/js/jquery.js +0 -18
- data/doc/js/navigation.js +0 -142
- data/doc/js/search.js +0 -94
- data/doc/js/search_index.js +0 -1
- data/doc/js/searcher.js +0 -228
- data/doc/rdoc.css +0 -543
- data/doc/table_of_contents.html +0 -462
- data/examples/empty.png +0 -0
- data/examples/flat.txt +0 -55
- data/examples/graph.dot +0 -106
- data/examples/graph.html +0 -823
- data/examples/graph.png +0 -0
- data/examples/graph.txt +0 -170
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -906
- data/examples/multi.grind.dat +0 -194
- data/examples/multi.stack.html +0 -573
- data/examples/plus.png +0 -0
- data/examples/stack.html +0 -573
- data/ext/ruby_prof/rp_call_info.c +0 -407
- data/ext/ruby_prof/rp_call_info.h +0 -48
- data/ext/ruby_prof/rp_measure.c +0 -48
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
- data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
- data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
- data/ext/ruby_prof/version.h +0 -7
- data/lib/ruby-prof/aggregate_call_info.rb +0 -72
- data/lib/ruby-prof/call_info.rb +0 -89
- data/lib/ruby-prof/call_info_visitor.rb +0 -44
- data/lib/ruby-prof/images/empty.png +0 -0
- data/lib/ruby-prof/images/minus.png +0 -0
- data/lib/ruby-prof/images/plus.png +0 -0
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
- data/lib/ruby-prof/test.rb +0 -150
- data/test/aggregate_test.rb +0 -136
- data/test/call_info_test.rb +0 -78
- data/test/call_info_visitor_test.rb +0 -31
- data/test/exec_test.rb +0 -14
- data/test/measure_cpu_time_test.rb +0 -220
- data/test/measure_gc_runs_test.rb +0 -32
- data/test/measure_gc_time_test.rb +0 -36
- data/test/measure_memory_test.rb +0 -31
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
- data/test/test_suite.rb +0 -37
@@ -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
|
@@ -1,255 +1,435 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
assert_equal(
|
31
|
-
assert_equal(
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
assert_in_delta(0.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
assert_equal('
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
assert_in_delta(0, methods[
|
101
|
-
assert_in_delta(0, methods[
|
102
|
-
|
103
|
-
assert_in_delta(0.
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
assert_in_delta(0, methods[
|
108
|
-
assert_in_delta(0, methods[
|
109
|
-
assert_in_delta(0, methods[
|
110
|
-
|
111
|
-
|
112
|
-
assert_in_delta(0, methods[
|
113
|
-
assert_in_delta(0, methods[
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
assert_in_delta(0,
|
149
|
-
assert_in_delta(0,
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
assert_in_delta(0
|
156
|
-
assert_in_delta(0,
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
#
|
174
|
-
|
175
|
-
#
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
assert_in_delta(0,
|
198
|
-
|
199
|
-
assert_in_delta(0.
|
200
|
-
assert_in_delta(0,
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
assert_in_delta(0,
|
205
|
-
assert_in_delta(0.
|
206
|
-
|
207
|
-
assert_in_delta(0,
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
assert_in_delta(0,
|
212
|
-
assert_in_delta(0,
|
213
|
-
assert_in_delta(0,
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
assert_in_delta(0.
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
assert_in_delta(0, methods[
|
248
|
-
assert_in_delta(0, methods[
|
249
|
-
assert_in_delta(0, methods[
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
assert_in_delta(0, methods[
|
254
|
-
|
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
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
|
399
|
+
method = methods.detect {|a_method| a_method.full_name == '<Class::RubyProf::C3>#instance'}
|
400
|
+
assert_equal('<Class::RubyProf::C3>#instance', method.full_name)
|
401
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
402
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
403
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
404
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
405
|
+
else
|
406
|
+
method = methods.detect {|a_method| a_method.full_name == 'Singleton::SingletonClassMethods#instance'}
|
407
|
+
assert_equal('Singleton::SingletonClassMethods#instance', method.full_name)
|
408
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
409
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
410
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
411
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
412
|
+
end
|
413
|
+
|
414
|
+
method = methods.detect {|a_method| a_method.full_name == 'Thread::Mutex#synchronize'}
|
415
|
+
assert_equal('Thread::Mutex#synchronize', method.full_name)
|
416
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
417
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
418
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
419
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
420
|
+
|
421
|
+
method = methods.detect {|a_method| a_method.full_name == 'Class#new'}
|
422
|
+
assert_equal('Class#new', method.full_name)
|
423
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
424
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
425
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
426
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
427
|
+
|
428
|
+
method = methods.detect {|a_method| a_method.full_name == 'BasicObject#initialize'}
|
429
|
+
assert_equal('BasicObject#initialize', method.full_name)
|
430
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
431
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
432
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
433
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
434
|
+
end
|
255
435
|
end
|