ruby-prof 1.0.0
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 +523 -0
- data/LICENSE +25 -0
- data/README.rdoc +5 -0
- data/Rakefile +110 -0
- data/bin/ruby-prof +380 -0
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +36 -0
- data/ext/ruby_prof/rp_allocation.c +292 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_info.c +283 -0
- data/ext/ruby_prof/rp_call_info.h +35 -0
- data/ext/ruby_prof/rp_measure_allocations.c +52 -0
- data/ext/ruby_prof/rp_measure_memory.c +42 -0
- data/ext/ruby_prof/rp_measure_process_time.c +63 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +62 -0
- data/ext/ruby_prof/rp_measurement.c +236 -0
- data/ext/ruby_prof/rp_measurement.h +49 -0
- data/ext/ruby_prof/rp_method.c +642 -0
- data/ext/ruby_prof/rp_method.h +70 -0
- data/ext/ruby_prof/rp_profile.c +881 -0
- data/ext/ruby_prof/rp_profile.h +36 -0
- data/ext/ruby_prof/rp_stack.c +196 -0
- data/ext/ruby_prof/rp_stack.h +56 -0
- data/ext/ruby_prof/rp_thread.c +338 -0
- data/ext/ruby_prof/rp_thread.h +36 -0
- data/ext/ruby_prof/ruby_prof.c +48 -0
- data/ext/ruby_prof/ruby_prof.h +17 -0
- data/ext/ruby_prof/vc/ruby_prof.sln +31 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +143 -0
- data/lib/ruby-prof.rb +53 -0
- data/lib/ruby-prof/assets/call_stack_printer.css.html +117 -0
- data/lib/ruby-prof/assets/call_stack_printer.js.html +385 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
- data/lib/ruby-prof/call_info.rb +57 -0
- data/lib/ruby-prof/call_info_visitor.rb +38 -0
- data/lib/ruby-prof/compatibility.rb +109 -0
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +14 -0
- data/lib/ruby-prof/method_info.rb +90 -0
- data/lib/ruby-prof/printers/abstract_printer.rb +118 -0
- data/lib/ruby-prof/printers/call_info_printer.rb +51 -0
- data/lib/ruby-prof/printers/call_stack_printer.rb +269 -0
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -0
- data/lib/ruby-prof/printers/dot_printer.rb +132 -0
- data/lib/ruby-prof/printers/flat_printer.rb +52 -0
- data/lib/ruby-prof/printers/graph_html_printer.rb +64 -0
- data/lib/ruby-prof/printers/graph_printer.rb +114 -0
- data/lib/ruby-prof/printers/multi_printer.rb +127 -0
- data/lib/ruby-prof/profile.rb +33 -0
- data/lib/ruby-prof/rack.rb +171 -0
- data/lib/ruby-prof/task.rb +147 -0
- data/lib/ruby-prof/thread.rb +35 -0
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -0
- data/ruby-prof.gemspec +58 -0
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +129 -0
- data/test/basic_test.rb +129 -0
- data/test/call_info_visitor_test.rb +31 -0
- data/test/duplicate_names_test.rb +32 -0
- data/test/dynamic_method_test.rb +53 -0
- data/test/enumerable_test.rb +21 -0
- data/test/exceptions_test.rb +24 -0
- data/test/exclude_methods_test.rb +146 -0
- data/test/exclude_threads_test.rb +53 -0
- data/test/line_number_test.rb +161 -0
- data/test/marshal_test.rb +119 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +385 -0
- data/test/measure_allocations_trace_test.rb +385 -0
- data/test/measure_memory_trace_test.rb +756 -0
- data/test/measure_process_time_test.rb +849 -0
- data/test/measure_times.rb +54 -0
- data/test/measure_wall_time_test.rb +459 -0
- data/test/multi_printer_test.rb +71 -0
- data/test/no_method_class_test.rb +15 -0
- data/test/parser_timings.rb +24 -0
- data/test/pause_resume_test.rb +166 -0
- data/test/prime.rb +56 -0
- data/test/printer_call_tree_test.rb +31 -0
- data/test/printer_flat_test.rb +68 -0
- data/test/printer_graph_html_test.rb +60 -0
- data/test/printer_graph_test.rb +41 -0
- data/test/printers_test.rb +141 -0
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/rack_test.rb +157 -0
- data/test/recursive_test.rb +210 -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 +24 -0
- data/test/thread_test.rb +144 -0
- data/test/unique_call_path_test.rb +190 -0
- data/test/yarv_test.rb +56 -0
- metadata +189 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Some classes used in measurement tests
|
|
2
|
+
module RubyProf
|
|
3
|
+
class C1
|
|
4
|
+
def C1.sleep_wait
|
|
5
|
+
sleep(0.1)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def C1.busy_wait
|
|
9
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
10
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.1
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def sleep_wait
|
|
15
|
+
sleep(0.2)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def busy_wait
|
|
19
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
20
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module M1
|
|
26
|
+
def sleep_wait
|
|
27
|
+
sleep(0.3)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def busy_wait
|
|
31
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
32
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.3
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class C2
|
|
38
|
+
include M1
|
|
39
|
+
extend M1
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class C3
|
|
43
|
+
include Singleton
|
|
44
|
+
def sleep_wait
|
|
45
|
+
sleep(0.3)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def busy_wait
|
|
49
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
50
|
+
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,459 @@
|
|
|
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
|
+
GC.start
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_mode
|
|
15
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
|
16
|
+
assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_class_methods
|
|
20
|
+
result = RubyProf.profile do
|
|
21
|
+
RubyProf::C1.sleep_wait
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
thread = result.threads.first
|
|
25
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
|
26
|
+
|
|
27
|
+
root_methods = thread.root_methods
|
|
28
|
+
assert_equal(1, root_methods.count)
|
|
29
|
+
assert_equal("MeasureWallTimeTest#test_class_methods", root_methods[0].full_name)
|
|
30
|
+
|
|
31
|
+
methods = result.threads.first.methods.sort.reverse
|
|
32
|
+
assert_equal(3, methods.length)
|
|
33
|
+
|
|
34
|
+
# Check the names
|
|
35
|
+
assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
|
|
36
|
+
assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
|
|
37
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
38
|
+
|
|
39
|
+
# Check times
|
|
40
|
+
assert_in_delta(0.1, methods[0].total_time, 0.03)
|
|
41
|
+
assert_in_delta(0, methods[0].wait_time, 0.03)
|
|
42
|
+
assert_in_delta(0, methods[0].self_time, 0.03)
|
|
43
|
+
|
|
44
|
+
assert_in_delta(0.1, methods[1].total_time, 0.03)
|
|
45
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
|
46
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
|
47
|
+
|
|
48
|
+
assert_in_delta(0.1, methods[2].total_time, 0.03)
|
|
49
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
|
50
|
+
assert_in_delta(0.1, methods[2].self_time, 0.03)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_class_methods_threaded
|
|
54
|
+
result = RubyProf.profile do
|
|
55
|
+
background_thread = Thread.new do
|
|
56
|
+
RubyProf::C1.sleep_wait
|
|
57
|
+
end
|
|
58
|
+
background_thread.join
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
assert_equal(2, result.threads.count)
|
|
62
|
+
|
|
63
|
+
thread = result.threads.first
|
|
64
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
|
65
|
+
|
|
66
|
+
root_methods = thread.root_methods
|
|
67
|
+
assert_equal(1, root_methods.count)
|
|
68
|
+
assert_equal("MeasureWallTimeTest#test_class_methods_threaded", root_methods[0].full_name)
|
|
69
|
+
|
|
70
|
+
methods = result.threads.first.methods.sort.reverse
|
|
71
|
+
assert_equal(4, methods.length)
|
|
72
|
+
|
|
73
|
+
# Check times
|
|
74
|
+
assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
|
|
75
|
+
assert_in_delta(0.1, methods[0].total_time, 0.03)
|
|
76
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
|
77
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
|
78
|
+
assert_in_delta(0.1, methods[0].children_time, 0.03)
|
|
79
|
+
|
|
80
|
+
assert_equal('Thread#join', methods[1].full_name)
|
|
81
|
+
assert_in_delta(0.1, methods[1].total_time, 0.03)
|
|
82
|
+
assert_in_delta(0.1, methods[1].wait_time, 0.03)
|
|
83
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
|
84
|
+
assert_in_delta(0.0, methods[1].children_time, 0.03)
|
|
85
|
+
|
|
86
|
+
assert_equal('<Class::Thread>#new', methods[2].full_name)
|
|
87
|
+
assert_in_delta(0.0, methods[2].total_time, 0.03)
|
|
88
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
|
89
|
+
assert_in_delta(0.0, methods[2].self_time, 0.03)
|
|
90
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
|
91
|
+
|
|
92
|
+
assert_equal('Thread#initialize', methods[3].full_name)
|
|
93
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
|
94
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
|
95
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
|
96
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
|
97
|
+
|
|
98
|
+
thread = result.threads.last
|
|
99
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
|
100
|
+
|
|
101
|
+
root_methods = thread.root_methods
|
|
102
|
+
assert_equal(1, root_methods.count)
|
|
103
|
+
assert_equal("MeasureWallTimeTest#test_class_methods_threaded", root_methods[0].full_name)
|
|
104
|
+
|
|
105
|
+
methods = result.threads.first.methods.sort.reverse
|
|
106
|
+
assert_equal(4, methods.length)
|
|
107
|
+
|
|
108
|
+
methods = result.threads.last.methods.sort.reverse
|
|
109
|
+
assert_equal(3, methods.length)
|
|
110
|
+
|
|
111
|
+
# Check times
|
|
112
|
+
assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
|
|
113
|
+
assert_in_delta(0.1, methods[0].total_time, 0.03)
|
|
114
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
|
115
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
|
116
|
+
assert_in_delta(0.1, methods[0].children_time, 0.03)
|
|
117
|
+
|
|
118
|
+
assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
|
|
119
|
+
assert_in_delta(0.1, methods[1].total_time, 0.03)
|
|
120
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.03)
|
|
121
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
|
122
|
+
assert_in_delta(0.1, methods[1].children_time, 0.03)
|
|
123
|
+
|
|
124
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
125
|
+
assert_in_delta(0.1, methods[2].total_time, 0.03)
|
|
126
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
|
127
|
+
assert_in_delta(0.1, methods[2].self_time, 0.03)
|
|
128
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def test_instance_methods
|
|
132
|
+
result = RubyProf.profile do
|
|
133
|
+
RubyProf::C1.new.sleep_wait
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
thread = result.threads.first
|
|
137
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
|
138
|
+
|
|
139
|
+
root_methods = thread.root_methods
|
|
140
|
+
assert_equal(1, root_methods.count)
|
|
141
|
+
assert_equal("MeasureWallTimeTest#test_instance_methods", root_methods[0].full_name)
|
|
142
|
+
|
|
143
|
+
methods = result.threads.first.methods.sort.reverse
|
|
144
|
+
assert_equal(5, methods.length)
|
|
145
|
+
names = methods.map(&:full_name)
|
|
146
|
+
|
|
147
|
+
# order can differ
|
|
148
|
+
assert(names.include?("BasicObject#initialize"))
|
|
149
|
+
|
|
150
|
+
# Check times
|
|
151
|
+
method = methods[0]
|
|
152
|
+
assert_equal('MeasureWallTimeTest#test_instance_methods', method.full_name)
|
|
153
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
154
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
|
155
|
+
assert_in_delta(0, method.self_time, 0.03)
|
|
156
|
+
|
|
157
|
+
method = methods[1]
|
|
158
|
+
assert_equal('RubyProf::C1#sleep_wait', method.full_name)
|
|
159
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
160
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
|
161
|
+
assert_in_delta(0, method.self_time, 0.03)
|
|
162
|
+
|
|
163
|
+
method = methods[2]
|
|
164
|
+
assert_equal('Kernel#sleep', method.full_name)
|
|
165
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
166
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
|
167
|
+
assert_in_delta(0.2, method.self_time, 0.03)
|
|
168
|
+
|
|
169
|
+
method = methods[3]
|
|
170
|
+
assert_equal('Class#new', method.full_name)
|
|
171
|
+
assert_in_delta(0, method.total_time, 0.03)
|
|
172
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
|
173
|
+
assert_in_delta(0, method.self_time, 0.03)
|
|
174
|
+
|
|
175
|
+
method = methods[4]
|
|
176
|
+
assert_equal('BasicObject#initialize', method.full_name)
|
|
177
|
+
assert_in_delta(0, method.total_time, 0.03)
|
|
178
|
+
assert_in_delta(0, method.wait_time, 0.03)
|
|
179
|
+
assert_in_delta(0, method.self_time, 0.03)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def test_instance_methods_block
|
|
183
|
+
result = RubyProf.profile do
|
|
184
|
+
1.times { RubyProf::C1.new.sleep_wait }
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
methods = result.threads.first.methods.sort.reverse
|
|
188
|
+
assert_equal(6, methods.length)
|
|
189
|
+
|
|
190
|
+
# Check times
|
|
191
|
+
method = methods[0]
|
|
192
|
+
assert_equal("MeasureWallTimeTest#test_instance_methods_block", method.full_name)
|
|
193
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
194
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
|
195
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
|
196
|
+
assert_in_delta(0.2, method.children_time, 0.03)
|
|
197
|
+
|
|
198
|
+
method = methods[1]
|
|
199
|
+
assert_equal("Integer#times", method.full_name)
|
|
200
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
201
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
|
202
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
|
203
|
+
assert_in_delta(0.2, method.children_time, 0.03)
|
|
204
|
+
|
|
205
|
+
method = methods[2]
|
|
206
|
+
assert_equal("RubyProf::C1#sleep_wait", method.full_name)
|
|
207
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
208
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
|
209
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
|
210
|
+
assert_in_delta(0.2, method.children_time, 0.03)
|
|
211
|
+
|
|
212
|
+
method = methods[3]
|
|
213
|
+
assert_equal("Kernel#sleep", method.full_name)
|
|
214
|
+
assert_in_delta(0.2, method.total_time, 0.03)
|
|
215
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
|
216
|
+
assert_in_delta(0.2, method.self_time, 0.03)
|
|
217
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
|
218
|
+
|
|
219
|
+
method = methods[4]
|
|
220
|
+
assert_equal("Class#new", method.full_name)
|
|
221
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
|
222
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
|
223
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
|
224
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
|
225
|
+
|
|
226
|
+
method = methods[5]
|
|
227
|
+
assert_equal("BasicObject#initialize", method.full_name)
|
|
228
|
+
assert_in_delta(0.0, method.total_time, 0.03)
|
|
229
|
+
assert_in_delta(0.0, method.wait_time, 0.03)
|
|
230
|
+
assert_in_delta(0.0, method.self_time, 0.03)
|
|
231
|
+
assert_in_delta(0.0, method.children_time, 0.03)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_instance_methods_threaded
|
|
235
|
+
result = RubyProf.profile do
|
|
236
|
+
background_thread = Thread.new do
|
|
237
|
+
RubyProf::C1.new.sleep_wait
|
|
238
|
+
end
|
|
239
|
+
background_thread.join
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
assert_equal(2, result.threads.count)
|
|
243
|
+
|
|
244
|
+
thread = result.threads.first
|
|
245
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
|
246
|
+
|
|
247
|
+
root_methods = thread.root_methods
|
|
248
|
+
assert_equal(1, root_methods.count)
|
|
249
|
+
assert_equal("MeasureWallTimeTest#test_instance_methods_threaded", root_methods[0].full_name)
|
|
250
|
+
|
|
251
|
+
methods = result.threads.first.methods.sort.reverse
|
|
252
|
+
assert_equal(4, methods.length)
|
|
253
|
+
|
|
254
|
+
# Check times
|
|
255
|
+
assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
|
|
256
|
+
assert_in_delta(0.2, methods[0].total_time, 0.03)
|
|
257
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
|
258
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
|
259
|
+
assert_in_delta(0.2, methods[0].children_time, 0.03)
|
|
260
|
+
|
|
261
|
+
assert_equal('Thread#join', methods[1].full_name)
|
|
262
|
+
assert_in_delta(0.2, methods[1].total_time, 0.03)
|
|
263
|
+
assert_in_delta(0.2, methods[1].wait_time, 0.03)
|
|
264
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
|
265
|
+
assert_in_delta(0.0, methods[1].children_time, 0.03)
|
|
266
|
+
|
|
267
|
+
assert_equal('<Class::Thread>#new', methods[2].full_name)
|
|
268
|
+
assert_in_delta(0.0, methods[2].total_time, 0.03)
|
|
269
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
|
270
|
+
assert_in_delta(0.0, methods[2].self_time, 0.03)
|
|
271
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
|
272
|
+
|
|
273
|
+
assert_equal('Thread#initialize', methods[3].full_name)
|
|
274
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
|
275
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
|
276
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
|
277
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
|
278
|
+
|
|
279
|
+
thread = result.threads.last
|
|
280
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
|
281
|
+
|
|
282
|
+
root_methods = thread.root_methods
|
|
283
|
+
assert_equal(1, root_methods.count)
|
|
284
|
+
assert_equal("MeasureWallTimeTest#test_instance_methods_threaded", root_methods[0].full_name)
|
|
285
|
+
|
|
286
|
+
methods = result.threads.first.methods.sort.reverse
|
|
287
|
+
assert_equal(4, methods.length)
|
|
288
|
+
|
|
289
|
+
methods = result.threads.last.methods.sort.reverse
|
|
290
|
+
assert_equal(5, methods.length)
|
|
291
|
+
|
|
292
|
+
# Check times
|
|
293
|
+
assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
|
|
294
|
+
assert_in_delta(0.2, methods[0].total_time, 0.03)
|
|
295
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
|
296
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
|
297
|
+
assert_in_delta(0.2, methods[0].children_time, 0.03)
|
|
298
|
+
|
|
299
|
+
assert_equal('RubyProf::C1#sleep_wait', methods[1].full_name)
|
|
300
|
+
assert_in_delta(0.2, methods[1].total_time, 0.03)
|
|
301
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.03)
|
|
302
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
|
303
|
+
assert_in_delta(0.2, methods[1].children_time, 0.03)
|
|
304
|
+
|
|
305
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
306
|
+
assert_in_delta(0.2, methods[2].total_time, 0.03)
|
|
307
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
|
308
|
+
assert_in_delta(0.2, methods[2].self_time, 0.03)
|
|
309
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
|
310
|
+
|
|
311
|
+
assert_equal('Class#new', methods[3].full_name)
|
|
312
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
|
313
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
|
314
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
|
315
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
|
316
|
+
|
|
317
|
+
assert_equal('BasicObject#initialize', methods[4].full_name)
|
|
318
|
+
assert_in_delta(0.0, methods[4].total_time, 0.03)
|
|
319
|
+
assert_in_delta(0.0, methods[4].wait_time, 0.03)
|
|
320
|
+
assert_in_delta(0.0, methods[4].self_time, 0.03)
|
|
321
|
+
assert_in_delta(0.0, methods[4].children_time, 0.03)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def test_module_methods
|
|
325
|
+
result = RubyProf.profile do
|
|
326
|
+
RubyProf::C2.sleep_wait
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
thread = result.threads.first
|
|
330
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
|
331
|
+
|
|
332
|
+
root_methods = thread.root_methods
|
|
333
|
+
assert_equal(1, root_methods.count)
|
|
334
|
+
assert_equal("MeasureWallTimeTest#test_module_methods", root_methods[0].full_name)
|
|
335
|
+
|
|
336
|
+
methods = result.threads.first.methods.sort.reverse
|
|
337
|
+
assert_equal(3, methods.length)
|
|
338
|
+
|
|
339
|
+
assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
|
|
340
|
+
assert_equal('RubyProf::M1#sleep_wait', methods[1].full_name)
|
|
341
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
342
|
+
|
|
343
|
+
# Check times
|
|
344
|
+
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
|
345
|
+
assert_in_delta(0, methods[0].wait_time, 0.03)
|
|
346
|
+
assert_in_delta(0, methods[0].self_time, 0.03)
|
|
347
|
+
|
|
348
|
+
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
|
349
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
|
350
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
|
351
|
+
|
|
352
|
+
assert_in_delta(0.3, methods[2].total_time, 0.1)
|
|
353
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
|
354
|
+
assert_in_delta(0.3, methods[2].self_time, 0.1)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def test_module_instance_methods
|
|
358
|
+
result = RubyProf.profile do
|
|
359
|
+
RubyProf::C2.new.sleep_wait
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
thread = result.threads.first
|
|
363
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
|
364
|
+
|
|
365
|
+
root_methods = thread.root_methods
|
|
366
|
+
assert_equal(1, root_methods.count)
|
|
367
|
+
assert_equal("MeasureWallTimeTest#test_module_instance_methods", root_methods[0].full_name)
|
|
368
|
+
|
|
369
|
+
methods = result.threads.first.methods.sort.reverse
|
|
370
|
+
assert_equal(5, methods.length)
|
|
371
|
+
names = methods.map(&:full_name)
|
|
372
|
+
assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
|
|
373
|
+
assert_equal('RubyProf::M1#sleep_wait', names[1])
|
|
374
|
+
assert_equal('Kernel#sleep', names[2])
|
|
375
|
+
assert_equal('Class#new', names[3])
|
|
376
|
+
|
|
377
|
+
# order can differ
|
|
378
|
+
assert(names.include?("BasicObject#initialize"))
|
|
379
|
+
|
|
380
|
+
# Check times
|
|
381
|
+
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
|
382
|
+
assert_in_delta(0, methods[0].wait_time, 0.1)
|
|
383
|
+
assert_in_delta(0, methods[0].self_time, 0.1)
|
|
384
|
+
|
|
385
|
+
assert_in_delta(0.3, methods[1].total_time, 0.03)
|
|
386
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
|
387
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
|
388
|
+
|
|
389
|
+
assert_in_delta(0.3, methods[2].total_time, 0.03)
|
|
390
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
|
391
|
+
assert_in_delta(0.3, methods[2].self_time, 0.03)
|
|
392
|
+
|
|
393
|
+
assert_in_delta(0, methods[3].total_time, 0.03)
|
|
394
|
+
assert_in_delta(0, methods[3].wait_time, 0.03)
|
|
395
|
+
assert_in_delta(0, methods[3].self_time, 0.03)
|
|
396
|
+
|
|
397
|
+
assert_in_delta(0, methods[4].total_time, 0.03)
|
|
398
|
+
assert_in_delta(0, methods[4].wait_time, 0.03)
|
|
399
|
+
assert_in_delta(0, methods[4].self_time, 0.03)
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def test_singleton_methods
|
|
403
|
+
result = RubyProf.profile do
|
|
404
|
+
RubyProf::C3.instance.sleep_wait
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
thread = result.threads.first
|
|
408
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
|
409
|
+
|
|
410
|
+
root_methods = thread.root_methods
|
|
411
|
+
assert_equal(1, root_methods.count)
|
|
412
|
+
assert_equal("MeasureWallTimeTest#test_singleton_methods", root_methods[0].full_name)
|
|
413
|
+
|
|
414
|
+
methods = result.threads.first.methods.sort.reverse
|
|
415
|
+
assert_equal(7, methods.length)
|
|
416
|
+
|
|
417
|
+
assert_equal('MeasureWallTimeTest#test_singleton_methods', methods[0].full_name)
|
|
418
|
+
assert_in_delta(0.3, methods[0].total_time, 0.03)
|
|
419
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.03)
|
|
420
|
+
assert_in_delta(0.0, methods[0].self_time, 0.03)
|
|
421
|
+
assert_in_delta(0.3, methods[0].children_time, 0.03)
|
|
422
|
+
|
|
423
|
+
assert_equal('RubyProf::C3#sleep_wait', methods[1].full_name)
|
|
424
|
+
assert_in_delta(0.3, methods[1].total_time, 0.03)
|
|
425
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.03)
|
|
426
|
+
assert_in_delta(0.0, methods[1].self_time, 0.03)
|
|
427
|
+
assert_in_delta(0.3, methods[1].children_time, 0.03)
|
|
428
|
+
|
|
429
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
430
|
+
assert_in_delta(0.3, methods[2].total_time, 0.03)
|
|
431
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.03)
|
|
432
|
+
assert_in_delta(0.3, methods[2].self_time, 0.03)
|
|
433
|
+
assert_in_delta(0.0, methods[2].children_time, 0.03)
|
|
434
|
+
|
|
435
|
+
assert_equal('<Class::RubyProf::C3>#instance', methods[3].full_name)
|
|
436
|
+
assert_in_delta(0.0, methods[3].total_time, 0.03)
|
|
437
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.03)
|
|
438
|
+
assert_in_delta(0.0, methods[3].self_time, 0.03)
|
|
439
|
+
assert_in_delta(0.0, methods[3].children_time, 0.03)
|
|
440
|
+
|
|
441
|
+
assert_equal('Thread::Mutex#synchronize', methods[4].full_name)
|
|
442
|
+
assert_in_delta(0.0, methods[4].total_time, 0.03)
|
|
443
|
+
assert_in_delta(0.0, methods[4].wait_time, 0.03)
|
|
444
|
+
assert_in_delta(0.0, methods[4].self_time, 0.03)
|
|
445
|
+
assert_in_delta(0.0, methods[4].children_time, 0.03)
|
|
446
|
+
|
|
447
|
+
assert_equal('Class#new', methods[5].full_name)
|
|
448
|
+
assert_in_delta(0.0, methods[5].total_time, 0.03)
|
|
449
|
+
assert_in_delta(0.0, methods[5].wait_time, 0.03)
|
|
450
|
+
assert_in_delta(0.0, methods[5].self_time, 0.03)
|
|
451
|
+
assert_in_delta(0.0, methods[5].children_time, 0.03)
|
|
452
|
+
|
|
453
|
+
assert_equal('BasicObject#initialize', methods[6].full_name)
|
|
454
|
+
assert_in_delta(0.0, methods[6].total_time, 0.03)
|
|
455
|
+
assert_in_delta(0.0, methods[6].wait_time, 0.03)
|
|
456
|
+
assert_in_delta(0.0, methods[6].self_time, 0.03)
|
|
457
|
+
assert_in_delta(0.0, methods[6].children_time, 0.03)
|
|
458
|
+
end
|
|
459
|
+
end
|