ruby-prof 1.1.0-x64-mingw32 → 1.3.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +19 -1
- data/bin/ruby-prof +100 -152
- data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +67 -59
- data/ext/ruby_prof/rp_allocation.h +3 -3
- data/ext/ruby_prof/rp_call_tree.c +369 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +288 -0
- data/ext/ruby_prof/rp_call_trees.h +28 -0
- data/ext/ruby_prof/rp_measure_allocations.c +11 -13
- data/ext/ruby_prof/rp_measure_process_time.c +11 -13
- data/ext/ruby_prof/rp_measure_wall_time.c +17 -15
- data/ext/ruby_prof/rp_measurement.c +47 -40
- data/ext/ruby_prof/rp_measurement.h +7 -7
- data/ext/ruby_prof/rp_method.c +116 -255
- data/ext/ruby_prof/rp_method.h +31 -39
- data/ext/ruby_prof/rp_profile.c +311 -281
- data/ext/ruby_prof/rp_profile.h +1 -2
- data/ext/ruby_prof/rp_stack.c +113 -105
- data/ext/ruby_prof/rp_stack.h +17 -20
- data/ext/ruby_prof/rp_thread.c +136 -111
- data/ext/ruby_prof/rp_thread.h +12 -9
- data/ext/ruby_prof/ruby_prof.c +27 -23
- data/ext/ruby_prof/ruby_prof.h +9 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +11 -7
- data/lib/ruby-prof.rb +2 -3
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +4 -7
- data/lib/ruby-prof/assets/graph_printer.html.erb +5 -6
- data/lib/ruby-prof/{call_info.rb → call_tree.rb} +6 -6
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/measurement.rb +5 -2
- data/lib/ruby-prof/method_info.rb +3 -15
- data/lib/ruby-prof/printers/call_info_printer.rb +12 -10
- data/lib/ruby-prof/printers/call_stack_printer.rb +19 -22
- data/lib/ruby-prof/printers/call_tree_printer.rb +1 -1
- data/lib/ruby-prof/printers/dot_printer.rb +3 -3
- data/lib/ruby-prof/printers/graph_printer.rb +3 -4
- data/lib/ruby-prof/printers/multi_printer.rb +2 -2
- data/lib/ruby-prof/rack.rb +3 -0
- data/lib/ruby-prof/thread.rb +3 -18
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +7 -0
- data/test/alias_test.rb +42 -45
- data/test/basic_test.rb +0 -86
- data/test/{call_info_visitor_test.rb → call_tree_visitor_test.rb} +6 -5
- data/test/call_trees_test.rb +66 -0
- data/test/exclude_methods_test.rb +17 -12
- data/test/fiber_test.rb +197 -9
- data/test/gc_test.rb +36 -42
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +67 -70
- data/test/marshal_test.rb +7 -11
- data/test/measure_allocations_test.rb +224 -234
- data/test/measure_allocations_trace_test.rb +224 -234
- data/test/measure_memory_trace_test.rb +814 -469
- data/test/measure_process_time_test.rb +0 -64
- data/test/measure_times.rb +2 -0
- data/test/measure_wall_time_test.rb +34 -58
- data/test/pause_resume_test.rb +19 -10
- data/test/prime.rb +1 -3
- data/test/prime_script.rb +6 -0
- data/test/printers_test.rb +1 -1
- data/test/recursive_test.rb +50 -54
- data/test/start_stop_test.rb +19 -19
- data/test/test_helper.rb +3 -15
- data/test/thread_test.rb +11 -11
- data/test/unique_call_path_test.rb +25 -95
- metadata +19 -10
- data/ext/ruby_prof/rp_call_info.c +0 -271
- data/ext/ruby_prof/rp_call_info.h +0 -35
- data/lib/2.6.5/ruby_prof.so +0 -0
- data/lib/ruby-prof/call_info_visitor.rb +0 -38
- data/test/parser_timings.rb +0 -24
@@ -137,7 +137,7 @@ module RubyProf
|
|
137
137
|
output << "#{method.line} #{convert(method.self_time)}\n"
|
138
138
|
|
139
139
|
# Now print out all the children methods
|
140
|
-
method.callees.each do |callee|
|
140
|
+
method.call_trees.callees.each do |callee|
|
141
141
|
output << "cfl=#{file(callee.target)}\n"
|
142
142
|
output << "cfn=#{self.calltree_name(callee.target)}\n"
|
143
143
|
output << "calls=#{callee.called} #{callee.line}\n"
|
@@ -114,12 +114,12 @@ module RubyProf
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def print_edges(total_time, method)
|
117
|
-
method.callers.sort_by(&:total_time).reverse.each do |
|
118
|
-
target_percentage = (
|
117
|
+
method.call_trees.callers.sort_by(&:total_time).reverse.each do |call_tree|
|
118
|
+
target_percentage = (call_tree.target.total_time / total_time) * 100.0
|
119
119
|
next if target_percentage < min_percent
|
120
120
|
|
121
121
|
# Get children method
|
122
|
-
puts "#{dot_id(method)} -> #{dot_id(
|
122
|
+
puts "#{dot_id(method)} -> #{dot_id(call_tree.target)} [label=\"#{call_tree.called}/#{call_tree.target.called}\" fontsize=10 fontcolor=#{EDGE_COLOR}];"
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -78,8 +78,7 @@ module RubyProf
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def print_parents(thread, method)
|
81
|
-
|
82
|
-
method.callers.sort_by(&:total_time).each do |caller|
|
81
|
+
method.call_trees.callers.sort_by(&:total_time).each do |caller|
|
83
82
|
@output << " " * 2 * PERCENTAGE_WIDTH
|
84
83
|
@output << sprintf("%#{TIME_WIDTH}.3f", caller.total_time)
|
85
84
|
@output << sprintf("%#{TIME_WIDTH}.3f", caller.self_time)
|
@@ -88,13 +87,13 @@ module RubyProf
|
|
88
87
|
|
89
88
|
call_called = "#{caller.called}/#{method.called}"
|
90
89
|
@output << sprintf("%#{CALL_WIDTH}s", call_called)
|
91
|
-
@output << sprintf(" %s", caller.parent.full_name)
|
90
|
+
@output << sprintf(" %s", caller.parent.target.full_name)
|
92
91
|
@output << "\n"
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
96
95
|
def print_children(method)
|
97
|
-
method.callees.sort_by(&:total_time).reverse.each do |child|
|
96
|
+
method.call_trees.callees.sort_by(&:total_time).reverse.each do |child|
|
98
97
|
# Get children method
|
99
98
|
|
100
99
|
@output << " " * 2 * PERCENTAGE_WIDTH
|
@@ -12,7 +12,7 @@ module RubyProf
|
|
12
12
|
@graph_html_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph_html)
|
13
13
|
|
14
14
|
@tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
|
15
|
-
@call_info_printer = CallInfoPrinter.new(result) if printers.include?(:
|
15
|
+
@call_info_printer = CallInfoPrinter.new(result) if printers.include?(:call_tree)
|
16
16
|
|
17
17
|
@stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
|
18
18
|
@dot_printer = DotPrinter.new(result) if printers.include?(:dot)
|
@@ -58,7 +58,7 @@ module RubyProf
|
|
58
58
|
|
59
59
|
# the name of the callinfo profile file
|
60
60
|
def call_info_report
|
61
|
-
"#{@directory}/#{@profile}.
|
61
|
+
"#{@directory}/#{@profile}.call_tree.txt"
|
62
62
|
end
|
63
63
|
|
64
64
|
# the name of the callgrind profile file
|
data/lib/ruby-prof/rack.rb
CHANGED
data/lib/ruby-prof/thread.rb
CHANGED
@@ -1,23 +1,8 @@
|
|
1
1
|
module RubyProf
|
2
2
|
class Thread
|
3
|
-
# Returns the root methods (ie, methods that were not called by other methods) that were profiled while
|
4
|
-
# this thread was executing. Generally there is only one root method (multiple root methods can occur
|
5
|
-
# when Profile#pause is used). By starting with the root methods, you can descend down the profile
|
6
|
-
# call tree.
|
7
|
-
def root_methods
|
8
|
-
self.methods.select do |method_info|
|
9
|
-
method_info.root?
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
# Returns the total time this thread was executed.
|
14
4
|
def total_time
|
15
|
-
self.
|
16
|
-
method_info.callers.each do |call_info|
|
17
|
-
sum += call_info.total_time
|
18
|
-
end
|
19
|
-
sum
|
20
|
-
end
|
5
|
+
self.call_tree.total_time
|
21
6
|
end
|
22
7
|
|
23
8
|
# Returns the amount of time this thread waited while other thread executed.
|
@@ -25,8 +10,8 @@ module RubyProf
|
|
25
10
|
# wait_time, like self:time, is always method local
|
26
11
|
# thus we need to sum over all methods and call infos
|
27
12
|
self.methods.inject(0) do |sum, method_info|
|
28
|
-
method_info.callers.each do |
|
29
|
-
sum +=
|
13
|
+
method_info.callers.each do |call_tree|
|
14
|
+
sum += call_tree.wait_time
|
30
15
|
end
|
31
16
|
sum
|
32
17
|
end
|
data/lib/ruby-prof/version.rb
CHANGED
data/ruby-prof.gemspec
CHANGED
@@ -19,6 +19,13 @@ EOF
|
|
19
19
|
spec.license = 'BSD-2-Clause'
|
20
20
|
spec.version = RubyProf::VERSION
|
21
21
|
|
22
|
+
spec.metadata = {
|
23
|
+
"bug_tracker_uri" => "https://github.com/ruby-prof/ruby-prof/issues",
|
24
|
+
"changelog_uri" => "https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES",
|
25
|
+
"documentation_uri" => "https://ruby-prof.github.io/",
|
26
|
+
"source_code_uri" => "https://github.com/ruby-prof/ruby-prof/tree/v#{spec.version}",
|
27
|
+
}
|
28
|
+
|
22
29
|
spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
|
23
30
|
spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
|
24
31
|
spec.platform = Gem::Platform::RUBY
|
data/test/alias_test.rb
CHANGED
@@ -37,19 +37,16 @@ class AliasTest < TestCase
|
|
37
37
|
assert_equal(28, method.line)
|
38
38
|
refute(method.recursive?)
|
39
39
|
|
40
|
-
assert_equal(
|
41
|
-
call_info = method.callers[0]
|
42
|
-
assert_nil(call_info.parent)
|
43
|
-
assert_equal(28, call_info.line)
|
40
|
+
assert_equal(0, method.call_trees.callers.count)
|
44
41
|
|
45
|
-
assert_equal(2, method.callees.count)
|
46
|
-
|
47
|
-
assert_equal('Class#new',
|
48
|
-
assert_equal(28,
|
42
|
+
assert_equal(2, method.call_trees.callees.count)
|
43
|
+
call_tree = method.call_trees.callees[0]
|
44
|
+
assert_equal('Class#new', call_tree.target.full_name)
|
45
|
+
assert_equal(28, call_tree.line)
|
49
46
|
|
50
|
-
|
51
|
-
assert_equal('AliasTest::TestMe#some_method',
|
52
|
-
assert_equal(28,
|
47
|
+
call_tree = method.call_trees.callees[1]
|
48
|
+
assert_equal('AliasTest::TestMe#some_method', call_tree.target.full_name)
|
49
|
+
assert_equal(28, call_tree.line)
|
53
50
|
|
54
51
|
# Method 1
|
55
52
|
method = methods[1]
|
@@ -57,15 +54,15 @@ class AliasTest < TestCase
|
|
57
54
|
assert_equal(0, method.line)
|
58
55
|
refute(method.recursive?)
|
59
56
|
|
60
|
-
assert_equal(1, method.callers.count)
|
61
|
-
|
62
|
-
assert_equal('AliasTest#test_alias',
|
63
|
-
assert_equal(28,
|
57
|
+
assert_equal(1, method.call_trees.callers.count)
|
58
|
+
call_tree = method.call_trees.callers[0]
|
59
|
+
assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
|
60
|
+
assert_equal(28, call_tree.line)
|
64
61
|
|
65
|
-
assert_equal(1, method.callees.count)
|
66
|
-
|
67
|
-
assert_equal('BasicObject#initialize',
|
68
|
-
assert_equal(0,
|
62
|
+
assert_equal(1, method.call_trees.callees.count)
|
63
|
+
call_tree = method.call_trees.callees[0]
|
64
|
+
assert_equal('BasicObject#initialize', call_tree.target.full_name)
|
65
|
+
assert_equal(0, call_tree.line)
|
69
66
|
|
70
67
|
# Method 2
|
71
68
|
method = methods[2]
|
@@ -73,12 +70,12 @@ class AliasTest < TestCase
|
|
73
70
|
assert_equal(0, method.line)
|
74
71
|
refute(method.recursive?)
|
75
72
|
|
76
|
-
assert_equal(1, method.callers.count)
|
77
|
-
|
78
|
-
assert_equal('Class#new',
|
79
|
-
assert_equal(0,
|
73
|
+
assert_equal(1, method.call_trees.callers.count)
|
74
|
+
call_tree = method.call_trees.callers[0]
|
75
|
+
assert_equal('Class#new', call_tree.parent.target.full_name)
|
76
|
+
assert_equal(0, call_tree.line)
|
80
77
|
|
81
|
-
assert_equal(0, method.callees.count)
|
78
|
+
assert_equal(0, method.call_trees.callees.count)
|
82
79
|
|
83
80
|
# Method 3
|
84
81
|
method = methods[3]
|
@@ -86,15 +83,15 @@ class AliasTest < TestCase
|
|
86
83
|
assert_equal(13, method.line)
|
87
84
|
refute(method.recursive?)
|
88
85
|
|
89
|
-
assert_equal(1, method.callers.count)
|
90
|
-
|
91
|
-
assert_equal('AliasTest#test_alias',
|
92
|
-
assert_equal(28,
|
86
|
+
assert_equal(1, method.call_trees.callers.count)
|
87
|
+
call_tree = method.call_trees.callers[0]
|
88
|
+
assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
|
89
|
+
assert_equal(28, call_tree.line)
|
93
90
|
|
94
|
-
assert_equal(1, method.callees.count)
|
95
|
-
|
96
|
-
assert_equal('AliasTest::TestMe#some_method_original',
|
97
|
-
assert_equal(14,
|
91
|
+
assert_equal(1, method.call_trees.callees.count)
|
92
|
+
call_tree = method.call_trees.callees[0]
|
93
|
+
assert_equal('AliasTest::TestMe#some_method_original', call_tree.target.full_name)
|
94
|
+
assert_equal(14, call_tree.line)
|
98
95
|
|
99
96
|
# Method 4
|
100
97
|
method = methods[4]
|
@@ -102,15 +99,15 @@ class AliasTest < TestCase
|
|
102
99
|
assert_equal(8, method.line)
|
103
100
|
refute(method.recursive?)
|
104
101
|
|
105
|
-
assert_equal(1, method.callers.count)
|
106
|
-
|
107
|
-
assert_equal('AliasTest::TestMe#some_method',
|
108
|
-
assert_equal(14,
|
102
|
+
assert_equal(1, method.call_trees.callers.count)
|
103
|
+
call_tree = method.call_trees.callers[0]
|
104
|
+
assert_equal('AliasTest::TestMe#some_method', call_tree.parent.target.full_name)
|
105
|
+
assert_equal(14, call_tree.line)
|
109
106
|
|
110
|
-
assert_equal(1, method.callees.count)
|
111
|
-
|
112
|
-
assert_equal('Kernel#sleep',
|
113
|
-
assert_equal(9,
|
107
|
+
assert_equal(1, method.call_trees.callees.count)
|
108
|
+
call_tree = method.call_trees.callees[0]
|
109
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
110
|
+
assert_equal(9, call_tree.line)
|
114
111
|
|
115
112
|
# Method 5
|
116
113
|
method = methods[5]
|
@@ -118,12 +115,12 @@ class AliasTest < TestCase
|
|
118
115
|
assert_equal(0, method.line)
|
119
116
|
refute(method.recursive?)
|
120
117
|
|
121
|
-
assert_equal(1, method.callers.count)
|
122
|
-
|
123
|
-
assert_equal('AliasTest::TestMe#some_method_original',
|
124
|
-
assert_equal(9,
|
118
|
+
assert_equal(1, method.call_trees.callers.count)
|
119
|
+
call_tree = method.call_trees.callers[0]
|
120
|
+
assert_equal('AliasTest::TestMe#some_method_original', call_tree.parent.target.full_name)
|
121
|
+
assert_equal(9, call_tree.line)
|
125
122
|
|
126
|
-
assert_equal(0, method.callees.count)
|
123
|
+
assert_equal(0, method.call_trees.callees.count)
|
127
124
|
end
|
128
125
|
end
|
129
126
|
end
|
data/test/basic_test.rb
CHANGED
@@ -10,11 +10,6 @@ class BasicTest < TestCase
|
|
10
10
|
RubyProf::measure_mode = RubyProf::WALL_TIME
|
11
11
|
end
|
12
12
|
|
13
|
-
def start
|
14
|
-
RubyProf.start
|
15
|
-
RubyProf::C1.sleep_wait
|
16
|
-
end
|
17
|
-
|
18
13
|
def test_running
|
19
14
|
assert(!RubyProf.running?)
|
20
15
|
RubyProf.start
|
@@ -45,85 +40,4 @@ class BasicTest < TestCase
|
|
45
40
|
|
46
41
|
RubyProf.stop
|
47
42
|
end
|
48
|
-
|
49
|
-
def test_leave_method
|
50
|
-
start
|
51
|
-
sleep 0.15
|
52
|
-
profile = RubyProf.stop
|
53
|
-
|
54
|
-
assert_equal(1, profile.threads.count)
|
55
|
-
|
56
|
-
thread = profile.threads.first
|
57
|
-
assert_in_delta(0.25, thread.total_time, 0.05)
|
58
|
-
|
59
|
-
root_methods = thread.root_methods.sort
|
60
|
-
assert_equal(2, root_methods.count)
|
61
|
-
assert_equal("BasicTest#start", root_methods[0].full_name)
|
62
|
-
assert_equal("BasicTest#test_leave_method", root_methods[1].full_name)
|
63
|
-
|
64
|
-
assert_equal(4, thread.methods.length)
|
65
|
-
methods = profile.threads.first.methods.sort
|
66
|
-
|
67
|
-
# Check times
|
68
|
-
assert_equal("<Class::RubyProf::C1>#sleep_wait", methods[0].full_name)
|
69
|
-
assert_in_delta(0.1, methods[0].total_time, 0.05)
|
70
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.05)
|
71
|
-
assert_in_delta(0.0, methods[0].self_time, 0.05)
|
72
|
-
|
73
|
-
assert_equal("BasicTest#start", methods[1].full_name)
|
74
|
-
assert_in_delta(0.1, methods[1].total_time, 0.05)
|
75
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.05)
|
76
|
-
assert_in_delta(0.0, methods[1].self_time, 0.05)
|
77
|
-
|
78
|
-
assert_equal("BasicTest#test_leave_method", methods[2].full_name)
|
79
|
-
assert_in_delta(0.15, methods[2].total_time, 0.05)
|
80
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.05)
|
81
|
-
assert_in_delta(0.0, methods[2].self_time, 0.05)
|
82
|
-
|
83
|
-
assert_equal("Kernel#sleep", methods[3].full_name)
|
84
|
-
assert_in_delta(0.25, methods[3].total_time, 0.05)
|
85
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.05)
|
86
|
-
assert_in_delta(0.25, methods[3].self_time, 0.05)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_leave_method_2
|
90
|
-
start
|
91
|
-
RubyProf::C1.sleep_wait
|
92
|
-
RubyProf::C1.sleep_wait
|
93
|
-
profile = RubyProf.stop
|
94
|
-
|
95
|
-
assert_equal(1, profile.threads.count)
|
96
|
-
|
97
|
-
thread = profile.threads.first
|
98
|
-
assert_in_delta(0.3, thread.total_time, 0.05)
|
99
|
-
|
100
|
-
root_methods = thread.root_methods.sort
|
101
|
-
assert_equal(2, root_methods.count)
|
102
|
-
assert_equal("BasicTest#start", root_methods[0].full_name)
|
103
|
-
assert_equal("BasicTest#test_leave_method_2", root_methods[1].full_name)
|
104
|
-
|
105
|
-
assert_equal(4, thread.methods.length)
|
106
|
-
methods = profile.threads.first.methods.sort
|
107
|
-
|
108
|
-
# Check times
|
109
|
-
assert_equal("BasicTest#start", methods[0].full_name)
|
110
|
-
assert_in_delta(0.1, methods[0].total_time, 0.05)
|
111
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.05)
|
112
|
-
assert_in_delta(0.0, methods[0].self_time, 0.05)
|
113
|
-
|
114
|
-
assert_equal("BasicTest#test_leave_method_2", methods[1].full_name)
|
115
|
-
assert_in_delta(0.2, methods[1].total_time, 0.05)
|
116
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.05)
|
117
|
-
assert_in_delta(0.0, methods[1].self_time, 0.05)
|
118
|
-
|
119
|
-
assert_equal("Kernel#sleep", methods[2].full_name)
|
120
|
-
assert_in_delta(0.3, methods[2].total_time, 0.05)
|
121
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.05)
|
122
|
-
assert_in_delta(0.3, methods[2].self_time, 0.05)
|
123
|
-
|
124
|
-
assert_equal("<Class::RubyProf::C1>#sleep_wait", methods[3].full_name)
|
125
|
-
assert_in_delta(0.3, methods[3].total_time, 0.05)
|
126
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.05)
|
127
|
-
assert_in_delta(0.0, methods[3].self_time, 0.05)
|
128
|
-
end
|
129
43
|
end
|
@@ -2,8 +2,9 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require_relative './measure_times'
|
5
6
|
|
6
|
-
class
|
7
|
+
class CallTreeVisitorTest < TestCase
|
7
8
|
def setup
|
8
9
|
# Need to use wall time for this test due to the sleep calls
|
9
10
|
RubyProf::measure_mode = RubyProf::WALL_TIME
|
@@ -14,16 +15,16 @@ class CallInfoVisitorTest < TestCase
|
|
14
15
|
RubyProf::C1.sleep_wait
|
15
16
|
end
|
16
17
|
|
17
|
-
visitor = RubyProf::
|
18
|
+
visitor = RubyProf::CallTreeVisitor.new(result.threads.first.call_tree)
|
18
19
|
|
19
20
|
method_names = Array.new
|
20
21
|
|
21
|
-
visitor.visit do |
|
22
|
-
method_names <<
|
22
|
+
visitor.visit do |call_tree, event|
|
23
|
+
method_names << call_tree.target.full_name if event == :enter
|
23
24
|
end
|
24
25
|
|
25
26
|
assert_equal(3, method_names.length)
|
26
|
-
assert_equal("
|
27
|
+
assert_equal("CallTreeVisitorTest#test_visit", method_names[0])
|
27
28
|
assert_equal("<Class::RubyProf::C1>#sleep_wait", method_names[1])
|
28
29
|
assert_equal("Kernel#sleep", method_names[2])
|
29
30
|
end
|
@@ -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
|