ruby-prof 0.18.0 → 1.2.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 +4 -4
- data/CHANGES +44 -1
- data/LICENSE +2 -2
- data/README.rdoc +1 -483
- data/Rakefile +3 -6
- data/bin/ruby-prof +111 -128
- data/ext/ruby_prof/extconf.rb +6 -38
- data/ext/ruby_prof/rp_aggregate_call_tree.c +41 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +259 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_tree.c +353 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +266 -0
- data/ext/ruby_prof/rp_call_trees.h +29 -0
- data/ext/ruby_prof/rp_measure_allocations.c +25 -51
- data/ext/ruby_prof/rp_measure_memory.c +21 -56
- data/ext/ruby_prof/rp_measure_process_time.c +37 -43
- data/ext/ruby_prof/rp_measure_wall_time.c +40 -21
- data/ext/ruby_prof/rp_measurement.c +221 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +279 -439
- data/ext/ruby_prof/rp_method.h +33 -45
- data/ext/ruby_prof/rp_profile.c +902 -0
- data/ext/ruby_prof/rp_profile.h +36 -0
- data/ext/ruby_prof/rp_stack.c +163 -132
- data/ext/ruby_prof/rp_stack.h +18 -28
- data/ext/ruby_prof/rp_thread.c +192 -124
- data/ext/ruby_prof/rp_thread.h +18 -8
- data/ext/ruby_prof/ruby_prof.c +36 -778
- data/ext/ruby_prof/ruby_prof.h +11 -45
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +18 -12
- data/lib/ruby-prof.rb +4 -21
- 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 +37 -107
- 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 +47 -90
- data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
- data/lib/ruby-prof/printers/call_info_printer.rb +24 -12
- data/lib/ruby-prof/printers/call_stack_printer.rb +66 -152
- data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
- data/lib/ruby-prof/printers/dot_printer.rb +5 -5
- data/lib/ruby-prof/printers/flat_printer.rb +6 -24
- data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
- data/lib/ruby-prof/printers/graph_printer.rb +11 -14
- data/lib/ruby-prof/printers/multi_printer.rb +66 -23
- data/lib/ruby-prof/profile.rb +10 -3
- data/lib/ruby-prof/thread.rb +5 -20
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +9 -2
- data/test/abstract_printer_test.rb +0 -27
- data/test/alias_test.rb +126 -0
- data/test/basic_test.rb +1 -86
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/dynamic_method_test.rb +0 -2
- data/test/exclude_methods_test.rb +17 -12
- data/test/fiber_test.rb +214 -23
- data/test/gc_test.rb +105 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +118 -40
- data/test/marshal_test.rb +115 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +361 -12
- 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 +757 -33
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +329 -149
- data/test/multi_printer_test.rb +1 -34
- data/test/pause_resume_test.rb +24 -15
- data/test/prime.rb +1 -1
- data/test/prime_script.rb +6 -0
- data/test/printer_call_stack_test.rb +28 -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 +32 -166
- data/test/printing_recursive_graph_test.rb +26 -72
- data/test/recursive_test.rb +68 -77
- data/test/stack_printer_test.rb +2 -15
- data/test/start_stop_test.rb +22 -25
- data/test/test_helper.rb +6 -261
- data/test/thread_test.rb +11 -54
- data/test/unique_call_path_test.rb +25 -107
- data/test/yarv_test.rb +1 -0
- metadata +43 -41
- data/examples/flat.txt +0 -50
- data/examples/graph.dot +0 -84
- data/examples/graph.html +0 -823
- data/examples/graph.txt +0 -139
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -760
- data/examples/multi.grind.dat +0 -114
- data/examples/multi.stack.html +0 -547
- data/examples/stack.html +0 -547
- data/ext/ruby_prof/rp_call_info.c +0 -425
- data/ext/ruby_prof/rp_call_info.h +0 -53
- data/ext/ruby_prof/rp_measure.c +0 -40
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
- data/lib/ruby-prof/aggregate_call_info.rb +0 -76
- data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
- data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
- data/lib/ruby-prof/call_info.rb +0 -115
- data/lib/ruby-prof/call_info_visitor.rb +0 -40
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
- data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
- data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
- data/test/aggregate_test.rb +0 -136
- data/test/block_test.rb +0 -74
- data/test/call_info_test.rb +0 -78
- data/test/call_info_visitor_test.rb +0 -31
- data/test/issue137_test.rb +0 -63
- data/test/measure_cpu_time_test.rb +0 -212
- 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 -33
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
@@ -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
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require_relative './measure_times'
|
5
6
|
|
6
7
|
class MeasureWallTimeTest < TestCase
|
7
8
|
def setup
|
@@ -14,242 +15,421 @@ class MeasureWallTimeTest < TestCase
|
|
14
15
|
assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
|
15
16
|
end
|
16
17
|
|
17
|
-
def test_wall_time_enabled_defined
|
18
|
-
assert(defined?(RubyProf::WALL_TIME_ENABLED))
|
19
|
-
end
|
20
|
-
|
21
18
|
def test_class_methods
|
22
19
|
result = RubyProf.profile do
|
23
|
-
RubyProf::C1.
|
20
|
+
RubyProf::C1.sleep_wait
|
24
21
|
end
|
25
22
|
|
26
23
|
thread = result.threads.first
|
27
|
-
assert_in_delta(0.1, thread.total_time, 0.
|
28
|
-
|
29
|
-
top_methods = thread.top_methods
|
30
|
-
assert_equal(1, top_methods.count)
|
31
|
-
assert_equal("MeasureWallTimeTest#test_class_methods", top_methods[0].full_name)
|
32
|
-
|
33
|
-
# Length should be 3:
|
34
|
-
# MeasureWallTimeTest#test_class_methods
|
35
|
-
# <Class::RubyProf::C1>#hello
|
36
|
-
# Kernel#sleep
|
24
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
37
25
|
|
38
26
|
methods = result.threads.first.methods.sort.reverse
|
39
27
|
assert_equal(3, methods.length)
|
40
28
|
|
41
29
|
# Check the names
|
42
30
|
assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
|
43
|
-
assert_equal('<Class::RubyProf::C1>#
|
31
|
+
assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
|
44
32
|
assert_equal('Kernel#sleep', methods[2].full_name)
|
45
33
|
|
46
34
|
# Check times
|
47
|
-
assert_in_delta(0.1, methods[0].total_time, 0.
|
48
|
-
assert_in_delta(0, methods[0].wait_time, 0.
|
49
|
-
assert_in_delta(0, methods[0].self_time, 0.
|
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)
|
50
38
|
|
51
|
-
assert_in_delta(0.1, methods[1].total_time, 0.
|
52
|
-
assert_in_delta(0, methods[1].wait_time, 0.
|
53
|
-
assert_in_delta(0, methods[1].self_time, 0.
|
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)
|
54
42
|
|
55
|
-
assert_in_delta(0.1, methods[2].total_time, 0.
|
56
|
-
assert_in_delta(0, methods[2].wait_time, 0.
|
57
|
-
assert_in_delta(0.1, methods[2].self_time, 0.
|
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)
|
58
46
|
end
|
59
47
|
|
60
|
-
def
|
48
|
+
def test_class_methods_threaded
|
61
49
|
result = RubyProf.profile do
|
62
|
-
|
50
|
+
background_thread = Thread.new do
|
51
|
+
RubyProf::C1.sleep_wait
|
52
|
+
end
|
53
|
+
background_thread.join
|
63
54
|
end
|
64
55
|
|
56
|
+
assert_equal(2, result.threads.count)
|
57
|
+
|
65
58
|
thread = result.threads.first
|
66
|
-
assert_in_delta(0.
|
59
|
+
assert_in_delta(0.1, thread.total_time, 0.03)
|
67
60
|
|
68
|
-
|
69
|
-
assert_equal(
|
70
|
-
assert_equal("MeasureWallTimeTest#test_instance_methods", top_methods[0].full_name)
|
61
|
+
methods = result.threads.first.methods.sort.reverse
|
62
|
+
assert_equal(4, methods.length)
|
71
63
|
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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)
|
79
91
|
|
80
92
|
methods = result.threads.first.methods.sort.reverse
|
81
|
-
assert_equal(
|
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)
|
82
128
|
names = methods.map(&:full_name)
|
83
|
-
assert_equal('MeasureWallTimeTest#test_instance_methods', names[0])
|
84
|
-
assert_equal('RubyProf::C1#hello', names[1])
|
85
|
-
assert_equal('Kernel#sleep', names[2])
|
86
|
-
assert_equal('Class#new', names[3])
|
87
129
|
|
88
130
|
# order can differ
|
89
|
-
assert(names.include?("#
|
90
|
-
unless RubyProf.ruby_2?
|
91
|
-
assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
|
92
|
-
end
|
131
|
+
assert(names.include?("BasicObject#initialize"))
|
93
132
|
|
94
133
|
# Check times
|
95
|
-
|
96
|
-
|
97
|
-
assert_in_delta(0,
|
98
|
-
|
99
|
-
assert_in_delta(0
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
assert_in_delta(0.2,
|
104
|
-
assert_in_delta(0,
|
105
|
-
assert_in_delta(0
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
assert_in_delta(0,
|
110
|
-
|
111
|
-
assert_in_delta(0,
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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 }
|
119
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)
|
120
215
|
end
|
121
216
|
|
122
|
-
def
|
217
|
+
def test_instance_methods_threaded
|
123
218
|
result = RubyProf.profile do
|
124
|
-
|
219
|
+
background_thread = Thread.new do
|
220
|
+
RubyProf::C1.new.sleep_wait
|
221
|
+
end
|
222
|
+
background_thread.join
|
125
223
|
end
|
126
224
|
|
225
|
+
assert_equal(2, result.threads.count)
|
226
|
+
|
127
227
|
thread = result.threads.first
|
128
|
-
assert_in_delta(0.
|
228
|
+
assert_in_delta(0.2, thread.total_time, 0.03)
|
129
229
|
|
130
|
-
|
131
|
-
assert_equal(
|
132
|
-
assert_equal("MeasureWallTimeTest#test_module_methods", top_methods[0].full_name)
|
230
|
+
methods = result.threads.first.methods.sort.reverse
|
231
|
+
assert_equal(4, methods.length)
|
133
232
|
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
|
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)
|
138
306
|
|
139
307
|
methods = result.threads.first.methods.sort.reverse
|
140
308
|
assert_equal(3, methods.length)
|
141
309
|
|
142
310
|
assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
|
143
|
-
assert_equal('RubyProf::M1#
|
311
|
+
assert_equal('RubyProf::M1#sleep_wait', methods[1].full_name)
|
144
312
|
assert_equal('Kernel#sleep', methods[2].full_name)
|
145
313
|
|
146
314
|
# Check times
|
147
315
|
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
148
|
-
assert_in_delta(0, methods[0].wait_time, 0.
|
149
|
-
assert_in_delta(0, methods[0].self_time, 0.
|
316
|
+
assert_in_delta(0, methods[0].wait_time, 0.03)
|
317
|
+
assert_in_delta(0, methods[0].self_time, 0.03)
|
150
318
|
|
151
319
|
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
152
|
-
assert_in_delta(0, methods[1].wait_time, 0.
|
153
|
-
assert_in_delta(0, methods[1].self_time, 0.
|
320
|
+
assert_in_delta(0, methods[1].wait_time, 0.03)
|
321
|
+
assert_in_delta(0, methods[1].self_time, 0.03)
|
154
322
|
|
155
323
|
assert_in_delta(0.3, methods[2].total_time, 0.1)
|
156
|
-
assert_in_delta(0, methods[2].wait_time, 0.
|
324
|
+
assert_in_delta(0, methods[2].wait_time, 0.03)
|
157
325
|
assert_in_delta(0.3, methods[2].self_time, 0.1)
|
158
326
|
end
|
159
327
|
|
160
328
|
def test_module_instance_methods
|
161
329
|
result = RubyProf.profile do
|
162
|
-
RubyProf::C2.new.
|
330
|
+
RubyProf::C2.new.sleep_wait
|
163
331
|
end
|
164
332
|
|
165
333
|
thread = result.threads.first
|
166
|
-
assert_in_delta(0.3, thread.total_time, 0.
|
167
|
-
|
168
|
-
top_methods = thread.top_methods
|
169
|
-
assert_equal(1, top_methods.count)
|
170
|
-
assert_equal("MeasureWallTimeTest#test_module_instance_methods", top_methods[0].full_name)
|
171
|
-
|
172
|
-
# Methods:
|
173
|
-
# MeasureWallTimeTest#test_module_instance_methods
|
174
|
-
# Class#new
|
175
|
-
# <Class::Object>#allocate
|
176
|
-
# Object#initialize
|
177
|
-
# M1#hello
|
178
|
-
# Kernel#sleep
|
334
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
179
335
|
|
180
336
|
methods = result.threads.first.methods.sort.reverse
|
181
|
-
assert_equal(
|
337
|
+
assert_equal(5, methods.length)
|
182
338
|
names = methods.map(&:full_name)
|
183
339
|
assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
|
184
|
-
assert_equal('RubyProf::M1#
|
340
|
+
assert_equal('RubyProf::M1#sleep_wait', names[1])
|
185
341
|
assert_equal('Kernel#sleep', names[2])
|
186
342
|
assert_equal('Class#new', names[3])
|
187
343
|
|
188
344
|
# order can differ
|
189
|
-
assert(names.include?("#
|
190
|
-
unless RubyProf.ruby_2?
|
191
|
-
assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
|
192
|
-
end
|
345
|
+
assert(names.include?("BasicObject#initialize"))
|
193
346
|
|
194
347
|
# Check times
|
195
348
|
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
196
349
|
assert_in_delta(0, methods[0].wait_time, 0.1)
|
197
350
|
assert_in_delta(0, methods[0].self_time, 0.1)
|
198
351
|
|
199
|
-
assert_in_delta(0.3, methods[1].total_time, 0.
|
200
|
-
assert_in_delta(0, methods[1].wait_time, 0.
|
201
|
-
assert_in_delta(0, methods[1].self_time, 0.
|
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)
|
202
355
|
|
203
|
-
assert_in_delta(0.3, methods[2].total_time, 0.
|
204
|
-
assert_in_delta(0, methods[2].wait_time, 0.
|
205
|
-
assert_in_delta(0.3, methods[2].self_time, 0.
|
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)
|
206
359
|
|
207
|
-
assert_in_delta(0, methods[3].total_time, 0.
|
208
|
-
assert_in_delta(0, methods[3].wait_time, 0.
|
209
|
-
assert_in_delta(0, methods[3].self_time, 0.
|
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)
|
210
363
|
|
211
|
-
assert_in_delta(0, methods[4].total_time, 0.
|
212
|
-
assert_in_delta(0, methods[4].wait_time, 0.
|
213
|
-
assert_in_delta(0, methods[4].self_time, 0.
|
214
|
-
|
215
|
-
unless RubyProf.ruby_2?
|
216
|
-
assert_in_delta(0, methods[5].total_time, 0.01)
|
217
|
-
assert_in_delta(0, methods[5].wait_time, 0.01)
|
218
|
-
assert_in_delta(0, methods[5].self_time, 0.01)
|
219
|
-
end
|
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)
|
220
367
|
end
|
221
368
|
|
222
|
-
def
|
223
|
-
c3 = RubyProf::C3.new
|
224
|
-
|
225
|
-
class << c3
|
226
|
-
def hello
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
369
|
+
def test_singleton_methods
|
230
370
|
result = RubyProf.profile do
|
231
|
-
|
371
|
+
RubyProf::C3.instance.sleep_wait
|
232
372
|
end
|
233
373
|
|
234
374
|
thread = result.threads.first
|
235
|
-
assert_in_delta(0.
|
236
|
-
|
237
|
-
top_methods = thread.top_methods
|
238
|
-
assert_equal(1, top_methods.count)
|
239
|
-
assert_equal("MeasureWallTimeTest#test_singleton", top_methods[0].full_name)
|
375
|
+
assert_in_delta(0.3, thread.total_time, 0.03)
|
240
376
|
|
241
377
|
methods = result.threads.first.methods.sort.reverse
|
242
|
-
assert_equal(
|
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)
|
243
385
|
|
244
|
-
assert_equal('
|
245
|
-
|
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)
|
246
391
|
|
247
|
-
|
248
|
-
assert_in_delta(0, methods[
|
249
|
-
assert_in_delta(0, methods[
|
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 {|method| 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 {|method| 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
|
250
413
|
|
251
|
-
|
252
|
-
|
253
|
-
assert_in_delta(0,
|
414
|
+
method = methods.detect {|method| 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 {|method| 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 {|method| 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)
|
254
434
|
end
|
255
|
-
end
|
435
|
+
end
|