ruby-prof 1.4.5-x64-mingw-ucrt → 1.5.0-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +6 -0
- data/Rakefile +1 -1
- data/ext/ruby_prof/rp_allocation.c +4 -4
- data/ext/ruby_prof/rp_call_tree.c +126 -36
- data/ext/ruby_prof/rp_call_tree.h +2 -1
- data/ext/ruby_prof/rp_call_trees.c +15 -7
- data/ext/ruby_prof/rp_measurement.c +139 -19
- data/ext/ruby_prof/rp_measurement.h +3 -0
- data/ext/ruby_prof/rp_method.c +58 -6
- data/ext/ruby_prof/rp_method.h +1 -1
- data/ext/ruby_prof/rp_profile.c +36 -3
- data/ext/ruby_prof/rp_thread.c +61 -13
- data/ext/ruby_prof/rp_thread.h +1 -1
- data/ext/ruby_prof/ruby_prof.c +0 -2
- data/ext/ruby_prof/ruby_prof.h +8 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +4 -6
- data/lib/3.1/ruby_prof.so +0 -0
- data/lib/3.2/ruby_prof.so +0 -0
- data/lib/ruby-prof/method_info.rb +8 -1
- data/lib/ruby-prof/printers/call_tree_printer.rb +0 -2
- data/lib/ruby-prof/profile.rb +34 -1
- data/lib/ruby-prof/version.rb +1 -1
- data/test/call_tree_builder.rb +126 -0
- data/test/call_tree_test.rb +197 -0
- data/test/call_trees_test.rb +4 -4
- data/test/fiber_test.rb +123 -1
- data/test/gc_test.rb +9 -7
- data/test/line_number_test.rb +36 -60
- data/test/measurement_test.rb +82 -0
- data/test/method_info_test.rb +95 -0
- data/test/profile_test.rb +85 -0
- data/test/recursive_test.rb +1 -1
- data/test/scheduler.rb +354 -0
- data/test/thread_test.rb +28 -2
- metadata +9 -6
- data/ext/ruby_prof/rp_aggregate_call_tree.c +0 -59
- data/ext/ruby_prof/rp_aggregate_call_tree.h +0 -13
@@ -0,0 +1,197 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../test_helper', __FILE__)
|
4
|
+
require_relative './call_tree_builder'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
class CallTreeTest < Minitest::Test
|
8
|
+
def test_initialize
|
9
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
10
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
11
|
+
assert_equal(method_info, call_tree.target)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_measurement
|
15
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
16
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
17
|
+
|
18
|
+
assert_equal(0, call_tree.total_time)
|
19
|
+
assert_equal(0, call_tree.self_time)
|
20
|
+
assert_equal(0, call_tree.wait_time)
|
21
|
+
assert_equal(0, call_tree.children_time)
|
22
|
+
assert_equal(0, call_tree.called)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_compare
|
26
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
27
|
+
call_tree_1 = RubyProf::CallTree.new(method_info_1)
|
28
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
29
|
+
call_tree_2 = RubyProf::CallTree.new(method_info_2)
|
30
|
+
assert_equal(0, call_tree_1 <=> call_tree_2)
|
31
|
+
|
32
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
|
33
|
+
call_tree_1 = RubyProf::CallTree.new(method_info_1)
|
34
|
+
call_tree_1.measurement.total_time = 1
|
35
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
36
|
+
call_tree_2 = RubyProf::CallTree.new(method_info_2)
|
37
|
+
assert_equal(1, call_tree_1 <=> call_tree_2)
|
38
|
+
|
39
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
|
40
|
+
call_tree_1 = RubyProf::CallTree.new(method_info_1)
|
41
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
42
|
+
call_tree_2 = RubyProf::CallTree.new(method_info_2)
|
43
|
+
call_tree_2.measurement.total_time = 1
|
44
|
+
assert_equal(-1, call_tree_1 <=> call_tree_2)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_s
|
48
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
49
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
50
|
+
assert_equal("<RubyProf::CallTree - Base64#encode64>", call_tree.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add_child
|
54
|
+
method_info_parent = RubyProf::MethodInfo.new(Base64, :encode64)
|
55
|
+
call_tree_parent = RubyProf::CallTree.new(method_info_parent)
|
56
|
+
|
57
|
+
method_info_child = RubyProf::MethodInfo.new(Array, :pack)
|
58
|
+
call_tree_child = RubyProf::CallTree.new(method_info_child)
|
59
|
+
|
60
|
+
assert_equal(0, call_tree_parent.children.size)
|
61
|
+
assert_nil(call_tree_child.parent)
|
62
|
+
|
63
|
+
result = call_tree_parent.add_child(call_tree_child)
|
64
|
+
assert_equal(1, call_tree_parent.children.size)
|
65
|
+
assert_equal(call_tree_child, call_tree_parent.children.first)
|
66
|
+
assert_equal(call_tree_child, result)
|
67
|
+
assert_equal(call_tree_parent, call_tree_child.parent)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_add_child_gc
|
71
|
+
GC.stress = true
|
72
|
+
|
73
|
+
begin
|
74
|
+
method_info_parent = RubyProf::MethodInfo.new(Base64, :encode64)
|
75
|
+
call_tree_parent = RubyProf::CallTree.new(method_info_parent)
|
76
|
+
|
77
|
+
method_info_child = RubyProf::MethodInfo.new(Array, :pack)
|
78
|
+
call_tree_child = RubyProf::CallTree.new(method_info_child)
|
79
|
+
call_tree_parent.add_child(call_tree_child)
|
80
|
+
|
81
|
+
# Free the child first
|
82
|
+
call_tree_child = nil
|
83
|
+
GC.start
|
84
|
+
|
85
|
+
# Now free the parent and make sure it doesn't free the child a second time
|
86
|
+
call_tree_parent = nil
|
87
|
+
GC.start
|
88
|
+
|
89
|
+
assert(true)
|
90
|
+
ensure
|
91
|
+
GC.stress = false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_merge
|
96
|
+
call_tree_1 = create_call_tree_1
|
97
|
+
call_tree_2 = create_call_tree_2
|
98
|
+
call_tree_1.merge!(call_tree_2)
|
99
|
+
|
100
|
+
# Root
|
101
|
+
call_tree = call_tree_1
|
102
|
+
assert_equal(:root, call_tree.target.method_name)
|
103
|
+
assert_in_delta(11.6, call_tree.total_time, 0.00001)
|
104
|
+
assert_in_delta(0, call_tree.self_time, 0.00001)
|
105
|
+
assert_in_delta(0.0, call_tree.wait_time, 0.00001)
|
106
|
+
assert_in_delta(11.6, call_tree.children_time, 0.00001)
|
107
|
+
|
108
|
+
assert_in_delta(11.6, call_tree.target.total_time, 0.00001)
|
109
|
+
assert_in_delta(0, call_tree.target.self_time, 0.00001)
|
110
|
+
assert_in_delta(0, call_tree.target.wait_time, 0.00001)
|
111
|
+
assert_in_delta(11.6, call_tree.target.children_time, 0.00001)
|
112
|
+
|
113
|
+
# a
|
114
|
+
call_tree = call_tree_1.children[0]
|
115
|
+
assert_equal(:a, call_tree.target.method_name)
|
116
|
+
|
117
|
+
assert_in_delta(4.1, call_tree.total_time, 0.00001)
|
118
|
+
assert_in_delta(0, call_tree.self_time, 0.00001)
|
119
|
+
assert_in_delta(0.0, call_tree.wait_time, 0.00001)
|
120
|
+
assert_in_delta(4.1, call_tree.children_time, 0.00001)
|
121
|
+
|
122
|
+
assert_in_delta(4.1, call_tree.target.total_time, 0.00001)
|
123
|
+
assert_in_delta(0, call_tree.target.self_time, 0.00001)
|
124
|
+
assert_in_delta(0.0, call_tree.target.wait_time, 0.00001)
|
125
|
+
assert_in_delta(4.1, call_tree.target.children_time, 0.00001)
|
126
|
+
|
127
|
+
# aa
|
128
|
+
call_tree = call_tree_1.children[0].children[0]
|
129
|
+
assert_equal(:aa, call_tree.target.method_name)
|
130
|
+
|
131
|
+
assert_in_delta(1.5, call_tree.total_time, 0.00001)
|
132
|
+
assert_in_delta(1.5, call_tree.self_time, 0.00001)
|
133
|
+
assert_in_delta(0.0, call_tree.wait_time, 0.00001)
|
134
|
+
assert_in_delta(0.0, call_tree.children_time, 0.00001)
|
135
|
+
|
136
|
+
assert_in_delta(1.5, call_tree.target.total_time, 0.00001)
|
137
|
+
assert_in_delta(1.5, call_tree.target.self_time, 0.00001)
|
138
|
+
assert_in_delta(0.0, call_tree.target.wait_time, 0.00001)
|
139
|
+
assert_in_delta(0.0, call_tree.target.children_time, 0.00001)
|
140
|
+
|
141
|
+
# ab
|
142
|
+
call_tree = call_tree_1.children[0].children[1]
|
143
|
+
assert_equal(:ab, call_tree.target.method_name)
|
144
|
+
|
145
|
+
assert_in_delta(2.6, call_tree.total_time, 0.00001)
|
146
|
+
assert_in_delta(2.6, call_tree.self_time, 0.00001)
|
147
|
+
assert_in_delta(0.0, call_tree.wait_time, 0.00001)
|
148
|
+
assert_in_delta(0.0, call_tree.children_time, 0.00001)
|
149
|
+
|
150
|
+
assert_in_delta(2.6, call_tree.target.total_time, 0.00001)
|
151
|
+
assert_in_delta(2.6, call_tree.target.self_time, 0.00001)
|
152
|
+
assert_in_delta(0.0, call_tree.target.wait_time, 0.00001)
|
153
|
+
assert_in_delta(0.0, call_tree.target.children_time, 0.00001)
|
154
|
+
|
155
|
+
# b
|
156
|
+
call_tree = call_tree_1.children[1]
|
157
|
+
assert_equal(:b, call_tree.target.method_name)
|
158
|
+
|
159
|
+
assert_in_delta(7.5, call_tree.total_time, 0.00001)
|
160
|
+
assert_in_delta(0, call_tree.self_time, 0.00001)
|
161
|
+
assert_in_delta(0.0, call_tree.wait_time, 0.00001)
|
162
|
+
assert_in_delta(7.5, call_tree.children_time, 0.00001)
|
163
|
+
|
164
|
+
assert_in_delta(7.5, call_tree.target.total_time, 0.00001)
|
165
|
+
assert_in_delta(0, call_tree.target.self_time, 0.00001)
|
166
|
+
assert_in_delta(0.0, call_tree.target.wait_time, 0.00001)
|
167
|
+
assert_in_delta(7.5, call_tree.target.children_time, 0.00001)
|
168
|
+
|
169
|
+
# bb
|
170
|
+
call_tree = call_tree_1.children[1].children[0]
|
171
|
+
assert_equal(:bb, call_tree.target.method_name)
|
172
|
+
|
173
|
+
assert_in_delta(6.6, call_tree.total_time, 0.00001)
|
174
|
+
assert_in_delta(6.6, call_tree.self_time, 0.00001)
|
175
|
+
assert_in_delta(0.0, call_tree.wait_time, 0.00001)
|
176
|
+
assert_in_delta(0.0, call_tree.children_time, 0.00001)
|
177
|
+
|
178
|
+
assert_in_delta(6.6, call_tree.target.total_time, 0.00001)
|
179
|
+
assert_in_delta(6.6, call_tree.target.self_time, 0.00001)
|
180
|
+
assert_in_delta(0.0, call_tree.target.wait_time, 0.00001)
|
181
|
+
assert_in_delta(0.0, call_tree.target.children_time, 0.00001)
|
182
|
+
|
183
|
+
# ba
|
184
|
+
call_tree = call_tree_1.children[1].children[1]
|
185
|
+
assert_equal(:ba, call_tree.target.method_name)
|
186
|
+
|
187
|
+
assert_in_delta(0.9, call_tree.total_time, 0.00001)
|
188
|
+
assert_in_delta(0.7, call_tree.self_time, 0.00001)
|
189
|
+
assert_in_delta(0.2, call_tree.wait_time, 0.00001)
|
190
|
+
assert_in_delta(0.0, call_tree.children_time, 0.00001)
|
191
|
+
|
192
|
+
assert_in_delta(0.9, call_tree.target.total_time, 0.00001)
|
193
|
+
assert_in_delta(0.7, call_tree.target.self_time, 0.00001)
|
194
|
+
assert_in_delta(0.2, call_tree.target.wait_time, 0.00001)
|
195
|
+
assert_in_delta(0.0, call_tree.target.children_time, 0.00001)
|
196
|
+
end
|
197
|
+
end
|
data/test/call_trees_test.rb
CHANGED
@@ -26,7 +26,7 @@ class CallTreesTest < TestCase
|
|
26
26
|
call_trees = method.call_trees
|
27
27
|
assert_empty(call_trees.callers)
|
28
28
|
assert_equal(1, call_trees.callees.length)
|
29
|
-
assert_kind_of(RubyProf::
|
29
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
|
30
30
|
assert_equal('CallTreesTest#some_method_1', call_trees.callees[0].target.full_name)
|
31
31
|
|
32
32
|
method = thread.methods[1]
|
@@ -34,10 +34,10 @@ class CallTreesTest < TestCase
|
|
34
34
|
|
35
35
|
call_trees = method.call_trees
|
36
36
|
assert_equal(1, call_trees.callers.length)
|
37
|
-
assert_kind_of(RubyProf::
|
37
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
|
38
38
|
assert_equal('CallTreesTest#test_call_infos', call_trees.callers[0].parent.target.full_name)
|
39
39
|
assert_equal(1, call_trees.callees.length)
|
40
|
-
assert_kind_of(RubyProf::
|
40
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
|
41
41
|
assert_equal('CallTreesTest#some_method_2', call_trees.callees[0].target.full_name)
|
42
42
|
|
43
43
|
method = thread.methods[2]
|
@@ -45,7 +45,7 @@ class CallTreesTest < TestCase
|
|
45
45
|
|
46
46
|
call_trees = method.call_trees
|
47
47
|
assert_equal(1, call_trees.callers.length)
|
48
|
-
assert_kind_of(RubyProf::
|
48
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
|
49
49
|
assert_equal('CallTreesTest#some_method_1', call_trees.callers[0].parent.target.full_name)
|
50
50
|
assert_empty(call_trees.callees)
|
51
51
|
end
|
data/test/fiber_test.rb
CHANGED
@@ -5,9 +5,25 @@ require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
require 'fiber'
|
6
6
|
require 'timeout'
|
7
7
|
require 'set'
|
8
|
+
require_relative './scheduler'
|
8
9
|
|
9
10
|
# -- Tests ----
|
10
11
|
class FiberTest < TestCase
|
12
|
+
def worker
|
13
|
+
sleep(0.5)
|
14
|
+
end
|
15
|
+
|
16
|
+
def concurrency
|
17
|
+
scheduler = Scheduler.new
|
18
|
+
Fiber.set_scheduler(scheduler)
|
19
|
+
|
20
|
+
3.times do
|
21
|
+
Fiber.schedule do |a|
|
22
|
+
worker
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Fiber.scheduler.close
|
26
|
+
end
|
11
27
|
|
12
28
|
def enumerator_with_fibers
|
13
29
|
enum = Enumerator.new do |yielder|
|
@@ -36,7 +52,7 @@ class FiberTest < TestCase
|
|
36
52
|
end
|
37
53
|
|
38
54
|
def test_fibers
|
39
|
-
result
|
55
|
+
result = RubyProf.profile { enumerator_with_fibers }
|
40
56
|
|
41
57
|
assert_equal(2, result.threads.size)
|
42
58
|
|
@@ -47,42 +63,82 @@ class FiberTest < TestCase
|
|
47
63
|
method = methods[0]
|
48
64
|
assert_equal('FiberTest#test_fibers', method.full_name)
|
49
65
|
assert_equal(1, method.called)
|
66
|
+
assert_in_delta(0, method.total_time)
|
67
|
+
assert_in_delta(0, method.self_time)
|
68
|
+
assert_in_delta(0, method.wait_time)
|
69
|
+
assert_in_delta(0, method.children_time)
|
50
70
|
|
51
71
|
method = methods[1]
|
52
72
|
assert_equal('FiberTest#enumerator_with_fibers', method.full_name)
|
53
73
|
assert_equal(1, method.called)
|
74
|
+
assert_in_delta(0, method.total_time)
|
75
|
+
assert_in_delta(0, method.self_time)
|
76
|
+
assert_in_delta(0, method.wait_time)
|
77
|
+
assert_in_delta(0, method.children_time)
|
54
78
|
|
55
79
|
method = methods[2]
|
56
80
|
assert_equal('Enumerator#next', method.full_name)
|
57
81
|
assert_equal(2, method.called)
|
82
|
+
assert_in_delta(0, method.total_time)
|
83
|
+
assert_in_delta(0, method.self_time)
|
84
|
+
assert_in_delta(0, method.wait_time)
|
85
|
+
assert_in_delta(0, method.children_time)
|
58
86
|
|
59
87
|
method = methods[3]
|
60
88
|
assert_equal('Class#new', method.full_name)
|
61
89
|
assert_equal(1, method.called)
|
90
|
+
assert_in_delta(0, method.total_time)
|
91
|
+
assert_in_delta(0, method.self_time)
|
92
|
+
assert_in_delta(0, method.wait_time)
|
93
|
+
assert_in_delta(0, method.children_time)
|
62
94
|
|
63
95
|
method = methods[4]
|
64
96
|
assert_equal('Enumerator#initialize', method.full_name)
|
65
97
|
assert_equal(1, method.called)
|
98
|
+
assert_in_delta(0, method.total_time)
|
99
|
+
assert_in_delta(0, method.self_time)
|
100
|
+
assert_in_delta(0, method.wait_time)
|
101
|
+
assert_in_delta(0, method.children_time)
|
66
102
|
|
67
103
|
thread2 = result.threads[1]
|
68
104
|
methods = thread2.methods.sort.reverse
|
69
105
|
assert_equal(4, methods.count)
|
106
|
+
assert_in_delta(0, method.total_time)
|
107
|
+
assert_in_delta(0, method.self_time)
|
108
|
+
assert_in_delta(0, method.wait_time)
|
109
|
+
assert_in_delta(0, method.children_time)
|
70
110
|
|
71
111
|
method = methods[0]
|
72
112
|
assert_equal('Enumerator#each', method.full_name)
|
73
113
|
assert_equal(1, method.called)
|
114
|
+
assert_in_delta(0, method.total_time)
|
115
|
+
assert_in_delta(0, method.self_time)
|
116
|
+
assert_in_delta(0, method.wait_time)
|
117
|
+
assert_in_delta(0, method.children_time)
|
74
118
|
|
75
119
|
method = methods[1]
|
76
120
|
assert_equal('Enumerator::Generator#each', method.full_name)
|
77
121
|
assert_equal(1, method.called)
|
122
|
+
assert_in_delta(0, method.total_time)
|
123
|
+
assert_in_delta(0, method.self_time)
|
124
|
+
assert_in_delta(0, method.wait_time)
|
125
|
+
assert_in_delta(0, method.children_time)
|
78
126
|
|
79
127
|
method = methods[2]
|
80
128
|
assert_equal('Array#each', method.full_name)
|
81
129
|
assert_equal(1, method.called)
|
130
|
+
assert_in_delta(0, method.total_time)
|
131
|
+
assert_in_delta(0, method.self_time)
|
132
|
+
assert_in_delta(0, method.wait_time)
|
133
|
+
assert_in_delta(0, method.children_time)
|
82
134
|
|
83
135
|
method = methods[3]
|
84
136
|
assert_equal('Enumerator::Yielder#yield', method.full_name)
|
85
137
|
assert_equal(2, method.called)
|
138
|
+
assert_in_delta(0, method.total_time)
|
139
|
+
assert_in_delta(0, method.self_time)
|
140
|
+
assert_in_delta(0, method.wait_time)
|
141
|
+
assert_in_delta(0, method.children_time)
|
86
142
|
end
|
87
143
|
|
88
144
|
def test_fiber_resume
|
@@ -97,33 +153,99 @@ class FiberTest < TestCase
|
|
97
153
|
method = methods[0]
|
98
154
|
assert_equal('FiberTest#test_fiber_resume', method.full_name)
|
99
155
|
assert_equal(1, method.called)
|
156
|
+
assert_in_delta(0, method.total_time)
|
157
|
+
assert_in_delta(0, method.self_time)
|
158
|
+
assert_in_delta(0, method.wait_time)
|
159
|
+
assert_in_delta(0, method.children_time)
|
100
160
|
|
101
161
|
method = methods[1]
|
102
162
|
assert_equal('FiberTest#fiber_yield_resume', method.full_name)
|
103
163
|
assert_equal(1, method.called)
|
164
|
+
assert_in_delta(0, method.total_time)
|
165
|
+
assert_in_delta(0, method.self_time)
|
166
|
+
assert_in_delta(0, method.wait_time)
|
167
|
+
assert_in_delta(0, method.children_time)
|
104
168
|
|
105
169
|
method = methods[2]
|
106
170
|
assert_equal('Fiber#resume', method.full_name)
|
107
171
|
assert_equal(2, method.called)
|
172
|
+
assert_in_delta(0, method.total_time)
|
173
|
+
assert_in_delta(0, method.self_time)
|
174
|
+
assert_in_delta(0, method.wait_time)
|
175
|
+
assert_in_delta(0, method.children_time)
|
108
176
|
|
109
177
|
method = methods[3]
|
110
178
|
assert_equal('Class#new', method.full_name)
|
111
179
|
assert_equal(1, method.called)
|
180
|
+
assert_in_delta(0, method.total_time)
|
181
|
+
assert_in_delta(0, method.self_time)
|
182
|
+
assert_in_delta(0, method.wait_time)
|
183
|
+
assert_in_delta(0, method.children_time)
|
112
184
|
|
113
185
|
method = methods[4]
|
114
186
|
assert_equal('Fiber#initialize', method.full_name)
|
115
187
|
assert_equal(1, method.called)
|
188
|
+
assert_in_delta(0, method.total_time)
|
189
|
+
assert_in_delta(0, method.self_time)
|
190
|
+
assert_in_delta(0, method.wait_time)
|
191
|
+
assert_in_delta(0, method.children_time)
|
116
192
|
|
117
193
|
thread1 = result.threads[1]
|
118
194
|
methods = thread1.methods.sort.reverse
|
119
195
|
assert_equal(2, methods.count)
|
196
|
+
assert_in_delta(0, method.total_time)
|
197
|
+
assert_in_delta(0, method.self_time)
|
198
|
+
assert_in_delta(0, method.wait_time)
|
199
|
+
assert_in_delta(0, method.children_time)
|
120
200
|
|
121
201
|
method = methods[0]
|
122
202
|
assert_equal('FiberTest#fiber_yield_resume', method.full_name)
|
123
203
|
assert_equal(1, method.called)
|
204
|
+
assert_in_delta(0, method.total_time)
|
205
|
+
assert_in_delta(0, method.self_time)
|
206
|
+
assert_in_delta(0, method.wait_time)
|
207
|
+
assert_in_delta(0, method.children_time)
|
124
208
|
|
125
209
|
method = methods[1]
|
126
210
|
assert_equal('<Class::Fiber>#yield', method.full_name)
|
127
211
|
assert_equal(2, method.called)
|
212
|
+
assert_in_delta(0, method.total_time)
|
213
|
+
assert_in_delta(0, method.self_time)
|
214
|
+
assert_in_delta(0, method.wait_time)
|
215
|
+
assert_in_delta(0, method.children_time)
|
216
|
+
end
|
217
|
+
|
218
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
|
219
|
+
def test_times_no_merge
|
220
|
+
result = RubyProf.profile { concurrency }
|
221
|
+
|
222
|
+
assert_equal(4, result.threads.size)
|
223
|
+
|
224
|
+
result.threads.each do |thread|
|
225
|
+
assert_in_delta(0.5, thread.call_tree.target.total_time, 0.2)
|
226
|
+
assert_in_delta(0.0, thread.call_tree.target.self_time)
|
227
|
+
assert_in_delta(0.0, thread.call_tree.target.wait_time)
|
228
|
+
assert_in_delta(0.5, thread.call_tree.target.children_time, 0.2)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_times_merge
|
233
|
+
result = RubyProf.profile { concurrency }
|
234
|
+
result.merge!
|
235
|
+
|
236
|
+
assert_equal(2, result.threads.size)
|
237
|
+
|
238
|
+
thread = result.threads[0]
|
239
|
+
assert_in_delta(0.5, thread.call_tree.target.total_time, 0.2)
|
240
|
+
assert_in_delta(0.0, thread.call_tree.target.self_time)
|
241
|
+
assert_in_delta(0.0, thread.call_tree.target.wait_time)
|
242
|
+
assert_in_delta(0.5, thread.call_tree.target.children_time, 0.2)
|
243
|
+
|
244
|
+
thread = result.threads[1]
|
245
|
+
assert_in_delta(1.5, thread.call_tree.target.total_time, 0.2)
|
246
|
+
assert_in_delta(0.0, thread.call_tree.target.self_time)
|
247
|
+
assert_in_delta(0.0, thread.call_tree.target.wait_time)
|
248
|
+
assert_in_delta(1.5, thread.call_tree.target.children_time, 0.2)
|
249
|
+
end
|
128
250
|
end
|
129
251
|
end
|
data/test/gc_test.rb
CHANGED
@@ -67,16 +67,18 @@ class GcTest < TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_hold_onto_measurements
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
# Run a profile
|
71
|
+
profile = run_profile
|
72
|
+
|
73
|
+
# Get measurement objects
|
74
|
+
measurements = profile.threads.map(&:methods).flatten.map(&:measurement)
|
75
|
+
|
76
|
+
# Free the profiles which frees the measurements
|
77
|
+
profile = nil
|
76
78
|
|
77
79
|
GC.start
|
78
80
|
|
79
|
-
measurements.
|
81
|
+
measurements.each_with_index do |measurement|
|
80
82
|
error = assert_raises(RuntimeError) do
|
81
83
|
measurement.total_time
|
82
84
|
end
|
data/test/line_number_test.rb
CHANGED
@@ -19,12 +19,10 @@ class LineNumbers
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def method_3
|
22
|
-
sleep(0.3)
|
23
22
|
method_4
|
24
23
|
end
|
25
24
|
|
26
25
|
def method_4
|
27
|
-
sleep(1.2)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -37,20 +35,24 @@ class LineNumbersTest < TestCase
|
|
37
35
|
numbers.method_1
|
38
36
|
end
|
39
37
|
|
40
|
-
methods
|
41
|
-
|
38
|
+
# Sort methods by name to have stable results
|
39
|
+
methods = result.threads.first.methods.sort_by(&:full_name)
|
40
|
+
assert_equal(6, methods.length)
|
42
41
|
|
43
42
|
# Method 0
|
44
43
|
method = methods[0]
|
45
|
-
assert_equal('
|
46
|
-
assert_equal(
|
44
|
+
assert_equal('Integer#times', method.full_name)
|
45
|
+
assert_equal(0, method.line)
|
47
46
|
|
48
|
-
assert_equal(
|
47
|
+
assert_equal(1, method.call_trees.callers.count)
|
48
|
+
call_tree = method.call_trees.callers[0]
|
49
|
+
assert_equal('LineNumbers#method_2', call_tree.parent.target.full_name)
|
50
|
+
assert_equal(15, call_tree.line)
|
49
51
|
|
50
52
|
assert_equal(1, method.call_trees.callees.count)
|
51
53
|
call_tree = method.call_trees.callees[0]
|
52
|
-
assert_equal('LineNumbers#
|
53
|
-
assert_equal(
|
54
|
+
assert_equal('LineNumbers#method_3', call_tree.target.full_name)
|
55
|
+
assert_equal(17, call_tree.line)
|
54
56
|
|
55
57
|
# Method 1
|
56
58
|
method = methods[1]
|
@@ -60,7 +62,7 @@ class LineNumbersTest < TestCase
|
|
60
62
|
assert_equal(1, method.call_trees.callers.count)
|
61
63
|
call_tree = method.call_trees.callers[0]
|
62
64
|
assert_equal('LineNumbersTest#test_function_line_no', call_tree.parent.target.full_name)
|
63
|
-
assert_equal(
|
65
|
+
assert_equal(35, call_tree.line)
|
64
66
|
|
65
67
|
assert_equal(2, method.call_trees.callees.count)
|
66
68
|
call_tree = method.call_trees.callees[0]
|
@@ -73,6 +75,21 @@ class LineNumbersTest < TestCase
|
|
73
75
|
|
74
76
|
# Method 2
|
75
77
|
method = methods[2]
|
78
|
+
assert_equal('LineNumbers#method_2', method.full_name)
|
79
|
+
assert_equal(13, method.line)
|
80
|
+
|
81
|
+
assert_equal(1, method.call_trees.callers.count)
|
82
|
+
call_tree = method.call_trees.callers[0]
|
83
|
+
assert_equal('LineNumbers#method_1', call_tree.parent.target.full_name)
|
84
|
+
assert_equal(8, call_tree.line)
|
85
|
+
|
86
|
+
assert_equal(1, method.call_trees.callees.count)
|
87
|
+
call_tree = method.call_trees.callees[0]
|
88
|
+
assert_equal('Integer#times', call_tree.target.full_name)
|
89
|
+
assert_equal(15, call_tree.line)
|
90
|
+
|
91
|
+
# Method 3
|
92
|
+
method = methods[3]
|
76
93
|
assert_equal('LineNumbers#method_3', method.full_name)
|
77
94
|
assert_equal(21, method.line)
|
78
95
|
|
@@ -85,74 +102,33 @@ class LineNumbersTest < TestCase
|
|
85
102
|
assert_equal('LineNumbers#method_1', call_tree.parent.target.full_name)
|
86
103
|
assert_equal(10, call_tree.line)
|
87
104
|
|
88
|
-
assert_equal(
|
105
|
+
assert_equal(1, method.call_trees.callees.count)
|
89
106
|
call_tree = method.call_trees.callees[0]
|
90
|
-
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
91
|
-
assert_equal(22, call_tree.line)
|
92
|
-
|
93
|
-
call_tree = method.call_trees.callees[1]
|
94
107
|
assert_equal('LineNumbers#method_4', call_tree.target.full_name)
|
95
|
-
assert_equal(23, call_tree.line)
|
96
|
-
|
97
|
-
# Method 3
|
98
|
-
method = methods[3]
|
99
|
-
assert_equal('Kernel#sleep', method.full_name)
|
100
|
-
assert_equal(0, method.line)
|
101
|
-
|
102
|
-
assert_equal(2, method.call_trees.callers.count)
|
103
|
-
call_tree = method.call_trees.callers[0]
|
104
|
-
assert_equal('LineNumbers#method_3', call_tree.parent.target.full_name)
|
105
108
|
assert_equal(22, call_tree.line)
|
106
109
|
|
107
|
-
call_tree = method.call_trees.callers[1]
|
108
|
-
assert_equal('LineNumbers#method_4', call_tree.parent.target.full_name)
|
109
|
-
assert_equal(27, call_tree.line)
|
110
|
-
|
111
|
-
assert_equal(0, method.call_trees.callees.count)
|
112
|
-
|
113
110
|
# Method 4
|
114
111
|
method = methods[4]
|
115
112
|
assert_equal('LineNumbers#method_4', method.full_name)
|
116
|
-
assert_equal(
|
113
|
+
assert_equal(25, method.line)
|
117
114
|
|
118
115
|
assert_equal(1, method.call_trees.callers.count)
|
119
116
|
call_tree = method.call_trees.callers[0]
|
120
117
|
assert_equal('LineNumbers#method_3', call_tree.parent.target.full_name)
|
121
|
-
assert_equal(
|
118
|
+
assert_equal(22, call_tree.line)
|
122
119
|
|
123
|
-
assert_equal(
|
124
|
-
call_tree = method.call_trees.callees[0]
|
125
|
-
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
126
|
-
assert_equal(27, call_tree.line)
|
120
|
+
assert_equal(0, method.call_trees.callees.count)
|
127
121
|
|
128
122
|
# Method 5
|
129
123
|
method = methods[5]
|
130
|
-
assert_equal('
|
131
|
-
assert_equal(
|
132
|
-
|
133
|
-
assert_equal(1, method.call_trees.callers.count)
|
134
|
-
call_tree = method.call_trees.callers[0]
|
135
|
-
assert_equal('LineNumbers#method_1', call_tree.parent.target.full_name)
|
136
|
-
assert_equal(8, call_tree.line)
|
137
|
-
|
138
|
-
assert_equal(1, method.call_trees.callees.count)
|
139
|
-
call_tree = method.call_trees.callees[0]
|
140
|
-
assert_equal('Integer#times', call_tree.target.full_name)
|
141
|
-
assert_equal(15, call_tree.line)
|
142
|
-
|
143
|
-
# Method 6
|
144
|
-
method = methods[6]
|
145
|
-
assert_equal('Integer#times', method.full_name)
|
146
|
-
assert_equal(0, method.line)
|
124
|
+
assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
|
125
|
+
assert_equal(35, method.line)
|
147
126
|
|
148
|
-
assert_equal(
|
149
|
-
call_tree = method.call_trees.callers[0]
|
150
|
-
assert_equal('LineNumbers#method_2', call_tree.parent.target.full_name)
|
151
|
-
assert_equal(15, call_tree.line)
|
127
|
+
assert_equal(0, method.call_trees.callers.count)
|
152
128
|
|
153
129
|
assert_equal(1, method.call_trees.callees.count)
|
154
130
|
call_tree = method.call_trees.callees[0]
|
155
|
-
assert_equal('LineNumbers#
|
156
|
-
assert_equal(
|
131
|
+
assert_equal('LineNumbers#method_1', call_tree.target.full_name)
|
132
|
+
assert_equal(35, call_tree.line)
|
157
133
|
end
|
158
134
|
end
|