ruby-prof 0.18.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,32 @@
|
|
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 CallTreeVisitorTest < 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_visit
|
14
|
+
result = RubyProf.profile do
|
15
|
+
RubyProf::C1.sleep_wait
|
16
|
+
end
|
17
|
+
|
18
|
+
visitor = RubyProf::CallTreeVisitor.new(result.threads.first.call_tree)
|
19
|
+
|
20
|
+
method_names = Array.new
|
21
|
+
|
22
|
+
visitor.visit do |call_tree, event|
|
23
|
+
method_names << call_tree.target.full_name if event == :enter
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal(3, method_names.length)
|
27
|
+
assert_equal("CallTreeVisitorTest#test_visit", method_names[0])
|
28
|
+
assert_equal("<Class::RubyProf::C1>#sleep_wait", method_names[1])
|
29
|
+
assert_equal("Kernel#sleep", method_names[2])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
|
6
|
+
# -- Tests ----
|
7
|
+
class CallTreesTest < TestCase
|
8
|
+
def some_method_1
|
9
|
+
some_method_2
|
10
|
+
end
|
11
|
+
|
12
|
+
def some_method_2
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_call_infos
|
16
|
+
result = RubyProf.profile do
|
17
|
+
some_method_1
|
18
|
+
end
|
19
|
+
|
20
|
+
thread = result.threads.first
|
21
|
+
assert_equal(3, thread.methods.length)
|
22
|
+
|
23
|
+
method = thread.methods[0]
|
24
|
+
assert_equal('CallTreesTest#test_call_infos', method.full_name)
|
25
|
+
|
26
|
+
call_trees = method.call_trees
|
27
|
+
assert_empty(call_trees.callers)
|
28
|
+
assert_equal(1, call_trees.callees.length)
|
29
|
+
assert_kind_of(RubyProf::AggregateCallTree, call_trees.callees[0])
|
30
|
+
assert_equal('CallTreesTest#some_method_1', call_trees.callees[0].target.full_name)
|
31
|
+
|
32
|
+
method = thread.methods[1]
|
33
|
+
assert_equal('CallTreesTest#some_method_1', method.full_name)
|
34
|
+
|
35
|
+
call_trees = method.call_trees
|
36
|
+
assert_equal(1, call_trees.callers.length)
|
37
|
+
assert_kind_of(RubyProf::AggregateCallTree, call_trees.callers[0])
|
38
|
+
assert_equal('CallTreesTest#test_call_infos', call_trees.callers[0].parent.target.full_name)
|
39
|
+
assert_equal(1, call_trees.callees.length)
|
40
|
+
assert_kind_of(RubyProf::AggregateCallTree, call_trees.callees[0])
|
41
|
+
assert_equal('CallTreesTest#some_method_2', call_trees.callees[0].target.full_name)
|
42
|
+
|
43
|
+
method = thread.methods[2]
|
44
|
+
assert_equal('CallTreesTest#some_method_2', method.full_name)
|
45
|
+
|
46
|
+
call_trees = method.call_trees
|
47
|
+
assert_equal(1, call_trees.callers.length)
|
48
|
+
assert_kind_of(RubyProf::AggregateCallTree, call_trees.callers[0])
|
49
|
+
assert_equal('CallTreesTest#some_method_1', call_trees.callers[0].parent.target.full_name)
|
50
|
+
assert_empty(call_trees.callees)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_gc
|
54
|
+
result = RubyProf.profile do
|
55
|
+
some_method_1
|
56
|
+
end
|
57
|
+
|
58
|
+
method = result.threads.first.methods[1]
|
59
|
+
|
60
|
+
100.times do |i|
|
61
|
+
method.call_trees.callers
|
62
|
+
GC.start
|
63
|
+
end
|
64
|
+
assert(true)
|
65
|
+
end
|
66
|
+
end
|
data/test/dynamic_method_test.rb
CHANGED
@@ -43,13 +43,12 @@ class ExcludeMethodsTest < TestCase
|
|
43
43
|
obj = ExcludeMethodsClass.new
|
44
44
|
prf = RubyProf::Profile.new
|
45
45
|
|
46
|
-
result = prf.profile {
|
46
|
+
result = prf.profile {obj.a}
|
47
47
|
methods = result.threads.first.methods.sort.reverse
|
48
|
-
|
49
48
|
assert_equal(10, methods.count)
|
50
49
|
assert_equal('ExcludeMethodsTest#test_methods_can_be_profiled', methods[0].full_name)
|
51
|
-
assert_equal('
|
52
|
-
assert_equal('
|
50
|
+
assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
|
51
|
+
assert_equal('Integer#times', methods[2].full_name)
|
53
52
|
assert_equal('ExcludeMethodsClass#b', methods[3].full_name)
|
54
53
|
assert_equal('<Class::ExcludeMethodsClass>#e', methods[4].full_name)
|
55
54
|
assert_equal('<Class::ExcludeMethodsClass>#f', methods[5].full_name)
|
@@ -65,7 +64,7 @@ class ExcludeMethodsTest < TestCase
|
|
65
64
|
|
66
65
|
prf.exclude_methods!(Integer, :times)
|
67
66
|
|
68
|
-
result = prf.profile {
|
67
|
+
result = prf.profile {obj.a}
|
69
68
|
methods = result.threads.first.methods.sort.reverse
|
70
69
|
|
71
70
|
assert_equal(9, methods.count)
|
@@ -88,7 +87,7 @@ class ExcludeMethodsTest < TestCase
|
|
88
87
|
prf.exclude_methods!(ExcludeMethodsClass.singleton_class, :f)
|
89
88
|
prf.exclude_methods!(ExcludeMethodsModule.singleton_class, :d)
|
90
89
|
|
91
|
-
result = prf.profile {
|
90
|
+
result = prf.profile {obj.a}
|
92
91
|
methods = result.threads.first.methods.sort.reverse
|
93
92
|
|
94
93
|
assert_equal(7, methods.count)
|
@@ -107,13 +106,19 @@ class ExcludeMethodsTest < TestCase
|
|
107
106
|
|
108
107
|
prf.exclude_common_methods!
|
109
108
|
|
110
|
-
result = prf.profile {
|
109
|
+
result = prf.profile {obj.a}
|
111
110
|
methods = result.threads.first.methods.sort.reverse
|
112
111
|
|
113
112
|
assert_equal(9, methods.count)
|
114
113
|
assert_equal('ExcludeMethodsTest#test_exclude_common_methods1', methods[0].full_name)
|
115
114
|
assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
|
116
115
|
assert_equal('ExcludeMethodsClass#b', methods[2].full_name)
|
116
|
+
assert_equal('<Class::ExcludeMethodsClass>#e', methods[3].full_name)
|
117
|
+
assert_equal('<Class::ExcludeMethodsClass>#f', methods[4].full_name)
|
118
|
+
assert_equal('Kernel#sleep', methods[5].full_name)
|
119
|
+
assert_equal('ExcludeMethodsModule#c', methods[6].full_name)
|
120
|
+
assert_equal('<Module::ExcludeMethodsModule>#d', methods[7].full_name)
|
121
|
+
assert_equal('Kernel#class', methods[8].full_name)
|
117
122
|
end
|
118
123
|
|
119
124
|
def test_exclude_common_methods2
|
@@ -130,14 +135,14 @@ class ExcludeMethodsTest < TestCase
|
|
130
135
|
|
131
136
|
private
|
132
137
|
|
133
|
-
def
|
138
|
+
def assert_method_has_been_excluded(result, excluded_method)
|
134
139
|
result.threads.each do |thread|
|
135
140
|
thread.methods.each do |method|
|
136
|
-
method.
|
137
|
-
assert(ci.target !=
|
138
|
-
assert(ci.parent.target !=
|
141
|
+
method.call_trees.each do |ci|
|
142
|
+
assert(ci.target != excluded_method, "broken self")
|
143
|
+
assert(ci.parent.target != excluded_method, "broken parent") if ci.parent
|
139
144
|
ci.children.each do |callee|
|
140
|
-
assert(callee.target !=
|
145
|
+
assert(callee.target != excluded_method, "broken kid")
|
141
146
|
end
|
142
147
|
end
|
143
148
|
end
|
data/test/fiber_test.rb
CHANGED
@@ -2,25 +2,21 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require 'fiber'
|
5
6
|
require 'timeout'
|
6
7
|
require 'set'
|
7
|
-
begin
|
8
|
-
require 'fiber'
|
9
|
-
rescue LoadError
|
10
|
-
end
|
11
8
|
|
12
9
|
# -- Tests ----
|
13
10
|
class FiberTest < TestCase
|
14
|
-
|
15
11
|
def fiber_test
|
16
12
|
@fiber_ids << Fiber.current.object_id
|
17
13
|
enum = Enumerator.new do |yielder|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
14
|
+
[1,2].each do |x|
|
15
|
+
@fiber_ids << Fiber.current.object_id
|
16
|
+
sleep 0.1
|
17
|
+
yielder.yield x
|
23
18
|
end
|
19
|
+
end
|
24
20
|
while true
|
25
21
|
begin
|
26
22
|
enum.next
|
@@ -41,6 +37,7 @@ class FiberTest < TestCase
|
|
41
37
|
|
42
38
|
def test_fibers
|
43
39
|
result = RubyProf.profile { fiber_test }
|
40
|
+
|
44
41
|
profiled_fiber_ids = result.threads.map(&:fiber_id)
|
45
42
|
assert_equal(2, result.threads.length)
|
46
43
|
assert_equal([@thread_id], result.threads.map(&:id).uniq)
|
@@ -49,31 +46,225 @@ class FiberTest < TestCase
|
|
49
46
|
assert profiled_fiber_ids.include?(@root_fiber)
|
50
47
|
assert(root_fiber_profile = result.threads.detect{|t| t.fiber_id == @root_fiber})
|
51
48
|
assert(enum_fiber_profile = result.threads.detect{|t| t.fiber_id != @root_fiber})
|
49
|
+
assert_in_delta(0.33, root_fiber_profile.total_time, 0.05)
|
50
|
+
assert_in_delta(0.33, enum_fiber_profile.total_time, 0.05)
|
52
51
|
|
53
|
-
|
54
|
-
|
52
|
+
methods = result.threads[0].methods.sort.reverse
|
53
|
+
assert_equal(12, methods.count)
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
method = methods[0]
|
56
|
+
assert_equal('FiberTest#test_fibers', method.full_name)
|
57
|
+
assert_equal(1, method.called)
|
58
|
+
assert_in_delta(0.33, method.total_time, 0.05)
|
59
|
+
assert_in_delta(0, method.self_time, 0.05)
|
60
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
61
|
+
assert_in_delta(0.33, method.children_time, 0.05)
|
58
62
|
|
59
|
-
|
60
|
-
|
63
|
+
method = methods[1]
|
64
|
+
assert_equal('FiberTest#fiber_test', method.full_name)
|
65
|
+
assert_equal(1, method.called)
|
66
|
+
assert_in_delta(0.33, method.total_time, 0.05)
|
67
|
+
assert_in_delta(0, method.self_time, 0.05)
|
68
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
69
|
+
assert_in_delta(0.33, method.children_time, 0.05)
|
70
|
+
|
71
|
+
method = methods[2]
|
72
|
+
assert_equal('Enumerator#next', method.full_name)
|
73
|
+
assert_equal(3, method.called)
|
74
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
75
|
+
assert_in_delta(0, method.self_time, 0.05)
|
76
|
+
assert_in_delta(0.22, method.wait_time, 0.05)
|
77
|
+
assert_in_delta(0, method.children_time, 0.05)
|
78
|
+
|
79
|
+
method = methods[3]
|
80
|
+
assert_equal('Kernel#sleep', method.full_name)
|
81
|
+
assert_equal(1, method.called)
|
82
|
+
assert_in_delta(0.11, method.total_time, 0.05)
|
83
|
+
assert_in_delta(0.11, method.self_time, 0.05)
|
84
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
85
|
+
assert_in_delta(0, method.children_time, 0.05)
|
86
|
+
|
87
|
+
# Since these methods have such short times their order is a bit indeterminate
|
88
|
+
method = methods.detect {|method| method.full_name == 'Class#new'}
|
89
|
+
assert_equal('Class#new', method.full_name)
|
90
|
+
assert_equal(1, method.called)
|
91
|
+
assert_in_delta(0, method.total_time, 0.05)
|
92
|
+
assert_in_delta(0, method.self_time, 0.05)
|
93
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
94
|
+
assert_in_delta(0, method.children_time, 0.05)
|
95
|
+
|
96
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
97
|
+
method = methods.detect {|method| method.full_name == 'Set#<<'}
|
98
|
+
assert_equal('Set#<<', method.full_name)
|
99
|
+
assert_equal(1, method.called)
|
100
|
+
assert_in_delta(0, method.total_time, 0.05)
|
101
|
+
assert_in_delta(0, method.self_time, 0.05)
|
102
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
103
|
+
assert_in_delta(0, method.children_time, 0.05)
|
104
|
+
end
|
105
|
+
|
106
|
+
method = methods.detect {|method| method.full_name == 'Module#==='}
|
107
|
+
assert_equal('Module#===', method.full_name)
|
108
|
+
assert_equal(1, method.called)
|
109
|
+
assert_in_delta(0, method.total_time, 0.05)
|
110
|
+
assert_in_delta(0, method.self_time, 0.05)
|
111
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
112
|
+
assert_in_delta(0, method.children_time, 0.05)
|
113
|
+
|
114
|
+
method = methods.detect {|method| method.full_name == 'Kernel#object_id'}
|
115
|
+
assert_equal('Kernel#object_id', method.full_name)
|
116
|
+
assert_equal(1, method.called)
|
117
|
+
assert_in_delta(0, method.total_time, 0.05)
|
118
|
+
assert_in_delta(0, method.self_time, 0.05)
|
119
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
120
|
+
assert_in_delta(0, method.children_time, 0.05)
|
121
|
+
|
122
|
+
method = methods.detect {|method| method.full_name == '<Class::Fiber>#current'}
|
123
|
+
assert_equal('<Class::Fiber>#current', method.full_name)
|
124
|
+
assert_equal(1, method.called)
|
125
|
+
assert_in_delta(0, method.total_time, 0.05)
|
126
|
+
assert_in_delta(0, method.self_time, 0.05)
|
127
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
128
|
+
assert_in_delta(0, method.children_time, 0.05)
|
129
|
+
|
130
|
+
method = methods.detect {|method| method.full_name == 'Exception#exception'}
|
131
|
+
assert_equal('Exception#exception', method.full_name)
|
132
|
+
assert_equal(1, method.called)
|
133
|
+
assert_in_delta(0, method.total_time, 0.05)
|
134
|
+
assert_in_delta(0, method.self_time, 0.05)
|
135
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
136
|
+
assert_in_delta(0, method.children_time, 0.05)
|
137
|
+
|
138
|
+
method = methods.detect {|method| method.full_name == 'Exception#backtrace'}
|
139
|
+
assert_equal('Exception#backtrace', method.full_name)
|
140
|
+
assert_equal(1, method.called)
|
141
|
+
assert_in_delta(0, method.total_time, 0.05)
|
142
|
+
assert_in_delta(0, method.self_time, 0.05)
|
143
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
144
|
+
assert_in_delta(0, method.children_time, 0.05)
|
145
|
+
|
146
|
+
method = methods.detect {|method| method.full_name == 'Enumerator#initialize'}
|
147
|
+
assert_equal('Enumerator#initialize', method.full_name)
|
148
|
+
assert_equal(1, method.called)
|
149
|
+
assert_in_delta(0, method.total_time, 0.05)
|
150
|
+
assert_in_delta(0, method.self_time, 0.05)
|
151
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
152
|
+
assert_in_delta(0, method.children_time, 0.05)
|
153
|
+
|
154
|
+
methods = result.threads[1].methods.sort.reverse
|
155
|
+
|
156
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
|
157
|
+
assert_equal(10, methods.count)
|
158
|
+
else
|
159
|
+
assert_equal(11, methods.count)
|
160
|
+
end
|
161
|
+
|
162
|
+
method = methods[0]
|
163
|
+
assert_equal('RubyProf::Profile#_inserted_parent_', method.full_name)
|
164
|
+
assert_equal(1, method.called)
|
165
|
+
assert_in_delta(0.33, method.total_time, 0.05)
|
166
|
+
assert_in_delta(0, method.self_time, 0.05)
|
167
|
+
assert_in_delta(0.11, method.wait_time, 0.05)
|
168
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
169
|
+
|
170
|
+
method = methods[1]
|
171
|
+
assert_equal('Enumerator#each', method.full_name)
|
172
|
+
assert_equal(1, method.called)
|
173
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
174
|
+
assert_in_delta(0, method.self_time, 0.05)
|
175
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
176
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
177
|
+
|
178
|
+
method = methods[2]
|
179
|
+
assert_equal('Enumerator::Generator#each', method.full_name)
|
180
|
+
assert_equal(1, method.called)
|
181
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
182
|
+
assert_in_delta(0, method.self_time, 0.05)
|
183
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
184
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
185
|
+
|
186
|
+
method = methods[3]
|
187
|
+
assert_equal('Array#each', method.full_name)
|
188
|
+
assert_equal(1, method.called)
|
189
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
190
|
+
assert_in_delta(0, method.self_time, 0.05)
|
191
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
192
|
+
assert_in_delta(0.22, method.children_time, 0.05)
|
193
|
+
|
194
|
+
method = methods[4]
|
195
|
+
assert_equal('Kernel#sleep', method.full_name)
|
196
|
+
assert_equal(2, method.called)
|
197
|
+
assert_in_delta(0.22, method.total_time, 0.05)
|
198
|
+
assert_in_delta(0.22, method.self_time, 0.05)
|
199
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
200
|
+
assert_in_delta(0, method.children_time, 0.05)
|
201
|
+
|
202
|
+
# Since these methods have such short times their order is a bit indeterminate
|
203
|
+
method = methods.detect {|method| method.full_name == 'Exception#initialize'}
|
204
|
+
assert_equal('Exception#initialize', method.full_name)
|
205
|
+
assert_equal(1, method.called)
|
206
|
+
assert_in_delta(0, method.total_time, 0.05)
|
207
|
+
assert_in_delta(0, method.self_time, 0.05)
|
208
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
209
|
+
assert_in_delta(0, method.children_time, 0.05)
|
210
|
+
|
211
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
212
|
+
method = methods.detect {|method| method.full_name == 'Set#<<'}
|
213
|
+
assert_equal('Set#<<', method.full_name)
|
214
|
+
assert_equal(2, method.called)
|
215
|
+
assert_in_delta(0, method.total_time, 0.05)
|
216
|
+
assert_in_delta(0, method.self_time, 0.05)
|
217
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
218
|
+
assert_in_delta(0, method.children_time, 0.05)
|
219
|
+
end
|
220
|
+
|
221
|
+
method = methods.detect {|method| method.full_name == 'Kernel#object_id'}
|
222
|
+
assert_equal('Kernel#object_id', method.full_name)
|
223
|
+
assert_equal(2, method.called)
|
224
|
+
assert_in_delta(0, method.total_time, 0.05)
|
225
|
+
assert_in_delta(0, method.self_time, 0.05)
|
226
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
227
|
+
assert_in_delta(0, method.children_time, 0.05)
|
228
|
+
|
229
|
+
method = methods.detect {|method| method.full_name == 'Enumerator::Yielder#yield'}
|
230
|
+
assert_equal('Enumerator::Yielder#yield', method.full_name)
|
231
|
+
assert_equal(2, method.called)
|
232
|
+
assert_in_delta(0, method.total_time, 0.05)
|
233
|
+
assert_in_delta(0, method.self_time, 0.05)
|
234
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
235
|
+
assert_in_delta(0, method.children_time, 0.05)
|
236
|
+
|
237
|
+
method = methods.detect {|method| method.full_name == '<Class::Fiber>#current'}
|
238
|
+
assert_equal('<Class::Fiber>#current', method.full_name)
|
239
|
+
assert_equal(2, method.called)
|
240
|
+
assert_in_delta(0, method.total_time, 0.05)
|
241
|
+
assert_in_delta(0, method.self_time, 0.05)
|
242
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
243
|
+
assert_in_delta(0, method.children_time, 0.05)
|
244
|
+
|
245
|
+
#if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
246
|
+
# method = methods.detect {|method| method.full_name == 'Numeric#eql?'}
|
247
|
+
# assert_equal('Numeric#eql?', method.full_name)
|
248
|
+
# assert_equal(1, method.called)
|
249
|
+
# assert_in_delta(0, method.total_time, 0.05)
|
250
|
+
# assert_in_delta(0, method.self_time, 0.05)
|
251
|
+
# assert_in_delta(0, method.wait_time, 0.05)
|
252
|
+
# assert_in_delta(0, method.children_time, 0.05)
|
253
|
+
#end
|
61
254
|
end
|
62
255
|
|
63
256
|
def test_merged_fibers
|
64
257
|
result = RubyProf.profile(merge_fibers: true) { fiber_test }
|
65
258
|
assert_equal(1, result.threads.length)
|
66
259
|
|
67
|
-
|
68
|
-
assert_equal
|
260
|
+
thread = result.threads.first
|
261
|
+
assert_equal(thread.id, thread.fiber_id)
|
262
|
+
assert_in_delta(0.3, thread.total_time, 0.05)
|
69
263
|
|
70
|
-
|
71
|
-
|
72
|
-
assert(method_next = profile.methods.detect{|m| m.full_name == "Enumerator#next"})
|
73
|
-
assert(method_each = profile.methods.detect{|m| m.full_name == "Enumerator#each"})
|
264
|
+
assert(method_next = thread.methods.detect{|m| m.full_name == "Enumerator#next"})
|
265
|
+
assert(method_each = thread.methods.detect{|m| m.full_name == "Enumerator#each"})
|
74
266
|
|
75
267
|
assert_in_delta(0.2, method_next.total_time, 0.05)
|
76
268
|
assert_in_delta(0.2, method_each.total_time, 0.05)
|
77
269
|
end
|
78
|
-
|
79
270
|
end
|